13

The below code worked for me QGis 1.8.0 You might modify this to accomodate multiple files with some loop.. from qgis.analysis import QgsZonalStatistics #specify polygon shapefile vector polygonLayer = QgsVectorLayer('F:/temp/zonalstat/zonePoly.shp', 'zonepolygons', "ogr") # specify raster filename rasterFilePath = 'F:/temp/zonalstat/raster1.tif' # ...


10

What you are looking for is COUNT, which is the frequency of the cells that you processed through Zonal Statistics. Sum, on the other hand, is the sum of cell values covered by your polygon. Overly simplistically, say, your cell values are 2,1,3,4,4 in this case COUNT is 5 and SUM is 14.


9

From Esri's support site : HowTo: Create points representing the highest or lowest elevations within polygon features Just replace the elevation raster by the Flow Accumulation raster. Identify the value of the highest elevation within each polygon feature using the Zonal Statistics tool: Open ArcMap and navigate to ArcToolbox > Spatial Analyst ...


9

It is a bug. Something terribly wrong with cell count. Correct mean (9.0452380952381) times correct number of non-empty cells (420) divided by 297 (that is a cell count reported by tool) results in 12.7912457912458. That is a wrong average reported by tool. Results of my own toy size grids test:


8

There is a bug that seems to correspond to what you're experiencing - it's registered as BUG-000084883 - The 'Ignore NoData in calculations' option in Zonal Statistics as Table tool {and Zonal Statistics tool} is not honored when checked off, producing incorrect results. It occurs with 10.3 and 10.2.2 but not 10.1. Did you try the tool with this version?


7

The Modifiable Aerial Unit Problem (MAUP) is a change of support issue associated with arbitrary aggregate units. Two classic examples are census tracks and wildlife game units. These have been found to be arbitrary political units and the underlying statistical response in demography acts independent of the unit. Because of this, the unit is not an accurate ...


6

With multiprocessing, for fastness! Has a little different output-formatting. #!/usr/bin/python import gdal, ogr, osr, numpy, sys from multiprocessing import Pool # Raster dataset input_value_raster = sys.argv[1] # Vector dataset(zones) input_zone_polygon = sys.argv[2] # Open data rast = gdal.Open(input_value_raster) shp = ogr.Open(input_zone_polygon) # ...


6

Use arcpy.env.overwriteOutput. arcpy.env.overwriteOutput = True # Execute ZonalStatisticsAsTable outZSaT = ZonalStatisticsAsTable(inZoneData, zoneField, inValueRaster, outTable, "NODATA", "MEAN")


5

If you want to get zonal statistics for several features in one shapefile, you have to loop over the zonal_stats function. You can write the results of the loop for example to a dictionary. Below is the modified zonal_stats function together with a loop, looping over the input shapefile. As an output you get a Dictionary containing for each Feature ID the ...


5

For a count of "lit" pixels--or of any other kind of cell value for that matter--simply create a binary indicator grid. This is a grid with ones at the cells where the values are to be counted and zeros elsewhere: it should be clear that the zonal sum of these values counts the cells. To create an indicator, exploit the fact that true values will be stored ...


5

I think you hit on your best option, which is to convert the raster to a vector and then intersect the result with your polygon layer. As a way of explanation regarding the frustration you're experiencing with Zonal Statistics (and actually this will also apply to your idea of cropping or "clipping" the raster), there is no alternative way for this to ...


5

When pixels are large comparing with polygons you better go "vector way". i.e. vectorize the raster tiles and then procede to a vector/vector intersection/computation. If you use the PostGIS Addons, you can do it like this: SELECT gt.id, (aws).geom, (aws).totalarea, (aws).weightedmean, FROM (SELECT id, ST_AreaWeightedSummaryStats(gv) ...


5

For calculating stats from raster cells intersected by line, you can use GRASS v.rast.stats directly from QGIS processing toolbox. It can calculate 13 different stats.


4

This is explained in the Zonal Statistics help: If the zone input is a feature dataset with relatively small features, keep in mind that the resolution of the information needs to be appropriate relative to the resolution of the value raster. If the areas of single features are similar to or smaller than the area of single cells in the value raster, in ...


4

I would use a zonal statistics analysis to investigate the relationship between crime rate and land price. Use Zonal Statistics as Table (Spatial Analyst) tool with these settings: in_zone_data = crime rate zone_field = label (field of crime rate) in_value_raster = land price statistics_type = all The result is a table. Use Excel to create a chart. ...


4

Begin with the elevation raster (the DSM). Compute focal minima and maxima using 2m radial neighborhoods, producing two new rasters. Subtract the original raster from these focal rasters. Take the absolute values of the differences. Compute the local maximum of the two absolute differences in (2): this gives the largest height deviation within 2 meters of ...


4

Unfortunately, because ArcGIS's source code is not publicaly available, we cannot know for certain how ESRI treats boundary locations when you provide a vector zone layer input. However, as DanC points out above, it is very likely that there is some kind of internal vector-to-raster conversion that is taking place such that the vector zone layer is mapped ...


4

The Focal Statistics tool in Spatial Analyst can take care of the local maxima. Unfortunately, the size and shape of the neighborhood around the focal cell is fixed for the entire run. Thus, you will need to rerun Focal Statistics for each window size by adjusting the neighborhood parameter: Once you have one local maximum raster for each window size, you ...


4

With a multi-band raster input, ArcGIS will only process the first band: Multiband raster data When a multiband raster is used as input, most Spatial Analyst tools operate only on the first band. The exceptions are certain tools in the Multivariate and Extraction toolsets which do process each of the bands in a multiband input and can create a ...


4

If your tif files store integer values you might try tabulate area tool (zones-polygon ids), thus transposing the table. It'll have 4000 rows instead of 4000 columns. If value grids store floating points, convert to integer first, this will still give you good estimate of histogram. All above is worth doing providing you value raster has less than few ...


4

If you look at QgsZonalStatistics.Mean it's part of an enumeration - it's actually the integer 4. You're calling it as if it's a function. Try removing the brackets:- zoneStat = QgsZonalStatistics (polygonLayer, rasterFilePath, 'pre-', 1, QgsZonalStatistics.Mean) zoneStat.calculateStatistics(None) Note that these values are done as powers of two; to get a ...


4

I performed a quick test and it seems that you need to turn on the edit mode for obtaining the desired result. If you want to use Python for this, try to use the following code: polygonLayer.startEditing() # usage - QgsZonalStatistics (QgsVectorLayer *polygonLayer, const QString &rasterFile, const QString &attributePrefix="", int rasterBand=1) ...


4

If you look in the toolbox, exactly 1 tool below Zonal Statistics is a tool called Zonal Statistics as Table! This creates a table which you can then join back to your original polygon dataset.


4

Update as April 2018 and QGIS 2.18 The current version of Zonal Statistics Plugin can provide: Count: to count the number of pixels Sum: to sum the pixel values Mean: to get the mean of pixel values Median: to get the median of pixel values StDev: to get the standard deviation of pixel values Min: to get the minimum of pixel values Max: to get the maximum ...


4

A Robust Zonal stats in QGIS can be implemented with PyQGIS. Following code was run with your layers by using a filter to select only ID_sub.pat between 19 and 27 (showed in your image). import processing registry = QgsMapLayerRegistry.instance() Polygons = registry.mapLayersByName('Polygons') request = QgsFeatureRequest().setFilterExpression (u'"ID_sub....


4

The Zonal Statistics as Table documentation states the following: If the areas of single features are similar to or smaller than the area of single cells in the value raster, in the feature-to-raster conversion some of these zones may not be represented. I suspect the algorithm assigns raster values to the zone if that zone contains the raster ...


4

If you wrote zonal in the Processing toolbox search, you will find many: The zonal Statistics is the second one from the top.


4

You could try resampling the raster to a finer resolution. Not sure why this works but accourding to the help section for version 10.3 (not present in 10.6): If the zone input is a feature dataset with relatively small features, keep in mind that the resolution of the information needs to be appropriate relative to the resolution of the value raster. ...


3

there is another function called "zonal histogram" in ArcGIS (http://help.arcgis.com/en%20/arcgisdesktop/10.0/help/index.html#//009z000000w6000000.htm). With the table you can extract anything you want. It is however recommende to resample your nightime data before use in order to have an integer image. Don't forget to set the pixel size equal to the ...


3

mean values are appropriate for that kind of analysis, however, you may also want to include max or min quantile/quintile statistics (probably easier to do outside of arc) if disease spread is dependent on min/max temperature etc. values. you will see which is your most significant variable when you look at the correlation matrix & run the regression ...


Only top voted, non community-wiki answers of a minimum length are eligible