forked from Grist-Data-Desk/land-grab-2
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Grist-Data-Desk/feat/add-clipping-filteri…
…ng-column-selection feat: Integrate code to clip parcels to reservation boundaries, filter columns by acreage and additional criteria in METHODOLOGY.md, and concatenate activity_info and activity_info_2 columns.
- Loading branch information
Showing
4 changed files
with
200 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import logging | ||
from pathlib import Path | ||
|
||
import geopandas as gpd | ||
|
||
from stlor.constants import ( | ||
NAD_83_CONUS_ALBERS, | ||
SQUARE_METERS_PER_ACRE, | ||
CLIPPED_ACRES, | ||
STATE, | ||
RESERVATION_NAME, | ||
) | ||
|
||
logging.basicConfig(level=logging.INFO) | ||
logger = logging.getLogger(__name__) | ||
|
||
|
||
def clip_to_reservation_boundaries(stl_gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame: | ||
"""Clip state trust lands to reservation boundaries. | ||
Arguments: | ||
stl_gdf -- the state trust lands GeoDataFrame | ||
Returns: | ||
gpd.GeoDataFrame -- the clipped state trust lands GeoDataFrame | ||
""" | ||
reservations_gdf = gpd.read_file( | ||
Path("public_data/00_Reservation Layer/BIA_AIAN+OK_Fixed.geojson").resolve() | ||
) | ||
supp_reservations_gdf = gpd.read_file( | ||
Path("public_data/00_Reservation Layer/BIA-supp.geojson").resolve() | ||
) | ||
|
||
# Reproject all GeoDataFrames to NAD83 Conus Albers. | ||
logger.info("Reprojecting STL and BIA_AIAN GeoDataFrames to NAD83 Conus Albers.") | ||
stl_gdf = stl_gdf.to_crs(NAD_83_CONUS_ALBERS) | ||
reservations_gdf = reservations_gdf.to_crs(NAD_83_CONUS_ALBERS) | ||
supp_reservations_gdf = supp_reservations_gdf.to_crs(NAD_83_CONUS_ALBERS) | ||
|
||
# Union the reservations_gdf and supp_reservations_gdf to a single layer in | ||
# prepartion for the clipping operation. | ||
logger.info("Unioning the BIA_AIAN primary and supplemental GeoDataFrames.") | ||
reservations_gdf = reservations_gdf.overlay(supp_reservations_gdf, how="union") | ||
|
||
logger.info("Clipping the STL GeoDataFrame to reservation boundaries.") | ||
stl_gdf = stl_gdf.clip(reservations_gdf) | ||
|
||
logger.info("Calculating the area of the clipped state trust lands.") | ||
stl_gdf[CLIPPED_ACRES] = (stl_gdf.area / SQUARE_METERS_PER_ACRE).round(2) | ||
|
||
return stl_gdf | ||
|
||
|
||
def filter_parcels_by_acreage(stl_gdf: gpd.GeoDataFrame) -> gpd.GeoDataFrame: | ||
"""Filter parcels with either of the following characteristics: | ||
1. "clipped_acres" < 10.0 | ||
- Note that this includes parcels with "clipped_acres" equal to 0.0. | ||
2. WY parcels with "reservation_name" == "Crow" | ||
Arguments: | ||
stl_gdf -- the state trust lands GeoDataFrame | ||
Returns: | ||
gpd.GeoDataFrame -- the filtered state trust lands GeoDataFrame | ||
""" | ||
stl_gdf = stl_gdf[ | ||
(stl_gdf[CLIPPED_ACRES] >= 10.0) | ||
& ~((stl_gdf[STATE] == "WY") & (stl_gdf[RESERVATION_NAME] == "Crow")) | ||
] | ||
|
||
return stl_gdf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,41 @@ | ||
# Column names. | ||
# Column names | ||
OBJECT_ID = "object_id" | ||
STATE = "state" | ||
RIGHTS_TYPE = "rights_type" | ||
ACTIVITY = "activity" | ||
ACTIVITY_INFO = "activity_info" | ||
ACTIVITY_INFO_2 = "activity_info_2" | ||
GEOMETRY = "geometry" | ||
CLIPPED_ACRES = "clipped_acres" | ||
RESERVATION_NAME = "reservation_name" | ||
|
||
# Projections | ||
NAD_83_CONUS_ALBERS = "EPSG:5070" | ||
|
||
# Units | ||
SQUARE_METERS_PER_ACRE = 4046.8564224 | ||
|
||
# Output columns | ||
FINAL_DATASET_COLUMNS = [ | ||
OBJECT_ID, | ||
STATE, | ||
"managing_agency", | ||
"state_enabling_act", | ||
"trust_name", | ||
RESERVATION_NAME, | ||
RIGHTS_TYPE, | ||
"rights_type_info", | ||
"acres", | ||
"gis_acres", | ||
"net_acres", | ||
CLIPPED_ACRES, | ||
ACTIVITY, | ||
ACTIVITY_INFO, | ||
"county", | ||
"meridian", | ||
"township", | ||
"range", | ||
"section", | ||
"aliquot", | ||
GEOMETRY, | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters