2

I want to import a large amount of ASTER DEM data into PostGIS (covering Europe). I use this script: https://wiki.openstreetmap.org/wiki/Contour_relief_maps_using_mapnik#Importing_ASTER_GDEMv2_data

The script creates the contour lines (gdal_contour) for every DEM tile in the form of a shapefile, then appends the data (shp2pgsql) to the contour table in postgis. The only thing I added is -s 4326:900913 to the shp2pgsql command.

Everything works, except the contour lines are not continuous at the tile borders (the borders of the DEM tiles): enter image description here

The DEM tiles overlap by one pixel. I also tried to crop it, then there is no overlap like in the picture, but an offset between the contour lines.

How is it possible to import the DEM data and get continuous contour lines at the borders of the DEM tiles?

PS: I tried to merge all DEM tiles and generate one big shapefile. But gdal_contour aborts at the file size of 4GB.

  • Your first/best option is to not use shapefile at all (it actually has a 2Gb limitation -- 4Gb is a non-conformant GDAL extension). From there I'd suggest mosaicking in skinny/tall strips, and clipping along east/west bounds , then stitching the contours together by value. If the lines are too dense, generate in modulus. Or you can just a acquire contours generated by others. – Vince Jan 23 at 11:38
  • Hi, thanks for the quick answer. The process I described basically uses mosaics. It processes every single DEM tile, which is 1°x1° and only around 25MB big. No storage problems occur here! It is just, that the contour lines are not continuous at the border of the DEM tiles and I wonder how this can be solved. – Andreas Jan 23 at 12:27
  • 1
    Have a try by creating a virtual mosaic from the input DEMs with gdal_buildvrt, use that as input DEM and save the result into geopackage by using option -f gpkg. – user30184 Jan 23 at 12:36
  • It can't be solved in 1x1 tiles (without more work than is feasible). An answer goes on for paragraphs, in an answer block; these are just comments. – Vince Jan 23 at 12:37
  • 1
    Yes, VRT as a seamless input layer for gdal_contour. And if your aim is to get contours into PostGIS then you can naturally configure gdal_contour to write the result directly into PostGIS. I suggested geopackage because originally you were using shapefile as outputformat and suffered from the size limit. – user30184 Jan 23 at 19:53
0

Found a solution. Probably not the best and easiest, but it works. It also has nice side effect regarding performance!

Gdal_contour basically draws a line between all pixels with the same value. Of course it doesn't see outside the tile, how the line would continue. That's why the line isn't equal between two adjacent tiles at their border.

The solution was to merge all 1°x1° DEM tiles to one big GEOtiff. Then cut out tile per tile with an allowance in width and length direction. Generate the contours off the now slightly bigger tile. (That has the effect, that the contour lines are drawn further than to the final tile border. Therefore the lines of two adjacent tiles will converge in the same direction and position. A seamless look is created.) Then cut off the allowance of the shapefile (so adjacent tiles share the same border) and import the result into PostGIS.

Of course this has to be automated. Bash worked very well here.

A nice side effect is, that you can choose the tile size yourself. That creates shorter contour lines for PostGIS. I had the feeling that benefits the rendering performance a lot.

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.