YirgacheffeLayer
A layer object represents some geospatial data. This might come from:
- A raster data source, for example, data from a GeoTIFF
- A polygon data source, for example, data from a GPKG, GeoJSON, or ESRI Shapefile
- A constant value
- An expression built up using the above inputs using operators to add, divide, etc.
yirgacheffe.YirgacheffeLayer
The common base class for the different layer types. Most still inherit from RasterLayer as deep down they end up as pixels, but this is a start to make other layers that don't need to rasterize not have to carry all that baggage.
area
property
Returns the geospatial Area of the layer.
datatype
property
Returns the DataType of the pixels within a layer.
map_projection
property
Returns the MapProjection (projection name and pixel size) of the layer.
latlng_for_pixel(x, y)
Get geo coords for pixel. This is relative to the set view window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
X axis position within raster |
required |
y
|
int
|
Y axis position within raster |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
A tuple containing the (latitude, longitude). |
pixel_for_latlng(lat, lng)
Get pixel for geo coords. This is relative to the set view window. Result is rounded down to nearest pixel.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
lat
|
float
|
Geospatial latitude in WGS84 |
required |
lng
|
float
|
Geospatial longitude in WGS84 |
required |
Returns:
| Type | Description |
|---|---|
tuple[int, int]
|
A tuple containing the x, y coordinates in pixel space. |
read_array(x, y, width, height)
Reads data from the layer based on the current reference window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
int
|
X axis offset for reading |
required |
y
|
int
|
Y axis offset for reading |
required |
width
|
int
|
Width of data to read |
required |
height
|
int
|
Height of data to read |
required |
Returns:
| Type | Description |
|---|---|
Any
|
An array of values from the layer. |
show(ax=None, max_pixels=1000, **kwargs)
Display data using matplotlib.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ax
|
Matplotlib axes object. If not provided, the default matplotlib context will be used. |
None
|
|
max_pixels
|
int | None
|
How many pixels to downsample to. If None, raw pixels will be used. |
1000
|
**kwargs
|
Passed to matplotlib imshow. |
{}
|
Returns:
| Type | Description |
|---|---|
|
A matplotlib image. |
to_geotiff(filename, and_sum=False, parallelism=None, callback=None, nodata=None)
Saves a calculation to a raster file, optionally also returning the sum of pixels.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filename
|
Path | str
|
Path of the raster to save the result to. |
required |
and_sum
|
bool
|
If true then the function will also calculate the sum of the raster as it goes and return that value. |
False
|
parallelism
|
int | bool | None
|
If passed, attempt to use multiple CPU cores up to the number provided, or if set to True, yirgacheffe will pick a sensible value. |
None
|
callback
|
Callable[[float], None] | None
|
If passed, this callback will be called periodically with a progress update for the saving, with a value between 0.0 and 1.0. |
None
|
nodata
|
float | int | None
|
Nominate a value to be stored as nodata in the result |
None
|
Returns:
| Type | Description |
|---|---|
float | None
|
Either returns None, or the sum of the pixels in the resulting raster if |