0

I have a raster file with 68M pixels and a shapefile with 83 polygons covering the same area.

I would like to find, for each pixel, which polygon it is located. If there is more than one polygon per pixel, I would like to choose one based on the predominant area, but if it is very "machine expensive", it could be a random choice as well.

I have both layers in a PostGIS DB, and I tried to do it using PostGIS ST_Intersects but it will take ages to do that, even in my very fast workstation and using geo-indexes (I tested with a small part of the raster data).

How can I do this using ArcGIS Desktop or python?

  • If you wish to ask a similar question about QGIS then that is fine to do as a separate question. – PolyGeo Jul 12 '18 at 21:41
2

You mentioned having access to arcGIS, so I my instructions will refer to its tools. Usually you don't identify every single cell of raster data as an individual, as you would vector data. It is more common to use raster as entire layers and then use raster math (aka map algebra) to perform analysis using multiple layers.

I see two possible workflows depending on what your actual goal is:

1- convert the polygon to raster and set the environment setting so the cell size and snap raster match your raster layer. This will give you a new raster, with one value for every cell location. Then you can use map algebra to compare/combine the data in your zone layer and your exiting raster. See: https://gisgeography.com/map-algebra-global-zonal-focal-local/

OR 2 - use the "Zonal Statistics" tool. You can use the polygon layer as the zones, pick which field in the polygon layer is the "ID" and the raster as the "value raster". You will get a new raster where each cell has a single value from the field you selected from your polygon layer. The tool comes with lots of options for how you want the zones interpreted. Max/min etc. See: http://desktop.arcgis.com/en/arcmap/10.5/tools/spatial-analyst-toolbox/zonal-statistics.htm

  • I think option 2 this is the preferable way to make raster and vector play nice together, but I have found that Zonal Stats fails to account for the area of pixels. That is, if the polygon zone overlaps, say, 49% of a pixel but fails to contain the pixel center point then the pixel is not counted. Depending on the size/resolution of the raster and the polygon zones, this can be either ignored as a rounding error, or could dramatically skew results. I do not know if this is still an issue in the current release, but I believe I last saw it in 10.3 – Zipper1365 Jul 12 '18 at 20:24
  • 1
    JMers, I did the first option and it worked fine. It was very fast as well.Tks! – Mauro Assis Jul 13 '18 at 20:32
1

With that many pixels I hesitate to offer this solution as it will get bogged down during processing and drawing, but you should have access to Raster to Point (Conversion) at all license levels of ArcGIS. It will convert each pixel to a vector point (at the center of the pixel)

You can then do a "spatial join or "select by location" or "intersect" of your points against your polygon zones.

the limitation of this is that the pixels loose their area as they are reduced to pixel center point. So another method to vectorize the raster data is to run Raster to Polygon. If you run this and unselect the option to "simplify points", then the area of the pixels will be retained, at which time you can intersect, union, spatial join etc.

68M pixels to convert to vector features is a lot though, and I suspect at that scale it could make the software unstable.

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.