From 0f74cf47d7b9a22465cbdc75e2004ed37ae156ec Mon Sep 17 00:00:00 2001 From: gpetit Date: Tue, 29 Jan 2019 16:41:20 +0100 Subject: [PATCH] Update the SHPWrite doc --- docs/dev/SHPWrite.md | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/docs/dev/SHPWrite.md b/docs/dev/SHPWrite.md index f4c0b95a8e..57caff2631 100644 --- a/docs/dev/SHPWrite.md +++ b/docs/dev/SHPWrite.md @@ -20,6 +20,13 @@ SHPWrite(VARCHAR path, VARCHAR tableName, VARCHAR fileEncoding); Writes the contents of table `tableName` to a [shapefile][wiki] located at `path`. + +`tablename` can be either: + +* the name of an existing table, +* the result of a selection (`SELECT` instruction which has to be written between simple quote `' '`). + + The default value of `fileEncoding` is `ISO-8859-1`.
@@ -48,18 +55,32 @@ CALL SHPWrite('/home/user/area.shp', 'AREA'); CALL SHPRead('/home/user/area.shp', 'AREA2'); SELECT * FROM AREA2; -- Answer: --- | THE_GEOM | IDAREA | --- | ------------------------------------------------ | ------ | --- | MULTIPOLYGON(((-10 109,, 90 9, -10 9, -10 109))) | 1 | --- | MULTIPOLYGON(((90 109, 190 109, 90 9, 90 109))) | 2 | +-- | THE_GEOM | ID | +-- | ------------------------------------------------ | -- | +-- | MULTIPOLYGON(((-10 109,, 90 9, -10 9, -10 109))) | 1 | +-- | MULTIPOLYGON(((90 109, 190 109, 90 9, 90 109))) | 2 | {% endhighlight %} +#### Case where `tablename` is the result of a selection. + +{% highlight mysql %} +CALL SHPWRITE('/home/user/area.shp', + '(SELECT * FROM AREA WHERE ID<2 )'); + +-- Read it back +CALL SHPRead('/home/user/area.shp', 'AREA2'); +SELECT * FROM AREA2; +-- Answer: +-- | THE_GEOM | ID | +-- | ------------------------------------------------ | -- | +-- | MULTIPOLYGON(((-10 109,, 90 9, -10 9, -10 109))) | 1 | +{% endhighlight %} ### Export the .prj file If you want to export your shapefile with it's projection, stored in a .prj file, you must assume that the table contains a SRID constraint value greater than 0. -If not the SRID must be enforced using the following commands: +If not, the SRID must be enforced using the following commands: {% highlight mysql %} UPDATE mytable SET the_geom = ST_SetSRID(the_geom, EPSG_CODE);