Skip to content

Commit

Permalink
Remove try except
Browse files Browse the repository at this point in the history
  • Loading branch information
Zeitsperre committed Feb 3, 2021
1 parent dc7da3b commit 2fa15f9
Showing 1 changed file with 18 additions and 24 deletions.
42 changes: 18 additions & 24 deletions emu/processes/wps_geospatial.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ def __init__(self):
"Region definition in GeoJSON format",
abstract="The original vector but buffered by a distance of 5.",
as_reference=True,
supported_formats=[FORMATS.GEOJSON]
)
supported_formats=[FORMATS.GEOJSON],
),
]

super(GeoData, self).__init__(
Expand Down Expand Up @@ -91,28 +91,22 @@ def _handler(self, request, response):
ras_file = request.inputs["raster"][0].file

response.update_status("Reading Vector file", 10)
try:
with fiona.open(vec_file, mode='r') as f:
feature = next(iter(f))
polygon = shape(feature["geometry"])
bounds = [*polygon.bounds]
centroid = polygon.centroid

buffered = polygon.buffer(5)
buffered_geojson = tempfile.NamedTemporaryFile(
prefix="out_", suffix=".geojson", delete=False, dir=self.workdir
).name
response.update_status("Writing Vector file", 10)
with open(buffered_geojson, "w") as bf:
output = {"type": "FeatureCollection", "features": []}
feature["geometry"] = mapping(buffered)
output["features"].append(feature)
bf.write(f"{json.dumps(output)}")

except Exception as e:
msg = f"{e}: unable to read vector file."
logging.warning(msg=msg)
raise
with fiona.open(vec_file, mode="r") as f:
feature = next(iter(f))
polygon = shape(feature["geometry"])
bounds = [*polygon.bounds]
centroid = polygon.centroid

buffered = polygon.buffer(5)
buffered_geojson = tempfile.NamedTemporaryFile(
prefix="out_", suffix=".geojson", delete=False, dir=self.workdir
).name
response.update_status("Writing Vector file", 10)
with open(buffered_geojson, "w") as bf:
output = {"type": "FeatureCollection", "features": []}
feature["geometry"] = mapping(buffered)
output["features"].append(feature)
bf.write(f"{json.dumps(output)}")

response.update_status("Reading Raster file", 30)
with rio.open(ras_file, mode="r") as data:
Expand Down

0 comments on commit 2fa15f9

Please sign in to comment.