2

I have the following PostgreSQL/PostGIS table

CREATE TABLE schema.table 
(
    id   bigint    NOT NULL CONSTRAINT id_pkey PRIMARY KEY, 
    geog geography NOT NULL
);

and an ARCGEN file file.gen which I want to append to the above table.

1 11.3 58.3
11.3 58.4
11.4 58.3
11.3 58.2
11.2 58.2
11.1 58.3
11.3 58.4
END
2 -168.7 58.3
-168.7 58.2
-168.8 58.2
-168.9 58.3
-168.8 58.4
-168.6 58.3
-168.7 58.2
END
3 -168.8 58.5
-168.6 58.5
-168.8 58.4
-168.9 58.5
-168.9 58.6
-168.8 58.6
-168.6 58.6
-168.6 58.5
END
4 -168.8 58.8
-168.6 58.7
-168.8 58.7
-168.9 58.7
-168.9 58.8
-168.8 58.9
-168.6 58.8
-168.6 58.7
END
5 -168.8 59.0
-168.6 59.0
-168.8 58.9
-168.9 59.0
-168.9 59.1
-168.8 59.1
-168.6 59.1
-168.6 59.0
END
6 -168.8 59.3
-168.6 59.2
-168.8 59.2
-168.9 59.2
-168.9 59.3
-168.8 59.4
-168.6 59.3
-168.6 59.2
END
7 -168.8 59.5
-168.6 59.5
-168.8 59.4
-168.9 59.5
-168.9 59.6
-168.8 59.6
-168.6 59.6
-168.6 59.5
END
8 -168.8 59.8
-168.6 59.7
-168.8 59.7
-168.9 59.7
-168.9 59.8
-168.8 59.9
-168.6 59.8
-168.6 59.7
END
9 -168.8 60.0
-168.6 60.0
-168.8 59.9
-168.9 60.0
-168.9 60.1
-168.8 60.1
-168.6 60.1
-168.6 60.0
END
10 -168.8 60.3
-168.6 60.2
-168.8 60.2
-168.9 60.2
-168.9 60.3
-168.8 60.4
-168.6 60.3
-168.6 60.2
END
END

To do this I use the following command:

ogr2ogr --config PG_USE_COPY YES   \
         -nln      schema.table    \
         -update                   \
         -append                   \
         -fieldmap identity        \
         -f        "PostgreSQL"    \
         PG:"host=192.168.56.1 port=5432 dbname=dev01 user=admin password=password"                 \
         ~/output/file.gen

However, I get the error ERROR 1: Invalid destination field index 0.

I know that this has something to do with the -fieldmap option. Both, the source and destination, have 2 columns, so I tried identity, 0,1, and other options like -1,identity,1, identity,2... Because I had no luck with that, and just to be sure, I tried to convert the ARCGEN file into GEOJSON and SHAPEFILE, but that resulted in the same error.

If I remove the CONSTRAINT id_pkey PRIMARY KEY from my destination table, the data from the ARCGEN file is successfully copied to the PostGIS table.

1 Answer 1

0

The source .gen dataset is composed by 1 field only (of geometry type), while the destination table has two fields, with types: 0: integer, 1:geometry.

So what you need to do is to send your unique input field in the destination field 1. This can be achieved by using:

-fieldmap 0

When you use "identity" it is required that source and destination have matching fields, same number and same order.

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.