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

Related posts:

Share

About number.0