API Documentation¶
Reader¶
- class papotch.reader.AbstractReader(uri: str | Path, **kwargs)¶
Abstract class for Readers.
An class inheriting from AbstractReader must implement an extract() method responsible for returning a Data instance.
- class papotch.reader.Reader(uri: str | Path | bytes, layer: int | str | None = None, encoding: str | None = None, columns: str | Sequence[str] | None = None, where: str | None = None, max_features: int | None = None, bbox: tuple[float, float, float, float] | None = None, **kwargs)¶
Class extracting Data using the polars_st read_file() function.
Extends AbstractReader.
- Parameters:
uri (str | Path | bytes) – Path to the data source
layer (int | str | None = None) – Index or name of the layer to read
encoding (str | None = None) – Data encoding
columns (str | Sequence[str] | None = None) – Column(s) to read from the source
where (str | None = None) – SQL condition to filter data
max_features – Maximum number of features to read
bbox (tuple[float, float, float, float] | None = None) – Bounding box spatially filtering read data
Data¶
- class papotch.data.Data(df: DataFrame, active_geometry: str = 'geometry')¶
The central class holding the data.
This is a thin wrapper around a polars DataFrame, passed from polars_st.
- Parameters:
df (polars.DataFrame) – The DataFrame to be processed.
active_geometry (str) – The current geometry column used for the processing.
- affine_transform(matrix: Sequence[float]) Self¶
- area(column_name: str = '_area') None¶
- attribute_join(other: DataFrame, left_on: str, right_on: str, how: str = 'inner') None¶
- boundary() Self¶
- bounds(column_name: str = '_bounds') None¶
- buffer(distance: float) Self¶
- build_area() Self¶
- calculate_attribute(*exprs, **named_exprs) None¶
- center() Self¶
- centroid() Self¶
- clip_by_rect(rect: tuple[float, float, float, float]) Self¶
- clone()¶
- collect(into: Literal['Unknown', 'Point', 'LineString', 'Polygon', 'MultiPoint', 'MultiLineString', 'MultiPolygon', 'GeometryCollection', 'CircularString', 'CompoundCurve', 'CurvePolygon', 'MultiCurve', 'MultiSurface', 'Curve', 'Surface', 'PolyhedralSurface', 'Tin', 'Triangle'] | None = None) Self¶
- concave_hull() Self¶
- convex_hull() Self¶
- coordinate_dimension(column_name: str = '_coord_dim') None¶
- coordinates(column_name: str = '_coord') None¶
- count_coordinates(column_name: str = '_n_coord') None¶
- count_geometries(column_name: str = '_n_geom') None¶
- count_interior_rings(column_name: str = '_n_rings') None¶
- count_points(column_name: str = '_n_points') None¶
- coverage_union_all() Self¶
- delaunay_triangles(tolerance: float = 0.0, only_edges: bool = False) Self¶
- difference_all(grid_size: float | None = None) Self¶
- dimensions(column_name: str = '_dimensions') None¶
- distance(other: Self, column_name: str = '_distance') None¶
- drop_attribute(attributes: list[str] | str) None¶
- envelope() Self¶
- explore()¶
- exterior_ring(column_name: str = '_ext_ring') Self¶
- extract_unique_points() Self¶
- filter_attribute(*args, **kwargs) None¶
- flip_xy() Self¶
- force_2d() Self¶
- force_3d(default_z: float) Self¶
- frechet_distance(other: Self, density: float, column_name: str = '_frechet') None¶
- geometry_type(column_name: str = '_geom_type') None¶
- get_nth_geometry(column_name: str = '_nth_geom', index: int = 0) Self¶
- get_nth_interior_ring(column_name: str = '_nth_ring', index: int = 0) Self¶
- get_nth_point(column_name: str = '_nth_point', index: int = 0) Self¶
- group_by_attributes(columns: Sequence[str], geom_agg: Literal['coverage_union', 'union', 'difference', 'symmetric_difference', 'collect', 'intersection', 'total_bounds'] = 'coverage_union')¶
- group_by_collect(columns: Sequence[str]) Self¶
- group_by_coverage_union() Self¶
- group_by_difference() Self¶
- group_by_intersection(columns: Sequence[str]) Self¶
- group_by_union() Self¶
- has_m(column_name: str = '_has_m') None¶
- has_z(column_name: str = '_has_z') None¶
- hausdorff_distance(other: Self, density: float, column_name: str = '_hausdorff') None¶
- head(n: int = 5) None¶
Print the first lines of Data.
- Parameters:
n (int) – The number of rows to print
- interior_rings(column_name: str = '_int_rings') None¶
- interpolate(distance: float, normalize: bool) Self¶
- intersection_all(grid_size: float | None = None) Self¶
- is_ccw(column_name: str = '_is_ccw') None¶
- is_closed(column_name: str = '_is_closed') None¶
- is_empty(column_name: str = '_is_empty') None¶
- is_ring(column_name: str = '_is_ring') None¶
- is_simple(column_name: str = '_is_simple') None¶
- is_valid(column_name: str = '_is_valid') None¶
- is_valid_reason(column_name: str = '_is_val_r') None¶
- length(column_name: str = '_length') None¶
- line_merge(directed: bool) Self¶
- m(column_name: str = '_m') None¶
- make_valid() Self¶
- minimum_clearance(column_name: str = '_min_clear') None¶
- minimum_rotated_rectangle() Self¶
- multi() Self¶
- node() Self¶
- normalize() Self¶
- offset_curve(distance: float, quad_segs: int = 8, join_style: Literal['round', 'mitre', 'bevel'] = 'round', mitre_limit: float = 5.0) Self¶
- plot(**kwargs)¶
- point_on_surface() Self¶
- polygonize() Self¶
- precision(column_name: str = '_precision') None¶
- project(other: Self, normalize: bool) Self¶
- remove_repeated_points() Self¶
- rename_attribute(attribute: str, new_name: str) None¶
- reverse() Self¶
- rotate(angle: float, origin: Literal['center', 'centroid'] | Sequence[float] = 'center') Self¶
- scale(x: float, y: float, z: float, origin: Literal['center', 'centroid'] | Sequence[float] = 'center') Self¶
- segmentize(max_length: float) Self¶
- set_precision(grid_size: float, mode: Literal['valid_output', 'no_topo', 'keep_collapsed'] = 'valid_output') None¶
- set_srid(srid: int) None¶
- simplify(tolerance: float, preserve_topology: bool) Self¶
- skew(x: float, y: float, z: float, origin: Literal['center', 'centroid'] | Sequence[float] = 'center') Self¶
- snap(other: Self, tolerance: float) Self¶
- spatial_join(other: DataFrame, predicate: str, how: str = 'inner') None¶
- srid(column_name: str = '_srid') None¶
- substring(start: int, end: int) Self¶
- symmetric_difference_all(grid_size: float | None = None) Self¶
- tail(n: int = 5) None¶
Print the last lines of Data.
- Parameters:
n (int) – The number of rows to print
- to_dict(column_name: str = '_dict') None¶
- to_ewkt(column_name: str = '_ewkt') None¶
- to_geojson(column_name: str = '_geojson') None¶
- to_shapely(column_name: str = '_shapely') None¶
- to_srid(srid: int) None¶
- to_wkt(column_name: str = '_wkt') None¶
- total_bounds() Self¶
- translate(x: float = 0.0, y: float = 0.0, z: float = 0.0) Self¶
- unary_union(grid_size: float) Self¶
- union(other: Self, grid_size: float | None = None) Self¶
- union_all(grid_size: float | None = None) Self¶
- voronoi_polygons(tolerance: float = 0.0, extend_to: bytes | None = None, only_edges: bool = False) Self¶
- write(path: str, layer: str, driver: str, **kwargs) None¶
- write_geojson(path: str, **kwargs) None¶
- write_gpkg(path: str, layer: str | None = '_layer', **kwargs) None¶
- write_postgis(uri: str, layer: str, **kwargs) None¶
- write_shapefile(path: str, **kwargs) None¶
- x(column_name: str = '_x') None¶
- y(column_name: str = '_y') None¶
- z(column_name: str = '_z') None¶
- property active_geometry: str¶
Return the name of the active geometry.
- Returns:
The name of the active geometry
- Return type:
str
- property df: DataFrame¶
Return the underlying DataFrame.
- Returns:
The polars DataFrame hosting the data
- Return type:
polars.DataFrame
- property extent: Self¶
Return the extent of the DataFrame.
- Returns:
A Data with a single rectangle geometry
- Return type:
- property schema: dict¶
Return the schema of the Data instance.
- Returns:
The dictionnary of the field names and types
- Return type:
dict
- property shape: tuple[int, int]¶
Return the shape of the Data instance.
- Returns:
The number of lines and columns of the Data
- Return type:
tuple[int, int]