API#
Reusable Python region geospatial utilities.
- class pyregeon.RegionMixin#
Mixin class to add a region attribute to a class.
The region property setter accepts the following values:
A string with a place name (Nominatim query) to geocode (requires osmnx).
A sequence with the west, south, east and north bounds.
A geometric object, e.g., shapely geometry, or a sequence of geometric objects (polygon or multi-polygon). In such a case, the value is passed as the data argument of the GeoSeries constructor, and needs to be in the same CRS as the one provided through the crs argument.
A geopandas geo-series or geo-data frame.
A filename or URL, a file-like object opened in binary (‘rb’) mode, or a Path object that will be passed to geopandas.read_file.
- generate_regular_grid_gser(res, *, offset=None, geometry_type=None, grid_index_name=None)#
Get a regular grid within a region.
- Parameters:
res (float or tuple of floats.) – The grid resolution in units of the region’s CRS. A scalar value will be interpreted as the same resolution in both x and y directions, whereas a tuple will be interpreted as the resolution in the x and y directions, respectively.
crs (CRS-like, optional) – The CRS of the grid, required if the region is a naive geometry (without a CRS set), ignored otherwise.
offset ({"center", "top-left"}, optional) – If set to “center” and the region dimensions and target resolution do not divide evenly, the grid is offsetted so that the region bounds are in the center of the grid. If set to “top-left”, the grid starts at the top-left corner of the region. If None, the default value set in settings.GRID_OFFSET will be used. Ignored if the region dimensions and the desired resolution divide evenly.
geometry_type ({"point", "polygon"}, optional) – The type of geometry to return. If “point”, the grid will be returned as a GeoSeries of points. If “polygon”, the grid will be returned as a GeoSeries of polygons. If None, the default value set in settings.GRID_GEOMETRY_TYPE will be used.
grid_index_name (str, optional) – The name of the index of the grid GeoSeries. If None, the default value set in settings.GRID_INDEX_NAME will be used.
- Returns:
grid_gser – A geo-series representing the generated grid.
- Return type:
gpd.GeoSeries
- property region: GeoDataFrame | None#
The region as a GeoDataFrame.
- pyregeon.generate_regular_grid_gser(region_gser, res, *, crs=None, offset=None, geometry_type=None, grid_index_name=None)#
Get a regular grid within a region.
- Parameters:
region (region-like) – The region for which to generate the grid.
res (float or tuple of floats.) – The grid resolution in units of the region’s CRS. A scalar value will be interpreted as the same resolution in both x and y directions, whereas a tuple will be interpreted as the resolution in the x and y directions, respectively.
crs (CRS-like, optional) – The CRS of the grid, required if the region is a naive geometry (without a CRS set), ignored otherwise.
offset ({"center", "top-left"}, optional) – If set to “center” and the region dimensions and target resolution do not divide evenly, the grid is offsetted so that the region bounds are in the center of the grid. If set to “top-left”, the grid starts at the top-left corner of the region. If None, the default value set in settings.GRID_OFFSET will be used. Ignored if the region dimensions and the desired resolution divide evenly.
geometry_type ({"point", "polygon"}, optional) – The type of geometry to return. If “point”, the grid will be returned as a GeoSeries of points. If “polygon”, the grid will be returned as a GeoSeries of polygons. If None, the default value set in settings.GRID_GEOMETRY_TYPE will be used.
grid_index_name (str, optional) – The name of the index of the grid GeoSeries. If None, the default value set in settings.GRID_INDEX_NAME will be used.
region_gser (GeoSeries)
- Returns:
grid_gser – A geo-series representing the generated grid.
- Return type:
gpd.GeoSeries