TransWikia.com

Geometry errors when importing shapefile with shp2pgsql PostGIS

Geographic Information Systems Asked by DogEatDog on August 27, 2021

I’m trying to import the Census State Boundaries from the census data site although I get errors in the geom data every time I import in the same rows.

I’ve tried shp2pgsql and ogr2ogr

shp2pgsql -I -d -e /Users/cj/Projects/geospacial_data/cb_2019_us_state_500k/cb_2019_us_state_500k.shp public.state | psql -h localhost -d my_db -U cj

and this

ogr2ogr -f "ESRI Shapefile" /Users/cj/Projects/geospacial_data/cb_2019_us_state_500k/cb_2019_us_state_500k.shp PG:"host=localhost user=cj dbname=mydb" "state"

The errors show up here in the geom column (in the screenshot) showing the loaded size. Are these errors just part of the file? or am I doing something wrong? This seems to crop up when I do Counties and zip codes as well.

enter image description here

I’m running

  • PostGIS 3.0.1 (homebrew)
  • PostgreSQL 12.3 (homebrew)
  • GDAL 2.4.4 (homebrew)
  • MacOS 10.14.6

One Answer

  1. Prefer ogr2ogr over shp2pgsql because the former has many built-in validations for the supported data sources and destinations.

  2. The Census State Boundary SHP dataset claimed to be of type POLYGON but contained at least one row of MULTIPOLYGON geometry.

  3. Use the following command to import the Census State Boundary SHP dataset into PostgreSQL (assuming that you had priorly enabled the PostGIS extension on the target database):

    ogr2ogr -f "PostgreSQL" PG:"host=localhost user=cj dbname=mydb" -nln state -nlt multipolygon cb_2019_us_state_500k.shp

Answered by Ralph Tee on August 27, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP