1

I'm trying to import contours from SRTM HGT files.

First try (nice):

gdal_contour -f PostgreSQL -a elevation -i 10 srtm/S01W069.hgt "PG:host=volcano-db user=postgres password=guesswhat dbname=contour"

Second try (error):

gdal_contour -f PostgreSQL -a elevation -i 10 srtm/S03W071.hgt "PG:host=volcano-db user=postgres password=guesswhat dbname=contour"


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

I can't find any append option in my gdal_contour and I'm afraid that override will erase my previous data.

  • There is no mention about appending data in gdal.org/programs/gdal_contour.html#gdal-contour. Have you tried to create contours into separate tables and combine them afterwards? Another option could be to mosaic source files with gdalbuildvrt and create contours from the resulting vrt mosaic. – user30184 Jun 10 at 14:43
  • @user30184 yes gdalbuildvrt was my first attempt but I have all South America HGT files. Six days, 40% and counting.... – Magno C Jun 10 at 15:39
1

I think the best option for this is going to be using the PGDump driver instead of the PostgreSQL driver, then for the append operations you can use the CREATE_TABLE=OFF layer creation option.

The initial command would be something like

gdal_contour -f PGDump -a elevation -i 10 srtm/S01W069.hgt | psql --host=volcano-db --user=postgres contour"

Then the append operations would be

gdal_contour -f PGDump -lco CREATE_TABLE=OFF -a elevation -i 10 srtm/S01W069.hgt | psql --host=volcano-db --user=postgres contour"
  • Thanks Jesse but I think user30184 have a better idea copying the inserted data to another table and allowing the erase opperation. It will be a database opperation instead two gdal_contour leaving my client-side processor cold. – Magno C Jun 10 at 15:43
1

Solved as follow:

First step: Import HGT data to a temp table:

gdal_contour -f PostgreSQL -a elevation -nln contour_lines -i 10 srtm/S01W069.hgt "PG:host=volcano-db user=postgres password=guesswhat dbname=contour" -lco OVERWRITE=YES

Step two: Try to COPY the data to the final table. Will fail if we are in the first loop iteration since the table doesn't exixts. Success in the Nth iteration

psql "host='volcano-db' dbname='contour' user='postgres' password='guesswhat'" -c "insert into contour ( select * from contour_lines);"

Step 3: Now we try to COPY-CREATE to the final table. Will fail if we are in the Nth iteration. Success if in the first iteration.

psql "host='volcano-db' dbname='contour' user='postgres' password='guesswhat'" -c "create table if not exists contour as ( select * from contour_lines);"

Go to step 1 to the next HGT file. Will override the old data in temp table.

We can drop the temp table at the end. The overhead will be at server-side.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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