Windows – Linux – Mac OSX Guides

Import Shapefiles (SHP) into Postgis

Follow these steps to start importing ESRI Shapefiles into Postgis database

1. Generate SQL from the shapefile using shp2pgsql

shp2pgsql -W UTF-8 <file_name.shp> <schema>.<table_name> > <filename.sql>

ex:

shp2pgsql –W UTF-8 world.shp public.world > world.sql

2. Open the generated sql file, append “WITH OIDS” before “;” of the CREATE TABLE statement

3. Now import the sql file into Postgis, using psql command

psql -h <host_name> -U <user_name> -d <db_name> -f <file_name.sql>

ex:

psql -h 127.0.0.1 -U postgres -d world -f world.sql

4.Use Query tool available in PgAdmin3

CREATE INDEX <index_name> ON <table_name> USING gist (<spatial_attribute>);
VACUUM ANALYZE <table_name>

ex:

CREATE INDEX world_the_geom_gist ON world USING gist (the_geom);
VACUUM ANALYZE world

Tagged with:     , , , , , , ,

Related Articles

Loading Facebook Comments ...

2 Comments

  1. ankit

    hi, i m finding solution for dgn to postgres
    I have use ogr2ogr tool but it miss data from some .dgn file. so pls provide me some better tool.

Post your comments

Your email address will not be published. Required fields are marked *