Skip to content

Instantly share code, notes, and snippets.

@anandology
Created March 27, 2014 04:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anandology/9800561 to your computer and use it in GitHub Desktop.
Save anandology/9800561 to your computer and use it in GitHub Desktop.
shp2pgsql for AC and PC data
[geosearch-anandology.rhcloud.com S01]\> shp2pgsql -W "latin1" -s4326 -d S01_AC ac geosearch > ac.sql
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
[geosearch-anandology.rhcloud.com S01]\> psql -q geosearch < ac.sql
dropgeometrycolumn
-------------------------------------
public.ac.geom effectively removed.
(1 row)
NOTICE: CREATE TABLE will create implicit sequence "ac_gid_seq" for serial column "ac.gid"
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "ac_pkey" for table "ac"
addgeometrycolumn
----------------------------------------------------
public.ac.geom SRID:4326 TYPE:MULTIPOLYGON DIMS:2
(1 row)
[geosearch-anandology.rhcloud.com S01]\> psql -c "select ac_no, ac_name, ac_type, ST_asText(ST_Centroid(geom)) from ac order by ac_no limit 5"
ac_no | ac_name | ac_type | st_astext
---------------+---------------+---------+-------------------------------------------
1.00000000000 | Ichapuram | GEN | POINT(-11.6497546606635 1.55231611263644)
2.00000000000 | Sompeta | GEN | POINT(-11.6624053804354 1.53739023043821)
3.00000000000 | Tekkali | GEN | POINT(-11.6756558330656 1.51855588848709)
4.00000000000 | Harishchandra | GEN | POINT(-11.6898601989798 1.50766009066023)
5.00000000000 | Narasannapeta | GEN | POINT(-11.6995545927925 1.49867010343033)
(5 rows)
[geosearch-anandology.rhcloud.com S01]\> pwd
/tmp/AC_Data/States/S01
------
[geosearch-anandology.rhcloud.com S01]\> shp2pgsql -d -s 4326 -W latin1 S01_PC.shp pc geosearch > pc.sql
Shapefile type: Polygon
Postgis type: MULTIPOLYGON[2]
[geosearch-anandology.rhcloud.com S01]\> psql -q geosearch < pc.sql
dropgeometrycolumn
-------------------------------------
public.pc.geom effectively removed.
(1 row)
NOTICE: CREATE TABLE will create implicit sequence "pc_gid_seq" for serial column "pc.gid"
NOTICE: ALTER TABLE / ADD PRIMARY KEY will create implicit index "pc_pkey" for table "pc"
addgeometrycolumn
----------------------------------------------------
public.pc.geom SRID:4326 TYPE:MULTIPOLYGON DIMS:2
(1 row)
[geosearch-anandology.rhcloud.com S01]\> psql -c "select pc_no, pc_name, pc_type, ST_asText(ST_Centroid(geom)) from pc order by pc_no limit 5"
pc_no | pc_name | pc_type | st_astext
-------+---------------+---------+------------------------------------------
1 | SRIKAKULAM | GEN | POINT(84.2240417663602 18.635986071352)
2 | PARVATHIPURAM | ST | POINT(83.6947541942235 18.7649878862544)
3 | BOBBILI | GEN | POINT(83.5029123726643 18.3508651375251)
4 | VISAKHAPATNAM | GEN | POINT(83.2279435296807 18.1635382621197)
5 | BHADRACHALAM | ST | POINT(81.6314708474619 17.7466516970806)
(5 rows)
[geosearch-anandology.rhcloud.com S01]\> pwd
/tmp/PC_Data/States/S01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment