# Creating raster or vector raster from DEM point file?

i have a point shape of 75.000 elevation points in a regular 5 m grid. We now want to create a polygon grid with the elevation points as "centroids".

Unfortunately, all attempts to do so fail: I first thought to create a raster from the point grid, and then vectorize the raster to get my polygon grid. Bu when i create a raster image from the points, the cells are created with the points representing the corners of this cell.

So, how to create a raster image or polygon grid from regular points, where those points represent the centroid ?

-

You could use gdal_rasterize either from the command line or QGIS to generate your raster. To make sure your points sit within a cell, you need to do two things. First, set the target resolution to 5m, and set the extents to be 2.5m bigger all around than the source data.

So, assuming your dataset goes from `[1000 2000] [2500 3250]`, giving you your 75,000 points, you'd use something like this:

``````gdal_rasterize -3d -te 997.5 1997.5 2502.5 3252.5 -tr 5.0 5.0 -ot Float32 -l heights dem.shp dem.tif
``````

This assumes your height data is in a Z point attribute, otherwise just use `-a <attribute_name>` instead of `-3d`

-
+1 This is by far more efficient than any vector-based solutions would be. – whuber Jun 26 '12 at 14:55
Also note that this is available through and API for C, Python, etc. – Mike T May 7 '14 at 0:17

You could try to create a Voronoi diagram. It seems to work:

If the Voronoi tool should fail on 75,000 points, try divide&conquer: Split the point layer into multiple smaller ones to make computation easier.

-

I went straight into MerseyViking's answer and dared to go the command line way and didn't try underdarks proposal so far.

• I opend the layer informations and copied the BoundingBox informations for my point layer from the Metadata-Tab.

In Bezugssystemeinheiten des Projekts : xMin,yMin 4494905.00;5646140.00 : xMax,yMax 4499105.00;5648025.00

For the convenience of not to have another program to store my steps, i used the `qnote plugin` to keep track of my actions, so i copied the data there

• Next i copied the example from MerseyViking

gdal_rasterize -3d -te 997.5 1997.5 2502.5 3252.5 -tr 5.0 5.0 -ot Float32 -l heights dem.shp dem.tif

and then changed the parts piece by piece to adopt the example to my data.

As is have a point shape with the hight in a field named `Hoehe` i have to substitute the `-3d` with the `-a Hoehe`and remove the part with `-l heights`.

• Then i copied my coordinates from the metadata in the exact order into the command line draft. I was told to extend my area by 2.5 meters to get the outer rows of points included, i manipulated the coordinates following this pattern:

xMin = xMin-2.5 ; yMin = yMin-2.5 ; xMax = xMax=xMax+2.5 ; yMax = yMax+2.5 (or the other way around, i'm still confused)

The resulting command line for my example looks like this:

gdal_rasterize -a Hoehe -te 4494902.5 5646137.5 4499107.5 5648027.5 -tr 5.0 5.0 -ot Float32 C:/Users/vogelbe/Documents/TEMP/DGM_Vektor_p/DGM_Vektor_p.shp C:/Users/vogelbe/Documents/TEMP/DGM_Vektor_p/dem.tif

Then i started the OSGeo4w command line shell from the desktop link and pasted the line. It took approximately 3 seconds to create the raster file (ok, i leave out all my attempts till i finally succeeded)

I loaded the raster image into qgis and it really perfectly fits.

The last step was only a half success: Vectorizing the raster back, so i get the cells as polygons with Raster -> Conversion -> Raster to Vector produces a vector layer, where all adjacent cells with the same hight value are dropped into a single polygon. This conversion was really quick as well, and actually i think, for further actions on the data, these polygons are as fine as having single polygons for each point. So, i am happy :)

Thanx a lot for you answers.

-