[postgis-users] export polygon to shapefile problem

Thomas Kouk thomaskouk at yahoo.gr
Wed Nov 17 05:32:38 PST 2010


I left the -a_srs out and I no longer have the usage information, but instead I 
have an error message: 

ESRI Shapefile driver failed to create file.shp. 
The same happens for other spatial tables as well (not necessarily polygons).

The table contains only a geometry column. The funny thing is that if I use a 
script to merge a lot of such tables into one, adding a gid column so that I can 
distinguish them, using the command I tried in the beginning:

 pgsql2shp -P [password] -f [shapefile path & name] postgis [tablename]

works fine! However it would be stupid to create another script to split the 
data and deal with this in this way.




________________________________
From: Marco Lechner - FOSSGIS e.V. <marco.lechner at fossgis.de>
To: PostGIS Users Discussion <postgis-users at postgis.refractions.net>
Sent: Wed, November 17, 2010 12:44:19 PM
Subject: Re: [postgis-users] export polygon to shapefile problem

- you could leave out the -a_srs for testing
- it should be possible to use those table names like W_TQ2575_Buffer by masking 
the "

Marco

Am 17.11.2010 13:40, schrieb Thomas Kouk: 
Hi Marco,
>
>I tried the sql statement in psql, it works fine, no error message.
>There is no error message right above the usage information.
>I do not want to reproject, polygon is already in SRID 27700.
>
>The table's name could be the problem, because in pgadmin sql window or psql 
>window it needs quotation (""). So I created a new table like the old one, only 
>with a simpler name. I tried again, but still with no results:
>ogr2ogr -a -f "ESRI Shapefile" file.shp PG:"dbname=postgis host=localhost 
>user=postgres password=postgres" -sql "SELECT AsBinary(the_geom) as wkb_geometry 
>FROM test"
>Is there any other way?
>Thanks
>
>
>
________________________________
From: Marco Lechner - FOSSGIS e.V. <marco.lechner at fossgis.de>
>To: PostGIS Users Discussion <postgis-users at postgis.refractions.net>
>Sent: Wed, November 17, 2010 12:07:27 PM
>Subject: Re: [postgis-users] export polygon to shapefile problem
>
>try
>C:\Program Files\FWTools2.4.7\bin>ogr2ogr -a srs "EPSG:27700" ...
>
>Does your sql-statemnet produce a result when executed within psql?
>Are you sure there's no error message right above the usage information?
>Do you want to reproject to 27700? Then you should use -t_srs
>
>Marco
>
>Am 17.11.2010 12:56, schrieb Thomas Kouk: 
>Thanks Helen,
>>I've been trying to make it work. I don't have ogr2ogr.exe somewhere in 
>>PostgreSQL folder. The only place where I have ogr2ogr.exe is in FWTools folder, 
>>(other ones in OSGeo4W do not work, dll problems).
>>So I try this:
>>
>>C:\Program Files\FWTools2.4.7\bin> ogr2ogr -a srs EPSG:27700 -f "ESRI Shapefile" 
>>file.shp PG:"dbname=postgis host=localhost user=postgres password=postgres" 
>>-sql "SELECT AsBinary(the_geom) as wkb_geometry FROM W_TQ2575_Buffer"
>>After this I do not get any error message, but I get the ogr2ogr usage 
>>information (as if something I typed is wrong) and the file.shp is not created 
>>(cannot be found anywhere).
>>Any help?
>>
>>
>>
>>
________________________________
From: Helen San Segundo Navazo <hsansegundo at meteo.cat>
>>To: PostGIS Users Discussion <postgis-users at postgis.refractions.net>
>>Sent: Wed, November 17, 2010 9:29:15 AM
>>Subject: Re: [postgis-users] export polygon to shapefile problem
>>
>>Hi Thomas,
>>
>>I use the next expression to export data automatically in an script from a table 
>>with polygons into a shape file:
>>
>>
>>ogr2ogr -a_srs EPSG:23031 -f "ESRI Shapefile" file.shp PG:"dbname=db_name 
>>host=the_host user=the_user password=the_password" -sql "SELECT 
>>AsBinary(the_geometry_column) as wkb_geometry, column2,column3,column4 etc. FROM 
>>table where conditions"
>>
>>I hope this will help you,
>>Helen
>>
>>
>>Thomas Kouk escribió:
>>> 
>>> Hi all,
>>> 
>>> I am newbie in PostGIS and I have a problem exporting a polygon table in shp. I 
>>>want to export specific spatial tables from by database using a batch procedure 
>>>(bat file). The command I use is:
>>> 
>>> pgsql2shp -P [password] -f [shapefile path & name] postgis [tablename], for 
>>>example: pgsql2shp -P postgres -f Data\Buffers\ Buffer.shp postgis buffer_table
>>> 
>>> It works fine with all other spatial tables (linestring or multilinestring 
>>>type). For polygons it also seems to work, as I get no error message:
>>> 
>>> / Initializing... Done (postgis major version: 1)./
>>> 
>>> / Output shape: Polygon/
>>> 
>>> / Dumping: XX [1 rows]./
>>> 
>>> However, when I try to load the polygon shp in Qgis or ArcGIS I get an error: 
>>>ArcGIS cannot open the file, while QGIS loads the shp but displays nothing (as 
>>>if the table is empty, which is not the case).
>>> 
>>> All my tables are spatial tables with no information on geometry_columns table, 
>>>but even if I add the polygon table in the geometry_columns, nothing changes. 
>>>After all, the function works with all other spatial non polygon tables despite 
>>>the fact that geometry_columns holds no information on them, so this is not the 
>>>problem.
>>> 
>>> I can load the postgis polygon table in qgis and export it manually to a shp, 
>>>which works fine, but I need to do it in an automatic way using a command.
>>> 
>>> Has anyone come to this problem or is there something I do not know about 
>>>exporting polygon tables to shp?
>>> 
>>> Thanks.
>>> 
>>> 
>>> ------------------------------------------------------------------------
>>> 
>>> _______________________________________________
>>> postgis-users mailing list
>>> postgis-users at postgis.refractions.net
>>> http://postgis.refractions.net/mailman/listinfo/postgis-users
>>>  
>>
>>
>>-- 
>>Helen San Segundo Navazo
>>
>>
>>http://www.meteo.cat
>>Tel. 93 567 60 90
>>Fax 93 567 61 02
>>A/e hsansegundo at meteo.cat <mailto:hsansegundo at meteo.cat>
>>
>>Abans d’imprimir aquest correu, assegureu-vos que és del tot necessari. El medi 
>>ambient és cosa de tothom!
>>
>>La informació d'aquesta transmissió electrònica és confidencial i el seu ús sols 
>>està permès als seus destinataris. Si Vostè no és la persona destinatària 
>>d'aquesta transmissió electrònica, li preguem que ens ho comuniqui de forma 
>>immediata i destrueixi qualsevol copia de la mateixa (tant digital com en 
>>paper).
>>
>>_______________________________________________
>>postgis-users mailing list
>>postgis-users at postgis.refractions.net
>>http://postgis.refractions.net/mailman/listinfo/postgis-users
>>
>>
>> _______________________________________________ postgis-users mailing list 
>>postgis-users at postgis.refractions.net 
>>http://postgis.refractions.net/mailman/listinfo/postgis-users   
>>

>
> _______________________________________________ postgis-users mailing list 
>postgis-users at postgis.refractions.net 
>http://postgis.refractions.net/mailman/listinfo/postgis-users   
>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/postgis-users/attachments/20101117/4046581e/attachment.html>


More information about the postgis-users mailing list