Skip to content

Commit

Permalink
Merge pull request #205 from cagov/set-crs-on-footprints
Browse files Browse the repository at this point in the history
Set crs on footprints
  • Loading branch information
britt-allen authored Sep 19, 2023
2 parents 69f7d43 + 2ccea23 commit 419c95b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions jobs/geo/write_building_footprints.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def write_building_footprints(conn):

import geopandas
import s3fs
import shapely
import shapely.wkb

sql_alter = """
alter session set GEOGRAPHY_OUTPUT_FORMAT='WKB';
Expand All @@ -33,14 +33,16 @@ def write_building_footprints(conn):
"""
df = conn.cursor().execute(sql_table).fetch_pandas_all()
gdf = geopandas.GeoDataFrame(
df.assign(geometry=df.geometry.apply(shapely.wkb.loads))
df.assign(geometry=df.geometry.apply(shapely.wkb.loads)),
crs="EPSG:4326",
)

gdf = gdf[gdf.geometry.geom_type != "GeometryCollection"]

file_prefix = f"footprints_with_tiger_for_county_fips_{county}"
gdf.to_parquet(f"{file_prefix}.parquet")
gdf.to_file(f"{file_prefix}.shp.zip")
# .shz suffix triggers GDAL to write zipped shapefile
gdf.to_file(f"{file_prefix}.shz")

print(
f"Loading {file_prefix}. This is number {index+1} out of {len(counties)} counties."
Expand All @@ -51,12 +53,14 @@ def write_building_footprints(conn):
f"{file_prefix}.parquet",
"s3://dof-demographics-dev-us-west-2-public/parquet/",
)
# Esri doesn't like .shp.zip or .shz, so rename to just be .zip.
s3.put(
f"{file_prefix}.shp.zip", "s3://dof-demographics-dev-us-west-2-public/shp/"
f"{file_prefix}.shz",
f"s3://dof-demographics-dev-us-west-2-public/shp/{file_prefix}.zip",
)

os.remove(f"{file_prefix}.parquet")
os.remove(f"{file_prefix}.shp.zip")
os.remove(f"{file_prefix}.shz")


if __name__ == "__main__":
Expand Down

0 comments on commit 419c95b

Please sign in to comment.