5

I want to convert point data into a grid and used the gdal tool rasterize. The tool works but unfortunately the result looks like this.

enter image description here

The converted point does not represent the center of the grid but the topleft corner. I need it to be in the center. I couldn't find any settings in the tool nor Explanation in the GDAL-Documentation to accomplish that.

Does anyone have suggestions?

I rasterrized the points into raster and NOT raster to point.

If I upload the data directly as raster I get them correct but that doesn't always work. In the picture the underlying raster image is the correct one.

enter image description here

  • By default gdal is using the top left corner of a pixel as an anchor point. You can shift the image with gdal_edit gdal.org/programs/gdal_edit.html by using option -a_ullr ulx uly lrx lry: Assign/override the georeferenced bounds of the dataset. but it is not very handy. – user30184 Dec 17 '19 at 16:56
  • Can you use the QGIS tool Raster pixels to points? It creates points in the center of each pixel. – csk Dec 17 '19 at 17:43
  • The whole point behind raster data format is using uniform-sized cells to represent continuous data. While it might be possible to calculate an origin and pixel dimensions that result in all your points being centered in pixels, the resulting raster is likely to be too large to use. Using raster format means working with approximations. It's best to let go of this "must be centered" requirement before it makes your datasets unusable. – Vince Jan 5 at 13:30
  • 1
    hmm but I learned that the value of a cell represents the center point of the cell. If I have a for example a 50m to 50m square cell and an elevation value of 100m for that cell than it means that 100m is the height of the middle of that cell. My point data have a height field and the way its rasterized now, the 100m is not in the middle but in the top left. Its inaccurate. I the example I used above I can directly import elevation data as raster and get them correct. Sometimes it doesn't work so I need to convert them to raster which is inaccurate. – DGIS Jan 5 at 15:06
  • the size of each raster cell should be 1m and the outputraster unit is "georeferenced unit" and the extent I chose is the extent of the Point layer. It is: 32346264.0,32346299.0,5631990.0,5631999.0 [EPSG:4647]. How do I add the half pixel size? – DGIS Jan 6 at 14:14
1
+50

Just modify the extent to so that xmin = xmin - 1/2 pixel, xmax = xmax + 1/2 pixel, ymin = min - 1/2 pixel, ymax = ymax + 1/2 pixel.

i.e assuming your desired pixel size is 1m and your point layer extent is xmin, xmax, ymin, ymax = 32346264.0,32346299.0,5631990.0,5631999.0

Then set your extent to 32346263.5,32346299.5,5631989.5,5631999.5

enter image description here

enter image description here

1

You can change the type of GeoTIFF into PixelIsPoint with gdal_edit https://gdal.org/programs/gdal_edit.html but you must use a special configuration option that seems to lack documentation at the first sight https://trac.osgeo.org/gdal/wiki/ConfigOptions#GTIFF_POINT_GEO_IGNORE. There is some more documentation in https://trac.osgeo.org/gdal/wiki/rfc33_gtiff_pixelispoint

It is not necassary to understand the details for running this command:

gdal_edit -mo AREA_OR_POINT=point --config GTIFF_POINT_GEO_IGNORE YES your_tiff.tif

Gdal_edit is Python script. It can be run as above in the OSGeo4W shell. In other environments you must have Python and GDAL Python bindings available and you may need to call the script like python gdal_edit.py ...

This screenshot shows how gdal_edit is supposed to be available in the OSGeo4W Shell

enter image description here

It the OSGeo4W Shell the command is actually launching a bat file "gdal_edit.bat" which is starting the Python script as python "%OSGEO4W_ROOT%\bin\gdal_edit.py"

  • sorry for the late answer, but now I have time for this issue again. So, I tried to use your command in the OSGeo4W Shell but it says " the command gdal_edit is either misspelled or couldn't be found" is there also a way to just use QGIS without the OSGeo4W Shell? – DGIS Dec 29 '19 at 13:08
  • tyr it from qgis python console. import os os.system("gdal_edit -mo AREA_OR_POINT=point --config GTIFF_POINT_GEO_IGNORE YES your_tiff.tif") – B-C B. Jan 6 at 23:34
  • I can't say why the command is not found in your system. Does o-help |find "edit"list the command for you? What does python --versionshow? – user30184 Jan 7 at 7:28

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.