From ab88fe48a4d5adf14bce2088c25755bc0aa9ffe2 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 22 Oct 2015 10:10:23 -0700 Subject: [PATCH] csv: fixup error messages when geometry fails to parse --- plugins/input/csv/csv_utils.hpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/plugins/input/csv/csv_utils.hpp b/plugins/input/csv/csv_utils.hpp index 2174c8de9..b1894da4e 100644 --- a/plugins/input/csv/csv_utils.hpp +++ b/plugins/input/csv/csv_utils.hpp @@ -259,38 +259,40 @@ static inline bool valid(geometry_column_locator const& locator, std::size_t max static inline mapnik::geometry::geometry extract_geometry(std::vector const& row, geometry_column_locator const& locator) { mapnik::geometry::geometry geom; - auto idx1 = row.at(locator.index); if (locator.type == geometry_column_locator::WKT) { - if (mapnik::from_wkt(idx1, geom)) + auto wkt_value = row.at(locator.index); + if (mapnik::from_wkt(wkt_value, geom)) { // correct orientations .. mapnik::geometry::correct(geom); } else { - throw mapnik::datasource_exception("Failed to parse WKT:" + idx1); + throw mapnik::datasource_exception("Failed to parse WKT: '" + wkt_value + "'"); } } else if (locator.type == geometry_column_locator::GEOJSON) { - if (!mapnik::json::from_geojson(idx1, geom)) + auto json_value = row.at(locator.index); + if (!mapnik::json::from_geojson(json_value, geom)) { - throw mapnik::datasource_exception("Failed to parse GeoJSON:" + idx1); + throw mapnik::datasource_exception("Failed to parse GeoJSON: '" + json_value + "'"); } } else if (locator.type == geometry_column_locator::LON_LAT) { double x, y; - auto idx2 = row.at(locator.index2); - if (!mapnik::util::string2double(idx1,x)) + auto long_value = row.at(locator.index); + auto lat_value = row.at(locator.index2); + if (!mapnik::util::string2double(long_value,x)) { - throw mapnik::datasource_exception("Failed to parse Longitude(Easting):" + idx1); + throw mapnik::datasource_exception("Failed to parse Longitude: '" + long_value + "'"); } - if (!mapnik::util::string2double(idx2,y)) + if (!mapnik::util::string2double(lat_value,y)) { - throw mapnik::datasource_exception("Failed to parse Latitude(Northing):" + idx2); + throw mapnik::datasource_exception("Failed to parse Latitude: '" + lat_value + "'"); } geom = mapnik::geometry::point(x,y); }