Skip to content

Commit

Permalink
Fix #1373 -- Ignore empty geometries for SHP export
Browse files Browse the repository at this point in the history
  • Loading branch information
oliverroick authored and amplifi committed May 10, 2017
1 parent 2de6597 commit 8b35a41
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions cadasta/organization/download/shape.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ def write_features(self, ds, filename):
layers = {}

for su in spatial_units:
# Excluding empty geometries from export
if not su.geometry:
continue

geom = ogr.CreateGeometryFromWkt(su.geometry.wkt)
layer_type = geom.GetGeometryName().lower()
layer = layers.get(layer_type, None)
Expand Down
10 changes: 10 additions & 0 deletions cadasta/organization/tests/test_downloads.py
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ def test_write_features(self):
'MULTIPOLYGON (((30 20, 45 40, 10 40, 30 20)),'
'((15 5, 40 10, 10 20, 5 10, 15 5)))',
attributes={'geom_type': 'multipolygon'})
su7 = SpatialUnitFactory.create(
project=project,
geometry='SRID=4326;'
'POLYGON EMPTY',
attributes={'geom_type': 'empty'})

dst_dir = os.path.join(settings.MEDIA_ROOT, 'temp/file4')
ds = exporter.create_datasource(dst_dir)
Expand All @@ -430,6 +435,9 @@ def test_write_features(self):
feature = layer.GetNextFeature()
assert geom.equals(GEOSGeometry(feature.geometry().ExportToWkt()))
assert feature.GetFieldAsString('id') == su.id

# Ensuring empty polygons are not added to shape
assert su.id != su7.id
ds.Destroy()

with open(filename) as csvfile:
Expand All @@ -449,6 +457,8 @@ def test_write_features(self):
assert row == [su5.id, su5.type, 'multilinestring']
if i == 6:
assert row == [su6.id, su6.type, 'multipolygon']
if i == 7:
assert row == [su7.id, su7.type, 'empty']

# remove this so other tests pass
os.remove(filename)
Expand Down

0 comments on commit 8b35a41

Please sign in to comment.