Skip to content

Commit

Permalink
Update the SHPWrite doc
Browse files Browse the repository at this point in the history
  • Loading branch information
gpetit committed Jan 29, 2019
1 parent 34afea9 commit 0f74cf4
Showing 1 changed file with 26 additions and 5 deletions.
31 changes: 26 additions & 5 deletions docs/dev/SHPWrite.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.

<div class="note warning">
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0f74cf4

Please sign in to comment.