Skip to content

Commit

Permalink
handle empty geometries when creating multipolygon/linestring/points
Browse files Browse the repository at this point in the history
  • Loading branch information
olt committed Dec 18, 2019
1 parent 4158575 commit d02b6fa
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
11 changes: 8 additions & 3 deletions admin_clipper.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# coding: utf-8
import sys
import json
Expand Down Expand Up @@ -26,16 +25,22 @@ def transform_bbox(transf, bbox):
return min(xs), min(ys), max(xs), max(ys)

def as_multipolygon(p):
if not p:
return []
if p.type == 'MultiPolygon':
return p
return MultiPolygon([p])

def as_multilinestring(l):
if not l:
return []
if l.type == 'MultiLineString':
return l
return MultiLineString([l])

def as_multipoint(l):
if not l:
return []
if l.type == 'MultiPoint':
return l
return MultiPoint([l])
Expand Down Expand Up @@ -137,16 +142,16 @@ def main():

clip_features = clipsrc.items(bbox=bbox_clip)
clip_geom = as_multipolygon(cascaded_union([asShape(f['geometry']) for i, f in clip_features]))
clip_geom = transform(proj_clip_to_src, clip_geom)

if clip_geom.is_empty:
if not clip_geom or clip_geom.is_empty:
result_features.append({
'type': 'Feature',
'properties': src_feature['properties'],
'geometry': mapping(transform(truncate, transform(proj_src_to_wgs, boundary_lines))),
})
continue

clip_geom = transform(proj_clip_to_src, clip_geom)
# Buffer the clipping geometry
clip_geom_buffered = clip_geom.buffer(clip_buffer)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

setup(
name='admin_clipper',
version='0.1.1',
version='0.1.2',
description='Clip administrative boundaries at coastlines.',
long_description='',
author='Omniscale',
Expand Down

0 comments on commit d02b6fa

Please sign in to comment.