Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save richpsharp/618a3f255b3be71f3d09a98a6e6a6fc7 to your computer and use it in GitHub Desktop.
Save richpsharp/618a3f255b3be71f3d09a98a6e6a6fc7 to your computer and use it in GitHub Desktop.
Convert Danny's R table to a CSV and reproject and rename
"""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