3

I have a vector file containing contour with 2m accuracy, covering a large area (All Hong Kong).

I tried to generate an elevation raster map with the file, by first rasterized the vector, using v.to.rast, and then generate the elevation map, by r.surf.contour.

The output file of step 1 (v.to.rast) is approximately 60GB. The resolution is 0.3m.

When I run the second step, I got the error: unable to allocate 808507328 bytes of memory at raster surf.contour

I guess it is because the file size is too large. I am using 64 bit version of QGIS 3.6.3. I am not sure whether the Grass installed is also 64 bit.

My question: is there any better way to do this? Currently, I am trying to separate the region into multiple pieces

  • You can take a look at the following link grasswiki.osgeo.org/wiki/Memory_issues about memory allocation in grass – kartoza-geek Jun 10 at 2:30
  • Please edit your question and report also the GRASS GIS version (which is the relevant part for the question), thanks – markusN Jun 13 at 19:45
3

The logical approach is correct, but 60 Gb is a massive raster file: I would first asses if all that detail is really needed. A 0.3 raster over Hong Kong seems a little far, if the input data does not have that resolution. Keep also in mind that the contouring process by definition introduces a smoothing of the data.

If reducing the detail is not an option in your case, you must resort to tiling.

Also, you might want to try gdal_grid instead of v.to.rast.

Tiling

Use smaller regions to run r.surf. Make sure your raster tiles do overlap, otherwise contours from different tiles will not match do to border artifacts. To do so:

  • Create square tiles as polygons, this will be your base to run r.surf.contour
  • Buffer (without dissolving) by a reasonable amount (which depends on resolution, interpolation parameters, etc.). Rule of thumb: 5% of the tile width.
  • Run gdal_grid on each buffered tile.
  • Run r.surf.contour on each base tile and the corresponding interpolated raster.
  • Check for consistency how contours match at the tiles borders.
  • Optionally merge the output contours.

gdal_grid

gdal_grid -txe Xmin Xmax -tye Ymin Ymax -outsize pixel_width pixel_height \
-l input_vector_file \
-zfield name_of_field_with_elevation \
-a nearest:radius1=15.0:radius2=15.0:angle=0.0:nodata=0.0 \
-ot Float32 -of GTiff -co COMPRESS=NONE -co BIGTIFF=IF_NEEDED \
input_vector_file.shp \
output_raster_file_gdal.tif

To find out (H/T kartoza-geek) which version of Grass your PC is running, and therefore the maximum addressable memory, which in turn will help you figuring out the tile dimension:

# run next line in a GRASS GIS session:
file `which r.contour`

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.