From a78e2df8f7566fb1c959b2ae1a66a6356f7f366e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Mart=C3=ADnez=20G=C3=B3mez?= Date: Sat, 27 Aug 2022 12:14:58 +0200 Subject: [PATCH] Skip CSV row with invalid coordinates (#967) * Skip CSV row with invalid coordinates * Use single quotes and message string in a variable --- pygeoapi/provider/csv_.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/pygeoapi/provider/csv_.py b/pygeoapi/provider/csv_.py index efd5852..983b506 100644 --- a/pygeoapi/provider/csv_.py +++ b/pygeoapi/provider/csv_.py @@ -110,15 +110,21 @@ class CSVProvider(BaseProvider): return feature_collection LOGGER.debug('Slicing CSV rows') for row in itertools.islice(data_, offset, offset+limit): + try: + coordinates = [ + float(row.pop(self.geometry_x)), + float(row.pop(self.geometry_y)), + ] + except ValueError: + msg = f'Skipping row with invalid geometry: {row.get(self.id_field)}' # noqa + LOGGER.error(msg) + continue feature = {'type': 'Feature'} feature['id'] = row.pop(self.id_field) if not skip_geometry: feature['geometry'] = { 'type': 'Point', - 'coordinates': [ - float(row.pop(self.geometry_x)), - float(row.pop(self.geometry_y)) - ] + 'coordinates': coordinates } else: feature['geometry'] = None