2

I run command:

ogr2ogr -f PostgreSQL PG:"dbname=regional host=localhost user=*** password=***" Hsp_09_13.MIF -t_srs EPSG:3857 -nlt MULTIPOLYGON -overwrite -nln postcode_sector_boundaries

And I have error:

ERROR 1: Layer postcode_sector_boundaries already exists, CreateLayer failed. Use the layer creation option OVERWRITE=YES to replace it.

So I run this command then:

ogr2ogr -f PostgreSQL PG:"dbname=regional host=localhost user=*** password=***" Hsp_09_13.MIF -t_srs EPSG:3857 -nlt MULTIPOLYGON -lco OVERWRITE=YES -overwrite -nln postcode_sector_boundaries

and got error:

ERROR 1: CREATE TABLE "public"."postcode_sector_boundaries" ( OGC_FID SERIAL, PRIMARY KEY (OGC_FID) ) ERROR: relation "postcode_sector_boundaries" already exists

So I remove table postcode_sector_boundaries and run once more last command and got:

ERROR 1: 'CREATE INDEX "postcode_sector_boundaries_geom_idx" ON "public"."postcode_sector_boundaries" USING GIST ("wkb_geometry")' failed for layer postcode_sector_boundaries, index creation has failed.

postcode_sector_boundaries_geom_idx is unique key so I think that maybe my data are broken. I would like that ogr2ogr create table without that index but I can not find where definition for this create query can be. Any one knows? Or maybe there is another solution for my problem?

edit:

Ok, I know what was the problem - it was because there were some other tables using values from one I wanted recreate.

12
  • So, you are trying to update/overwrite an existing PostGIS table using ogr?
    – artwork21
    May 31, 2016 at 13:18
  • Yes. It works for other tables with other data but not for this table.
    – nospor
    May 31, 2016 at 13:21
  • I've always used the -update and -overwrite switches like: ogr2ogr -update -overwrite -f PostgreSQL PG:"dbname=regional host=localhost user=*** password=***" Hsp_09_13.MIF -t_srs EPSG:3857 -nlt MULTIPOLYGON -nln postcode_sector_boundaries
    – artwork21
    May 31, 2016 at 13:23
  • Adding -update does not help. I still have ERROR 1: Layer postcode_sector_boundaries already exists, CreateLayer failed.
    – nospor
    May 31, 2016 at 13:25
  • 1
    @nospor This is the reason I use the "append" and "truncate" method, to avoid problems with depending views. I don't know why it does nothing in your case.
    – thibautg
    May 31, 2016 at 17:17

1 Answer 1

2

I've had some success with -append (to avoid recreating the table) and --config OGR_TRUNCATE YES (to truncate/empty the table before uploading new data)

ogr2ogr -append -f PostgreSQL PG:"dbname=regional host=localhost user=*** password=***" Hsp_09_13.MIF -t_srs EPSG:3857 -nlt MULTIPOLYGON -nln postcode_sector_boundaries --config OGR_TRUNCATE YES

(not tested with the above command but I use it regularly with other layers)

1
  • Your code do not throw any error but also do not update any data
    – nospor
    May 31, 2016 at 13:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.