wiki:CookBook pgsql2shp

Version 8 (modified by cedric, 15 years ago) (diff)

--

using shp2pgsql

As the rgdal driver fails to load posgres and the solution from roger Bivand does not seem to work we have to find a way to use shape files in postgres

C:\"Program Files"\PostgreSQL\8.4\bin\pgsql2shp --help
RCSID: $Id: pgsql2shp.c 4914 2009-11-27 18:12:43Z pramsey $ RELEASE: 1.4 USE_GEO
S=1 USE_PROJ=1 USE_STATS=1
USAGE: C:\Program Files\PostgreSQL\8.4\bin\pgsql2shp [<options>] <database> [<sc
hema>.]<table>
       C:\Program Files\PostgreSQL\8.4\bin\pgsql2shp [<options>] <database> <que
ry>

OPTIONS:
  -f <filename>  Use this option to specify the name of the file
     to create.
  -h <host>  Allows you to specify connection to a database on a
     machine other than the default.
  -p <port>  Allows you to specify a database port other than the default.
  -P <password>  Connect to the database with the specified password.
  -u <user>  Connect to the database as the specified user.
  -g <geometry_column> Specify the geometry column to be exported.
  -b Use a binary cursor.
  -r Raw mode. Do not assume table has been created by
     the loader. This would not unescape attribute names
     and will not skip the 'gid' attribute.
  -k Keep postgresql identifiers case.
  -? Display this help screen.

the gid is not loaded into the database so I thing we shoud use -r option We do not want shifts to maj so we should be using the -k option

ccm21.riversegments_bretagne

C:\"Program Files"\PostgreSQL\8.4\bin\pgsql2shp -f "C:\Documents and Settings\cedric\Mes documents\Migrateur\eda\exports_shape\riversegments_bretagne" -p 5433 -u postgres -P postgres -g the_geom -r -k eda2.0 ccm21.riversegments_bretagne

ccm21.catchments_bretagne

C:\"Program Files"\PostgreSQL\8.4\bin\pgsql2shp -f "C:\Documents and Settings\cedric\Mes documents\Migrateur\eda\exports_shape\catchments_bretagne" -p 5433 -u postgres -P postgres -g the_geom -r -k eda2.0 ccm21.catchments_bretagne

clc.clipped_bretagne1

C:\"Program Files"\PostgreSQL\8.4\bin\pgsql2shp -f "C:\Documents and Settings\cedric\Mes documents\Migrateur\eda\exports_shape\clipped_bretagne1" -p 5433 -u postgres -P postgres -g the_geom -r -k eda2.0 clc.clipped_bretagne1

ccm21.riversegments_france

A query selecting a reduced area

C:\"Program Files"\PostgreSQL\8.4\bin\pgsql2shp -f "C:\Documents and Settings\cedric\Mes documents\Migrateur\eda\exports_shape\riversegments_france" -p 5433 -u postgres -P postgres -g the_geom -r -k eda2.0 "select * from ccm21.riversegments where wso_id in (select wso_id from france.wso where area='France');"

ccm21.catchments_france

C:\"Program Files"\PostgreSQL\8.4\bin\pgsql2shp -f "C:\Documents and Settings\cedric\Mes documents\Migrateur\eda\exports_shape\catchments_france" -p 5433 -u postgres -P postgres -g the_geom -r -k eda2.0 "select * from ccm21.catchments where wso_id in (select wso_id from france.wso where area='France');"

clc.surf_area_final

C:\"Program Files"\PostgreSQL\8.4\bin\pgsql2shp -f "C:\Documents and Settings\cedric\Mes documents\Migrateur\eda\exports_shape\surf_area_final" -p 5433 -u postgres -P postgres -g the_geom -r -k eda2.0 select clc.surf_area_final

percentage urban

select r.gid, c.gid as c_gid, art_11_13/catchment_area as psurf, c.the_geom 
from ccm21.riversegments r
join ccm21.catchments c on c.wso1_id=r.wso1_id
where r.wso_id in (select wso_id from france.wso where area='France');