Skip to content

RavenGIS #127

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5db84b4
First pass at refactoring GIS functions out of RavenPy with their ass…
Zeitsperre Aug 5, 2021
e3db46a
Run pre-commit checks
Zeitsperre Aug 6, 2021
e7d1e70
Move vector transformation logic into RavenPy, rewrite generic vector…
Zeitsperre Aug 6, 2021
5ba73d9
Working version of generic reproject with shapefile - No GDAL
Zeitsperre Aug 6, 2021
0541e2e
First pass at remove ogr from routing_product.py, fix pyproj transfor…
Zeitsperre Aug 6, 2021
b728a11
Low-level ogr/osr calls removed
Zeitsperre Aug 6, 2021
29d9f06
First half of geopandas calls replaced
Zeitsperre Aug 6, 2021
e447868
Removed more GeoPandas logic - WIP
Zeitsperre Aug 7, 2021
78839a3
Removed more of the GDAL-dependent functions from routing - Tests fai…
Zeitsperre Aug 9, 2021
7b731e1
removed last GeoPandas import - Broken
Zeitsperre Aug 9, 2021
c1d0e07
Fix some docstrings and refactor transformation logic into vector.py,
Zeitsperre Aug 9, 2021
cc4da77
Fix NumberHRUs bug, some refactoring
Zeitsperre Aug 9, 2021
e2acdcc
Added class field for CRS specifications since projection cannot be i…
Zeitsperre Aug 10, 2021
8960255
Force to always use XY for grid transforms (for now)
Zeitsperre Aug 10, 2021
4c98279
Skip slow tests for tox builds
Zeitsperre Aug 10, 2021
fef1d67
Leverage pandas dataframes with geometries constructed via shapely
Zeitsperre Aug 10, 2021
9fac999
remove some useless imports
Zeitsperre Aug 10, 2021
dd74de1
Fix unnecessary shape conversion, stricter CRS transformation controls
Zeitsperre Aug 11, 2021
5fc918d
Re-enabled some GDAL-based logic by applying dataframe approach to fi…
Zeitsperre Aug 17, 2021
1c3c14c
Fix geopandas triggering, delete fully-removed dependencies, add a no…
Zeitsperre Aug 18, 2021
d0c21f6
explicitly install libnetcdf headers
Zeitsperre Aug 18, 2021
620eb68
Install geopandas in tox recipe
Zeitsperre Aug 18, 2021
c308271
run slow tests
Zeitsperre Aug 18, 2021
d1a9b7d
Try another logic syntax
Zeitsperre Aug 18, 2021
31ed75c
hmmm
Zeitsperre Aug 18, 2021
0b7fdc1
hmmm again
Zeitsperre Aug 18, 2021
588479b
another try
Zeitsperre Aug 18, 2021
29f5772
Try another approach
Zeitsperre Aug 18, 2021
8438cb2
Fix a forgotten inplace=True flag
Zeitsperre Aug 18, 2021
a107436
testing - Use STRtree shapely speedup
Zeitsperre Aug 18, 2021
8d245f1
Shapely speedup final version
Zeitsperre Aug 18, 2021
813e819
Add geos
Zeitsperre Aug 19, 2021
9e386cf
Merge branch 'master' into raven-gis-refactor
Zeitsperre Aug 19, 2021
a8cfb57
Merge branch 'master' into raven-gis-refactor
Zeitsperre Aug 31, 2021
87ddddb
WIP - add pygml for gmlv32 reading
Zeitsperre Sep 8, 2021
0e78f5a
add pygml dependency
Zeitsperre Sep 24, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 49 additions & 14 deletions ravenpy/extractors/routing_product.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

from ravenpy.utilities import gis_import_error_message
from ravenpy.utilities.vector import (
WGS84,
archive_sniffer,
generic_extract_archive,
generic_vector_reproject,
Expand Down Expand Up @@ -359,35 +360,69 @@ def __init__(
self._input_is_netcdf = True

input_file_path = Path(input_file_path)
if input_file_path.suffix == ".nc":
if {input_file_path.suffix.lower()}.issubset({".nc", ".nc4"}):
# Note that we cannot use xarray because it complains about variables and dimensions
# having the same name.
self._input_data = nc4.Dataset(input_file_path)
elif input_file_path.suffix == ".zip":
self._input_data = geopandas.read_file(f"zip://{input_file_path}")
self._input_is_netcdf = False
elif input_file_path.suffix == ".shp":
self._input_data = geopandas.read_file(input_file_path)
self._input_is_netcdf = False
elif {input_file_path.suffix.lower()}.issubset({".zip", ".shp"}):
# self._input_data = geopandas.read_file(f"zip://{input_file_path}")
if input_file_path.suffix.lower() == ".zip":
input_file_path = next(
iter(archive_sniffer(generic_extract_archive(input_file_path)))
)
if input_file_path.suffix.lower() == ".shp":
# self._input_data = geopandas.read_file(input_file_path)
self._input_data = geojson.loads(
json.dumps(Reader(input_file_path.as_posix()).__geo_interface__)
)
self._input_is_netcdf = False
else:
raise ValueError(
"The input file must be a shapefile (.shp or .zip) or NetCDF"
"The input file must be a shapefile (.shp or .zip) or a NetCDF."
)

routing_file_path = Path(routing_file_path)
if routing_file_path.suffix == ".zip":
routing_file_path = f"zip://{routing_file_path}"
self._routing_data = geopandas.read_file(routing_file_path)
# if routing_file_path.suffix == ".zip":
# routing_file_path = f"zip://{routing_file_path}"
# self._routing_data = geopandas.read_file(routing_file_path)

if routing_file_path.suffix.lower() == ".zip":
# self._input_data = geopandas.read_file(f"zip://{input_file_path}")
routing_file_path = Path(
next(iter(archive_sniffer(generic_extract_archive(routing_file_path))))
)
if routing_file_path.suffix.lower() == ".shp":
# self._input_data = geopandas.read_file(input_file_path)
self._routing_data = geojson.loads(
json.dumps(Reader(routing_file_path.as_posix()).__geo_interface__)
)
else:
raise ValueError("The routing file must be a shapefile (.shp or .zip).")

def extract(self) -> GridWeightsCommand:
self._prepare_input_data()

# Read routing data

# WGS 84 / North Pole LAEA Canada
self._routing_data = self._routing_data.to_crs(
epsg=RoutingProductGridWeightExtractor.CRS_CAEA
)
# self._routing_data = self._routing_data.to_crs(
# epsg=RoutingProductGridWeightExtractor.CRS_CAEA
# )
output = list()
for feature in self._routing_data.features:
geom = sgeo.shape(feature.geometry)
transformed = geom_transform(
geom, WGS84, RoutingProductGridWeightExtractor.CRS_CAEA
)
feature.geometry = sgeo.mapping(transformed)
if hasattr(feature, "bbox"):
bbox = sgeo.box(*feature.bbox)
transformed = geom_transform(
bbox, WGS84, RoutingProductGridWeightExtractor.CRS_CAEA
)
feature.bbox = sgeo.mapping(transformed)
output.append(feature)
self._routing_data = geojson.FeatureCollection(output)

def keep_only_valid_downsubid_and_obs_nm(g):
"""
Expand Down