[postgis-users] export polygon to shapefile problem

Helen San Segundo Navazo hsansegundo at meteo.cat
Wed Nov 17 01:29:15 PST 2010

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,

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

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).

More information about the postgis-users mailing list