shp2pgsql loader

View: New views
3 Messages — Rating Filter:   Alert me  

shp2pgsql loader

by Solomon Pulapkura :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Does any one know how to use shp2pgsql loader in PostGIS. I need to convert
(obviously) an ESRI shape file to PostGIS' Extended Well Known Text format.
I have downloaded both PostGIS and postgresql on to my machine

Any help would be appreciated

Thanks
Solomon
_______________________________________________
gislist mailing list
gislist@...
http://lists.geocomm.com/mailman/listinfo/gislist

_________________________________
This list is brought to you by
The GeoCommunity
http://www.geocomm.com/

Re: shp2pgsql loader

by TONY NETTO :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


check out fwtools  OGR (http://fwtools.maptools.org/)

http://www.bostongis.com/PrinterFriendly.aspx?content_name=ogr_cheatsheet


> Date: Mon, 5 Oct 2009 10:03:47 -0700
> From: solomon.roy@...
> To: gislist@...
> Subject: [gislist] shp2pgsql loader
>
> Does any one know how to use shp2pgsql loader in PostGIS. I need to convert
> (obviously) an ESRI shape file to PostGIS' Extended Well Known Text format.
> I have downloaded both PostGIS and postgresql on to my machine
>
> Any help would be appreciated
>
> Thanks
> Solomon
> _______________________________________________
> gislist mailing list
> gislist@...
> http://lists.geocomm.com/mailman/listinfo/gislist
>
> _________________________________
> This list is brought to you by
> The GeoCommunity
> http://www.geocomm.com/
     
_______________________________________________
gislist mailing list
gislist@...
http://lists.geocomm.com/mailman/listinfo/gislist

_________________________________
This list is brought to you by
The GeoCommunity
http://www.geocomm.com/

Parent Message unknown Re: shp2pgsql loader

by Karsten Vennemann :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Solomon,
 
First you need to know the projection your shape file is in (look at prj file if available in a text editor for example)
and determine the EPSG code to tell PostGIS what projection your data are in (that is the SRID value).
Geographic (or "no projection in decimal degrees) is e.g EPSG 4326. See for example  <http://www.remotesensing.org/geotiff/proj_list/> http://www.remotesensing.org/geotiff/proj_list/ or even easier use to determine your EPSG code:  <http://www.spatialreference.org/> http://www.spatialreference.org/
 
Then on the command line there are basically two options to load  a shape file to pgsql (and note you don't need to use ogr2ogr for that)
 
1. This is an example using a two step process to load a shape file called "counties.shp" itno PostGIS. Projection is geographic - EPSG code 4326
 
a. Create a sql import file from your shape data: shp2pgsql -I -s 4326 counties.shp counties_table > counties_import_file.sql
where
-I           is a switch to automatically create a spatial index on the data once they are in the database (very important)
-s 4326  is geographic projection as EPSG code called here SRID
counties.shp   is the name of the shape file you want to import
counties_table  is a name you can freely choose for the table in PostGIS once imported
> counties_import_file.sql   is the switch to output to a file named "counties_import_file.sql" (can chose any name) that you can execute to load your data into PostGIS in step b.
 
b. Execute the sql file to load into PostGIS:psql -U postgres -d yourdatabase -f D:/data/counties_import_file.sql
where
psql  is the command to connect to the database from the command line
-U postgres  specifies the database user in this case "postgres"
-d yourdatabase  is the name of your databse you want to load the data into (you have to cerate a databse with this name, but name you can choose freely)
-f D:/data/counties_import_file.sql   is the switch to run the sql commands in the file you cerate in step a "counties_import_file.sql" . Note you have to include the path where is is located on your system
 
2. If you are on a Linux operating system you can do a one step process and directly connect to db an load the shape file using UNIX pipes: (symbol "|" in command below):
shp2pgsql -I -s 4326 counties.shp counties_table | psql -U postgres -d yourdatabase
 
Read also http://postgis.refractions.net/docs/ch04.html#id2537490 (4.3.2. Using the Loader)

There is now also a graphical user interface based tool that you can load to get shape files transformed into PostgreSQL format (that is a sql files that you can load into PostGIS).
This is also a good way to learn shp2pgsql  commands because you can see the commands it assembles when you use the user interface... http://polylinie.de/gshp2pgsql/en/index.html
 
Cheers
Karsten

Karsten Vennemann
Principal

Terra GIS LTD
Seattle, WA  98112
USA
www.terragis.net <http://www.terragis.net/>

_______________________________________________
gislist mailing list
gislist@...
http://lists.geocomm.com/mailman/listinfo/gislist

_________________________________
This list is brought to you by
The GeoCommunity
http://www.geocomm.com/