diff --git a/package.json b/package.json index e9c95310..049d989a 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ "@placemarkio/tokml": "0.3.4", "@tmcw/togeojson": "^5.8.0", "colorbrewer": "1.5.7", - "csv2geojson": "5.1.2", + "csv2geojson": "github:umap-project/csv2geojson#patched", "dompurify": "3.1.7", "georsstogeojson": "^0.2.0", "jsdom": "^24.0.0", diff --git a/umap/static/umap/js/modules/formatter.js b/umap/static/umap/js/modules/formatter.js index c641da2f..6a03b6b5 100644 --- a/umap/static/umap/js/modules/formatter.js +++ b/umap/static/umap/js/modules/formatter.js @@ -81,6 +81,8 @@ export class Formatter { { delimiter: 'auto', includeLatLon: false, + sexagesimal: false, + parseLatLon: (raw) => Number.parseFloat(raw.toString().replace(',', '.')), }, (err, result) => { // csv2geojson fallback to null geometries when it cannot determine @@ -115,7 +117,9 @@ export class Formatter { } async fromGeoRSS(str) { - const GeoRSSToGeoJSON = await import('../../vendors/georsstogeojson/GeoRSSToGeoJSON.js') + const GeoRSSToGeoJSON = await import( + '../../vendors/georsstogeojson/GeoRSSToGeoJSON.js' + ) return GeoRSSToGeoJSON.parse(this.toDom(str)) } diff --git a/umap/static/umap/vendors/csv2geojson/csv2geojson.js b/umap/static/umap/vendors/csv2geojson/csv2geojson.js index 09a73e5f..260312f5 100644 --- a/umap/static/umap/vendors/csv2geojson/csv2geojson.js +++ b/umap/static/umap/vendors/csv2geojson/csv2geojson.js @@ -81,6 +81,8 @@ function csv2geojson(x, options, callback) { } options.delimiter = options.delimiter || ','; + options.parseLatLon = options.parseLatLon || parseFloat; + options.sexagesimal = options.sexagesimal !== false; var latfield = options.latfield || '', lonfield = options.lonfield || '', @@ -129,6 +131,7 @@ function csv2geojson(x, options, callback) { if (!latfield) latfield = guessLatHeader(parsed[0]); if (!lonfield) lonfield = guessLonHeader(parsed[0]); + var noGeometry = (!latfield || !lonfield); if (noGeometry) { @@ -152,13 +155,15 @@ function csv2geojson(x, options, callback) { lonf, latf, a; - a = sexagesimal(lonk, 'EW'); - if (a) lonk = a; - a = sexagesimal(latk, 'NS'); - if (a) latk = a; + if (options.sexagesimal) { + a = sexagesimal(lonk, 'EW'); + if (a) lonk = a; + a = sexagesimal(latk, 'NS'); + if (a) latk = a; + } - lonf = parseFloat(lonk); - latf = parseFloat(latk); + lonf = options.parseLatLon(lonk); + latf = options.parseLatLon(latk); if (isNaN(lonf) || isNaN(latf)) { @@ -179,8 +184,8 @@ function csv2geojson(x, options, callback) { geometry: { type: 'Point', coordinates: [ - parseFloat(lonf), - parseFloat(latf) + lonf, + latf ] } });