geoutils.Raster.value_at_coords#
- Raster.value_at_coords(x, y, latlon=False, band=None, masked=False, window=None, reducer_function=<numpy.ma.core._frommethod object>, return_window=False, boundless=True)[source]#
Extract raster values at the nearest pixels from the specified coordinates, or reduced (e.g., mean of pixels) from a window around the specified coordinates.
By default, samples pixel value of each band. Can be passed a band index to sample from.
- Parameters:
x (
Union
[int
,float
,integer
[Any
],floating
[Any
],_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – X (or longitude) coordinate(s).y (
Union
[int
,float
,integer
[Any
],floating
[Any
],_SupportsArray
[dtype
[Any
]],_NestedSequence
[_SupportsArray
[dtype
[Any
]]],bool
,complex
,str
,bytes
,_NestedSequence
[Union
[bool
,int
,float
,complex
,str
,bytes
]]]) – Y (or latitude) coordinate(s).latlon (
bool
) – Whether coordinates are provided as longitude-latitude.band (
int
|None
) – Band number to extract from (from 1 to self.count).masked (
bool
) – Whether to return a masked array, or classic array.window (
int
|None
) – Window size to read around coordinates. Must be odd.reducer_function (
Callable
[[ndarray
[Any
,dtype
[Union
[floating
[Any
],integer
[Any
]]]]],float
]) – Reducer function to apply to the values in window (defaults to np.mean).return_window (
bool
) – Whether to return the windows (in addition to the reduced value).boundless (
bool
) – Whether to allow windows that extend beyond the extent.
- Return type:
- Returns:
When called on a raster or with a specific band set, return value of pixel.
- Returns:
If multiple band raster and the band is not specified, a dictionary containing the value of the pixel in each band.
- Returns:
In addition, if return_window=True, return tuple of (values, arrays)
- Examples:
>>> self.value_at_coords(-48.125, 67.8901, window=3) Returns mean of a 3*3 window: v v v v c v | = float(mean) v v v / (c = provided coordinate, v= value of surrounding coordinate)