Skip to content
This repository has been archived by the owner on Aug 25, 2024. It is now read-only.

Commit

Permalink
Skip invalid geometries when reading shapes from ground truth vector
Browse files Browse the repository at this point in the history
  • Loading branch information
munshkr committed Oct 29, 2018
1 parent d2765df commit 0e72e85
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion aplatam/build_trainset.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,12 @@ def _extract_images_from_windows(self, windows, raster, percentiles,
def _read_shapes(self):
"""Read features from the vector file and return their geometry shapes"""
with fiona.open(self.vector) as data:
return [(shape(feat['geometry'])) for feat in data], data.crs
shapes = [(shape(feat['geometry'])) for feat in data]
valid_shapes = [s for s in shapes if s.is_valid]
if len(valid_shapes) != len(shapes):
num_invalid_shapes = len(shapes) - len(valid_shapes)
_logger.warn("Invalid geometries were found! %d invalid shapes.", num_invalid_shapes)
return valid_shapes, data.crs

def _reproject_shapes(self, shapes, src_crs, dst_crs):
"""Reproject shapes from CRS +src_crs+ to +dst_crs+"""
Expand Down

0 comments on commit 0e72e85

Please sign in to comment.