pylusat.geotools module

pylusat.geotools.erase(input_gdf, erase_gdf=None)

Erase erase_gdf from input_gdf.

Parameters:
Returns:

output – The remaining features after erasure.

Return type:

geopandas.GeoDataFrame

pylusat.geotools.spatial_join(target_gdf, join_gdf, op='intersects', cols_agg: Dict[str, list] | None = None, join_type='one to one', keep_all=True)

Spatial join two GeoDataFrames.

Parameters:
  • target_gdf (geopandas.GeoDataFrame) – The GeoDataFrame to join to the target GeoDataFrame.

  • join_gdf (geopandas.GeoDataFrame) – The GeoDataFrame to join to the target GeoDataFrame.

  • op (string, default 'intersects') – Binary predicate, one of {‘intersects’, ‘contains’, ‘within’}. See http://shapely.readthedocs.io/en/latest/manual.html#binary-predicates.

  • cols_agg (dict, default None) – Dict of {column_name: a list of statistics}, where the list of statistics is a list of strings containing the names of desired statistics for each column. Names of the statistics include: {‘first’, ‘last’, ‘sum’, ‘mean’, ‘median’, ‘max’, ‘min’, ‘std’, ‘var’, ‘count’, ‘size’}.

  • join_type (string, default 'one to one') – Binary predicate, one of {‘one to one’, ‘one to many’}. The option ‘one to one’ only returns one row for each target feature, whereas option ‘one to many’ return multiple rows for each match between target feature and join feature.

  • keep_all (bool, default True) – Whether to keep all features from the target GeoDataFrame.

Returns:

A GeoDataFrame contains all columns in the target GeoDataFrame and the specified columns from the join GeoDataFrame.

Return type:

geopandas.GeoDataFrame

Examples

>>> pylusat.geotools.spatial_join(acs2016_gdf, schools_gdf,
                                  cols_agg={'ENROLLMENT': ['sum]})
         GEOID10    ENROLLMENT_SUM
0   120010006001               0.0
1   120010006002               0.0
2   120010006003             345.0
3   120010007001              37.0
4   120010007002            1420.0
...
150 120010022191             113.0
151 120010022192            1889.0
152 120010022193             118.0
153 120010022201               0.0
154 120011108001             803.0
pylusat.geotools.within_dist(input_gdf, input_id, distance, target_gdf=None, output_col=None)

For each object in the input, test if any object in the target set is within a specified distance.

Parameters:
  • input_gdf (geopandas.GeoDataFrame) – The input set.

  • input_id (str) – The name of the column containing the unique id of the input set.

  • distance (int or float) – Distance (in the same unit as the input GeoDataFrame).

  • target_gdf (geopandas.GeoDataFrame) – The target set.

  • output_col (str) – The name of the output column.

Returns:

output – The output value is 1 if there exists any target object within the specified distance of the input object and 0 otherwise.

Return type:

geopandas.GeoDataFrame

pylusat.geotools.select_by_location(input_gdf, select_gdf, op='intersects', within_dist=0)

Select part of the input GeoDataFrame based on its relationship with the selecting GeoDataFrame.

Parameters:
Returns:

output – The selected features from the input GeoDataFrame.

Return type:

geopandas.GeoDataFrame

Examples

>>> pylusat.geotools.select_by_location(acso2016_gdf, schools_gdf)
           GEOID    geometry
0   120010006001    POLYGON ((564121.721 629847.127, 564127.038...))
2   120010006003    POLYGON ((565858.254 629636.152, 565695.479...))
3   120010007001    POLYGON ((563316.398 627676.644, 563228.536...))
4   120010007002    POLYGON ((563768.801 627680.962, 563770.869...))
5   120010007003    POLYGON ((565229.514 624327.588, 564862.624...))
pylusat.geotools.combine(rast1, rast2)

Combines input rasters by their unique value pairs. Assigns new values to each unique pair.

Parameters:
Returns:

Results – The combined raster files as a Rasterio Dataset. The output attribute table as a Pandas DataFrame.

Return type:

rasterio.Dataset, pandas.DataFrame

Examples

>>> pylusat.geotools.combine(habitat_tif, habitati_tif)
0   1   0   0   618688
1   2   2   2   1
2   3   3   3   1
3   4   5   5   20539
4   5   6   6   115
pylusat.geotools.gridify(input_gdf, cell_x=None, cell_y=None, n_cols=None, n_rows=None)

Create a grid covering the extent of the input_gdf based on either (cell_x, celly_y) or (n_cols, n_rows).

If both are specified, (cell_x, cell_y) will be used.

If neither are specified, the cell size will be calcualted based on the input_gdf’s width (length of x-axis) divided by 30.

Parameters:
  • input_gdf (geopandas.GeoDataFrame) – Input GeoDataFrame based on which the grid is created.

  • cell_x (int or float) – Cell size on the x-axis.

  • cell_y (int or float) – Cell cell_y.

  • n_cols (int) – Number of columns. When specified, this number will determine cell_x (i.e., input_gdf’s width divided by n_cols).

  • n_rows (int) – Number of rows. When specified, this number will determine cell_y (input_gdf’s height divided by n_rows).

Returns:

The output grid (polygons).

Return type:

geopandas.GeoDataFrame

Notes

cell_x and cell_y are in the same unit as the input_gdf’s CRS.

The output grid will have the same CRS as the input_gdf. The CRS of the input_gdf must be projected (not geographic).

Examples

Create grid of polygons from the schools GeoDataFrame with a cell size of 1000 (meters).

>>> pylusat.geotools.gridify(schools_gdf, cell_x=1000)
0       POLYGON ((533359.960 611556.855, 534359.960...))
1       POLYGON ((534359.960 611556.855, 535359.960...))
2       POLYGON ((535359.960 611556.855, 536359.960...))
3       POLYGON ((536359.960 611556.855, 537359.960...))
4       POLYGON ((537359.960 611556.855, 538359.960...))
...
2491    POLYGON ((580359.960 658556.855, 581359.960...))
2492    POLYGON ((581359.960 658556.855, 582359.960...))
2493    POLGYON ((582359.960 658556.855, 583359.960...))
2494    POLYGON ((583359.960 658556.855, 584359.960...))
2495    POLGYON ((584359.960 658556.855, 585359.960...))