Commit 2646e972 authored by Sonja Tripkovic's avatar Sonja Tripkovic

Updates to pull_from_geodatenviewer_meas and pull_from_geodatenviewer_list in fetch.py

parent 2335e4ae
...@@ -131,12 +131,14 @@ def pull_from_geodatenviewer_list(squares: List[str]) -> gpd.GeoDataFrame: ...@@ -131,12 +131,14 @@ def pull_from_geodatenviewer_list(squares: List[str]) -> gpd.GeoDataFrame:
# downloading .zip files # downloading .zip files
# example of single square with data: https://www.wien.gv.at/ma41datenviewer/downloads/ma41/geodaten/fmzk_bkm/103081_bkm.zip # example of single square with data: https://www.wien.gv.at/ma41datenviewer/downloads/ma41/geodaten/fmzk_bkm/103081_bkm.zip
for square_number in squares: for square_number in squares:
try:
urllib.request.urlretrieve( urllib.request.urlretrieve(
"https://www.wien.gv.at/ma41datenviewer/downloads/geodaten/fmzk_bkm/{}_bkm.zip".format( "https://www.wien.gv.at/ma41datenviewer/downloads/geodaten/fmzk_bkm/{}_bkm.zip".format(
square_number square_number
), ),
os.path.join(dir_path, "{}.zip".format(square_number)), os.path.join(dir_path, "{}.zip".format(square_number)),
) )
except: continue
# extracting and deleting .zip files # extracting and deleting .zip files
for item in os.listdir(dir_path): # loop through items in dir for item in os.listdir(dir_path): # loop through items in dir
...@@ -150,8 +152,10 @@ def pull_from_geodatenviewer_list(squares: List[str]) -> gpd.GeoDataFrame: ...@@ -150,8 +152,10 @@ def pull_from_geodatenviewer_list(squares: List[str]) -> gpd.GeoDataFrame:
# combine all .shp files # combine all .shp files
geo_df_all = pd.DataFrame() geo_df_all = pd.DataFrame()
for square in squares: for square in squares:
try:
geo_df = gpd.read_file(os.path.join(dir_path, square + "_bkm.shp")) geo_df = gpd.read_file(os.path.join(dir_path, square + "_bkm.shp"))
geo_df_all = pd.concat([geo_df_all, geo_df], ignore_index=True) geo_df_all = pd.concat([geo_df_all, geo_df], ignore_index=True)
except: continue
shutil.rmtree(dir_path) # deletes the directory containing all the files shutil.rmtree(dir_path) # deletes the directory containing all the files
return geo_df_all return geo_df_all
...@@ -187,10 +191,8 @@ def pull_from_geodatenviewer_meas( ...@@ -187,10 +191,8 @@ def pull_from_geodatenviewer_meas(
for file in os.listdir(raster_path): for file in os.listdir(raster_path):
if file.endswith(".shp"): if file.endswith(".shp"):
raster_gdf = gpd.read_file(os.path.join(raster_path, file)) raster_gdf = gpd.read_file(os.path.join(raster_path, file))
if raster_gdf.geometry.crs != "EPSG:4326":
raise ValueError( raster_gdf.to_crs(4326,inplace=True)
"Raster EPSG has changed, see https://www.data.gv.at/katalog/dataset/b2d17060-b2f4-4cd7-a2e5-64beccfeb4c1 for mor information."
)
meas_gdf = gpd.GeoDataFrame(geometry=measurement_coords) meas_gdf = gpd.GeoDataFrame(geometry=measurement_coords)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment