Skip to content

Commit

Permalink
Handle projecting of empty elements (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Feb 11, 2018
1 parent 5cd188a commit ee9ba3f
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions geoviews/operation.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,9 @@ class project_path(Operation):
supported_types = [Polygons, Path, Contours]

def _process_element(self, element):
if element.interface.datatype == 'geodataframe':
if not len(element):
return element.clone(crs=self.p.projection)
elif element.interface.datatype == 'geodataframe':
geoms = element.split(datatype='geom')
projected = [self.p.projection.project_geometry(geom, element.crs)
for geom in geoms]
Expand Down Expand Up @@ -117,6 +119,8 @@ class project_shape(Operation):
supported_types = [Shape]

def _process_element(self, element):
if not len(element):
return element.clone(crs=self.p.projection)
geom = self.p.projection.project_geometry(element.geom(), element.crs)
return element.clone(geom, crs=self.p.projection)

Expand All @@ -134,14 +138,17 @@ class project_points(Operation):
supported_types = [Points]

def _process_element(self, element):
if not len(element):
return element.clone(crs=self.p.projection)
xdim, ydim = element.dimensions()[:2]
xs, ys = (element.dimension_values(i) for i in range(2))
coordinates = self.p.projection.transform_points(element.crs, xs, ys)
new_data = element.columns()
new_data[xdim.name] = coordinates[:, 0]
new_data[ydim.name] = coordinates[:, 1]
datatype = [element.interface.datatype]+element.datatype
return element.clone(new_data, crs=self.p.projection,
datatype=[element.interface.datatype]+element.datatype)
datatype=datatype)

def _process(self, element, key=None):
return element.map(self._process_element, self.supported_types)
Expand Down

0 comments on commit ee9ba3f

Please sign in to comment.