CartoDB / CartoDB-basemaps

CartoDB basemaps
http://cartodb.com/basemaps
Other
55 stars 13 forks source link

ne2pgsql.sh errors #40

Closed pnorman closed 8 years ago

pnorman commented 8 years ago

The

for z in $DIR/*.shp; do 
  ogr2ogr -skipfailures -nlt PROMOTE_TO_MULTI -lco GEOMETRY_NAME=the_geom \
    -lco FID=cartodb_id -lco PRECISION=NO -overwrite -f "PostgreSQL" \
    PG:"dbname=cartodb_basemaps" $z
done

section of code prints the following errors

ERROR 1: ALTER TABLE "ne_10m_admin_1_states_provinces_lines_shp" ADD COLUMN "cartodb_id" INTEGER
ERROR:  column "cartodb_id" of relation "ne_10m_admin_1_states_provinces_lines_shp" already exists

ERROR 1: ALTER TABLE "ne_10m_geography_marine_polys" ADD COLUMN "cartodb_id" INTEGER
ERROR:  column "cartodb_id" of relation "ne_10m_geography_marine_polys" already exists

ERROR 1: ALTER TABLE "ne_50m_geography_marine_polys" ADD COLUMN "cartodb_id" INTEGER
ERROR:  column "cartodb_id" of relation "ne_50m_geography_marine_polys" already exists

These seem to be the shapefiles which already have a cartodb_id.

pnorman commented 8 years ago

Loading up the shapefile, I see that the in-DB cartodb_ids differ from those in the shapefile.

Looking at the OGR PostgreSQL driver documentation, I think I see the problem.

FID: (From GDAL 1.9.0) Name of the FID column to create. Defaults to 'ogc_fid'.

This option is causing a cartodb_id column to be created and automatically populated as a postgres serial. This column conflicts with a cartodb_id column which it tries to populate from the shapefile.

I'm actually surprised this results in a populated table rather than an error when inserting.

If I omit this option, it lets these tables import, but will break those without cartodb_id already in the shapefile, and results in a ogr_fid column as a primary key.

I tried using -preserve_fid but that didn't change the results.

pnorman commented 8 years ago

fixed in develop