Created
June 11, 2025 23:14
-
-
Save richpsharp/618a3f255b3be71f3d09a98a6e6a6fc7 to your computer and use it in GitHub Desktop.
Convert Danny's R table to a CSV and reproject and rename
This file contains hidden or 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
"""Script to process Danny's RDS file into something that can be analyzed by the PCLD.""" | |
import pyreadr | |
import geopandas as gpd | |
PROJECTION_EPSG = 32610 | |
FILE_PATH = "Karp_LU_UseCase.RDS" | |
def main(): | |
result = pyreadr.read_r(FILE_PATH) | |
print(result) | |
df = next(iter(result.values())) | |
df = df.rename( | |
columns={ | |
"FixLongitude_UTM": "Longitude", | |
"FixLatitude_UTM": "Latitude", | |
} # noqa: E123 | |
) | |
gdf = gpd.GeoDataFrame( | |
df, | |
geometry=gpd.points_from_xy(df["Longitude"], df["Latitude"]), | |
crs="EPSG:32610", | |
) | |
gdf = gdf.to_crs("EPSG:4326") | |
gdf["Longitude"] = gdf.geometry.x | |
gdf["Latitude"] = gdf.geometry.y | |
gdf = gdf.drop(columns="geometry") | |
print(gdf.head()) | |
gdf.to_csv("Karp_LU_UseCase.csv", index=False) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment