zonal_statistics
zonal_statistics(GI::GItype, shapes::GDtype, fun::Function; touches=false, byfeatures=false, groupby="")
or
zonal_statistics(fun::Function, GI::GItype, shapes::GDtype; touches=false, byfeatures=false, groupby="")
or zonal_stats(...)
Compute the statistics of fun applied to the elements of the grid or image GI that lie inside the polygons of the GMTdataset shapes.
Arguments
GI: A grid (GMTgrid) or image (GMTimage) type uppon which the statistics will be computed by applying thefunfunction to the elements that fall inside the polygons ofshapes.shapes: A vector of GMTdataset containing the polygons inside which the elements ifGIwill be assigned a single value obtained by applying the functionfun.fun: A unidemensional function name used to compute the contant value for theGIelements that fall inside each of the polygons ofshapes.
Parameters
touches: include all cells/pixels that are touched by the polygons. The default is to include only the cells whose centers that are inside the polygons.byfeatures: Datasets read from OGR vector filres (shapes, geopackages, arrow, etc) are organized in features that may contain several geomeometries each. Each group of geometries in a Feature share the sameFeauture_IDatribute. Ifbyfeaturesis true, the functionfunwill be applied to each feature independently. This option is actually similar to thegroupbyparameter but doesn’t require an attribute name. If neither ofbyfeaturesorgroupbyare provided, thefunfunction is applied to each of the polygons independently.groupby: If provided, it must be an attribute name, for example,groupby="NAME". If not provided, we use theFeature_IDattribute that is a unique identifier assigned during an OGR file reading (by the GMT6.5 C lib). If neither ofbyfeaturesorgroupbyare provided, thefunfunction is applied to each of the polygons independently.
Examples
What is the mean altitude of Swisserland?
G = gmtread("@earth_relief_06m");
Swiss = coast(DCW=:CH, dump=true, minpts=50);
zonal_statistics(G, Swiss, mean)
1×1 GMTdataset{Float64, 2}
Row │ X
─────┼─────────
1 │ 1313.21Methods
# 2 methods for generic function "zonal_statistics" from GMT:
[1] zonal_statistics(GI::GItype, shapes::GDtype, fun::Function; touches, byfeatures, groupby)
[2] zonal_statistics(fun::Function, GI::GItype, shapes::GDtype; touches, byfeatures, groupby)