-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
1,019 additions
and
279 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,3 +91,6 @@ typing-extensions==3.7.4.3 | |
urllib3==1.26.2 | ||
xarray==0.16.2 | ||
zict==2.0.0 | ||
|
||
fastparquet~=0.5.0 | ||
casex~=1.0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from typing import NoReturn, Tuple | ||
|
||
import geopandas as gpd | ||
import numpy as np | ||
from holoviews.element import Geometry | ||
from shapely import geometry as sg | ||
|
||
from seedpod_ground_risk.layers.blockable_data_layer import BlockableDataLayer | ||
|
||
|
||
class ArbitraryObstacleLayer(BlockableDataLayer): | ||
def __init__(self, key, filepath: str = '', **kwargs): | ||
super(ArbitraryObstacleLayer, self).__init__(key, **kwargs) | ||
self.filepath = filepath | ||
|
||
def preload_data(self) -> NoReturn: | ||
|
||
self.dataframe = gpd.read_file(self.filepath) | ||
if self.buffer_dist: | ||
epsg3857_geom = self.dataframe.to_crs('EPSG:3857').geometry | ||
self.buffer_poly = gpd.GeoDataFrame( | ||
{'geometry': epsg3857_geom.buffer(self.buffer_dist).to_crs('EPSG:4326')} | ||
) | ||
|
||
def generate(self, bounds_polygon: sg.Polygon, raster_shape: Tuple[int, int], from_cache: bool = False, **kwargs) -> \ | ||
Tuple[Geometry, np.ndarray, gpd.GeoDataFrame]: | ||
import geoviews as gv | ||
from holoviews.operation.datashader import rasterize | ||
|
||
bounds = bounds_polygon.bounds | ||
|
||
bounded_df = self.dataframe.cx[bounds[1]:bounds[3], bounds[0]:bounds[2]] | ||
|
||
polys = gv.Polygons(bounded_df).opts(style={'alpha': 0.8, 'color': self._colour}) | ||
raster = rasterize(polys, width=raster_shape[0], height=raster_shape[1], | ||
x_range=(bounds[1], bounds[3]), y_range=(bounds[0], bounds[2]), dynamic=False) | ||
raster_grid = np.copy(list(raster.data.data_vars.items())[0][1].data.astype(np.float)) | ||
if self.blocking: | ||
raster_grid[raster_grid != 0] = -1 | ||
|
||
return polys, raster_grid, gpd.GeoDataFrame(self.dataframe) | ||
|
||
def clear_cache(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import random | ||
from abc import ABCMeta, abstractmethod | ||
|
||
from seedpod_ground_risk.layers.data_layer import DataLayer | ||
|
||
|
||
class BlockableDataLayer(DataLayer, metaclass=ABCMeta): | ||
def __init__(self, key, colour: str = None, | ||
blocking=False, buffer_dist=0): | ||
super().__init__(key) | ||
self.blocking = blocking | ||
self.buffer_dist = buffer_dist | ||
# Set a random colour | ||
self._colour = colour if colour is not None else "#" + ''.join( | ||
[random.choice('0123456789ABCDEF') for _ in range(6)]) | ||
|
||
@abstractmethod | ||
def preload_data(self): | ||
pass | ||
|
||
@abstractmethod | ||
def generate(self, bounds_polygon, raster_shape, from_cache: bool = False, **kwargs): | ||
pass | ||
|
||
@abstractmethod | ||
def clear_cache(self): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.