Wednesday, 27 December 2017

qgis - How to make polygon from cells of a raster?


I have 100 rasters, each raster has the same cell size and extent and i want to make a polygon of each cell.


Can anyone help me doing this?



Answer



I have found that although my raster files and grid vector (created in QGIS, under Vector > Geoprocessing Tools > Vector Grid) have the exact same extents and cell sizes, I still get slivers when I spatially overlay the raster and grid vector.


In order to avoid this, I used 'Add Grid Values to Shapes' in the Processing Toolbox, as shown below:



enter image description here


This allowed me to add the raster value to the grid itself, as a polygon with the same extent and cell size as my original raster. This can also be completed as a batch process by right clicking the function in the Processing Toolbox, which is helpful if you have multiple raster sets and eventually want them in the same polygon (which can be easily achieved by joining). This method also preserves decimal values from the raster, which converting from raster to polygon does not do (as using the 'Polygonize' tool in QGIS will create an integer value).


Another, longer, way it can be completed (if slivers are an issue) is to create regular points in QGIS (Vector > Research Tools > Regular Points) to make centroids for each raster cell.


enter image description here


These centroid points can be spatially joined with the polygon (converted from a raster) and the resulting points joined with the grid (by FID). When exported (Data > Export Data) into its own shapefile, this will result in the grids having the same value as the points derived from the rasters.


enter image description here


The last steps were completed in ArcMap but can also be done in QGIS, depending on what you are most familiar with.


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...