Skip to content

Commit

Permalink
Merge pull request #9 from nens/casper-geometryfilesource
Browse files Browse the repository at this point in the history
Implement columns attribute for GeometryFileSource
  • Loading branch information
arjanverkerk committed Oct 22, 2019
2 parents 8cc2b6f + d5ba0d4 commit 1087b24
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ Changelog of dask-geomodeling
When taking the difference of a geometry with a missing geometry (A - None),
geopandas < 0.6 returned A as result, while >= 0.6 returns None as result.


- Implemented the 'columns' attribute for GeometryFileSource.

- Fixed the projection attribute of elementwise raster blocks in case one of
the arguments is a number and not a Block instance.

Expand Down
13 changes: 12 additions & 1 deletion dask_geomodeling/geometry/sources.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
"""
Module containing geometry sources.
"""
import fiona
import geopandas as gpd

from dask import config
from dask_geomodeling import utils
from .base import GeometryBlock

# this import is a copy from geopandas.io.files
try:
from fiona import Env as fiona_env
except ImportError:
from fiona import drivers as fiona_env


__all__ = ["GeometryFileSource"]


Expand Down Expand Up @@ -54,7 +62,10 @@ def path(self):

@property
def columns(self):
raise NotImplementedError()
# this is exactly how geopandas determines the columns
with fiona_env(), fiona.open(self.path) as reader:
properties = reader.meta["schema"]["properties"]
return set(properties.keys()) | {"geometry"}

def get_sources_and_requests(self, **request):
# check the filters: this block does not support lookups
Expand Down
3 changes: 3 additions & 0 deletions dask_geomodeling/tests/test_geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ def test_attr(self):
self.assertEqual(self.source.path, self.abspath)
self.assertEqual(self.source.id_field, self.id_field)

def test_columns(self):
self.assertSetEqual(self.source.columns, {"id", "name", "geometry"})

def test_get_data(self):
result = self.source.get_data(geometry=box(*self.bbox), projection="EPSG:4326")
self.assertEqual(self.projection, result["projection"])
Expand Down

0 comments on commit 1087b24

Please sign in to comment.