Core data structures#
- class Blocks[source]
Class stores and prepares aggregated data.
Examples
>>> geocls = Blocks() >>> geocls.from_file('testfile.shp', value_col='val', geometry_col='geometry', index_col='idx') >>> parsed_columns = geocls.data.columns >>> print(list(parsed_columns)) (idx, val, geometry, centroid.x, centroid.y)
- Attributes:
- datagpd.GeoDataFrame
Dataset with block values.
- value_column_nameAny
Name of the column with block rates.
- geometry_column_nameAny
Name of the column with a block geometry.
- index_column_nameAny
Name of the column with the index.
Methods
from_file()
Reads and parses data from spatial file supported by GeoPandas.
from_geodataframe()
Reads and parses data from GeoPandas
GeoDataFrame
.- from_file(fpath, value_col, geometry_col='geometry', index_col=None, layer_name=None, **kwargs)[source]
Loads areal dataset from a file supported by GeoPandas.
- Parameters:
- fpathstr
Path to the spatial file with appropriate extension such as
.shp
,- ``.gpkg``, ``.feather``, or ``.parquet``.
- value_colAny
The name of a column with values.
- geometry_coldefault=’geometry’
The name of a column with blocks.
- index_coldefault = None
Index column name. It could be any unique value from a dataset. If not given then index is taken from the index array of
GeoDataFrame
, and it is named'index'
.- layer_nameAny, default = None
The name of a layer with data if provided input is a gpkg file.
- **kwargsAny
Additional kwargs parameters passed to the
geopandas.read_file()
,geopandas.read_feather()
orgeopandas.read_parquet()
functions.
- Raises:
- IndexColNotUniqueError
Raised when given index column has not unique values.
- from_geodataframe(gdf, value_col, geometry_col='geometry', index_col=None)[source]
Loads areal dataset from a GeoDataFrame supported by GeoPandas.
- Parameters:
- gdfgpd.GeoDataFrame
- value_colAny
The name of a column with values.
- geometry_colAny, default = ‘geometry’
The name of a column with blocks.
- index_colAny, default = None
If set then a specific column is treated as an index.
- Raises:
- IndexColNotUniqueError
Given index column values are not unique.
- class PointSupport(log_not_used_points=False)[source]
Class prepares the point support data in relation to block dataset.
- Parameters:
- log_not_used_pointsbool, default=False
Should dropped points be logged?
Notes
The PointSupport class structure is designed to store the information about the points within polygons. During the regularization process, the inblock variograms are estimated from the polygon’s point support, and semivariances are calculated between point supports of neighbouring blocks.
The class takes population grid (support) and blocks data (polygons). Then, spatial join is performed and points are assigned to areas within they are placed. The core attribute is
point_support
- GeoDataFrame with columns:x_col
- a floating representation of longitude,y_col
- a floating representation of latitude,value_column
- the attribute which describes the name of a column with the point-support’s value,geometry_column
- the attribute which describes the name of a geometry column withPoint()
representation of the point support coordinates,block_index_column
- the name of a column which directs to the block index values.
Examples
>>> import geopandas as gpd >>> from pyinterpolate import PointSupport >>> >>> >>> POPULATION_DATA = "path to the point support file" >>> POLYGON_DATA = "path to the polygon data" >>> GEOMETRY_COL = "geometry" >>> POP10 = "POP10" >>> POLYGON_ID = "FIPS" >>> >>> gdf_points = gpd.read_file(POPULATION_DATA) >>> gdf_polygons = gpd.read_file(POLYGON_DATA) >>> point_support = PointSupport() >>> out = point_support.from_geodataframes(gdf_points, ... gdf_polygons, ... point_support_geometry_col=GEOMETRY_COL, ... point_support_val_col=POP10, ... blocks_geometry_col=GEOMETRY_COL, ... blocks_index_col=POLYGON_ID)
- Attributes:
- point_supportgpd.GeoDataFrame
Dataset with point support values and indexes of blocks (where points fall into).
- value_columnstr
The value column name
- geometry_columnstr
The geometry column name.
- block_index_columnstr
The area index.
- x_colstr, default = “x_col”
Longitude column name.
- y_colstr, default = “y_col”
Latitude column name.
- log_droppedbool
See log_not_used_points parameter.
Methods
from_files()
Loads point support and polygon data from files.
from_geodataframes()
Loads point support and polygon data from dataframe.
- from_files(point_support_data_file, blocks_file, point_support_geometry_col, point_support_val_col, blocks_geometry_col, blocks_index_col, use_point_support_crs=True, point_support_layer_name=None, blocks_layer_name=None, **kwargs)[source]
Methods prepares the point support data from files.
- Parameters:
- point_support_data_filestr
Path to the file with point support data. Reads all files processed by the GeoPandas with appropriate extension such as
.shp
,.gpkg
,.feather
, or.parquet
.- blocks_filestr
Path to the file with polygon data. Reads all files processed by GeoPandas with appropriate extension such as
.shp
,- ``.gpkg``, ``.feather``, or ``.parquet``.
- point_support_geometry_colAny
The name of the point support geometry column.
- point_support_val_colAny
The name of the point support column with values.
- blocks_geometry_colAny
The name of the polygon geometry column.
- blocks_index_colAny
The name of polygon’s index column (must be unique!).
- use_point_support_crsbool, default = True
If set to
False
then the point support crs is transformed to the same crs as polygon dataset.- point_support_layer_nameAny, default = None
If provided file is .gpkg then this parameter must be provided.
- blocks_layer_nameAny, default = None
If provided file is .gpkg then this parameter must be provided.
- **kwargsAny
Additional kwargs parameters passed to the
geopandas.read_file()
,geopandas.read_feather()
orgeopandas.read_parquet()
functions.
- from_geodataframes(point_support_dataframe, blocks_dataframe, point_support_geometry_col, point_support_val_col, blocks_geometry_col, blocks_index_col, use_point_support_crs=True)[source]
Methods prepares the point support data from files.
- Parameters:
- point_support_dataframeGeoDataFrame or GeoSeries
- blocks_dataframeGeoDataFrame
Block data with block indexes and geometries.
- point_support_geometry_colAny
The name of the point support geometry column.
- point_support_val_colAny
The name of the point support column with values.
- point_support_val_colAny
The name of the point support column with values.
- blocks_geometry_colAny
The name of the polygon geometry column.
- blocks_index_colAny
The name of polygon’s index column (must be unique!).
- use_point_support_crsbool, default = True
If set to
False
then the point support crs is transformed to the same crs as polygon dataset.