fix: use our fork of csv2geojson to be able to parse lat/lon with commas

This commit is contained in:
Yohan Boniface 2024-11-15 18:10:08 +01:00
parent 810537696d
commit 92ef4b25b4
3 changed files with 19 additions and 10 deletions

View file

@ -40,7 +40,7 @@
"@placemarkio/tokml": "0.3.4", "@placemarkio/tokml": "0.3.4",
"@tmcw/togeojson": "^5.8.0", "@tmcw/togeojson": "^5.8.0",
"colorbrewer": "1.5.7", "colorbrewer": "1.5.7",
"csv2geojson": "5.1.2", "csv2geojson": "github:umap-project/csv2geojson#patched",
"dompurify": "3.1.7", "dompurify": "3.1.7",
"georsstogeojson": "^0.2.0", "georsstogeojson": "^0.2.0",
"jsdom": "^24.0.0", "jsdom": "^24.0.0",

View file

@ -81,6 +81,8 @@ export class Formatter {
{ {
delimiter: 'auto', delimiter: 'auto',
includeLatLon: false, includeLatLon: false,
sexagesimal: false,
parseLatLon: (raw) => Number.parseFloat(raw.toString().replace(',', '.')),
}, },
(err, result) => { (err, result) => {
// csv2geojson fallback to null geometries when it cannot determine // csv2geojson fallback to null geometries when it cannot determine
@ -115,7 +117,9 @@ export class Formatter {
} }
async fromGeoRSS(str) { 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)) return GeoRSSToGeoJSON.parse(this.toDom(str))
} }

View file

@ -81,6 +81,8 @@ function csv2geojson(x, options, callback) {
} }
options.delimiter = options.delimiter || ','; options.delimiter = options.delimiter || ',';
options.parseLatLon = options.parseLatLon || parseFloat;
options.sexagesimal = options.sexagesimal !== false;
var latfield = options.latfield || '', var latfield = options.latfield || '',
lonfield = options.lonfield || '', lonfield = options.lonfield || '',
@ -129,6 +131,7 @@ function csv2geojson(x, options, callback) {
if (!latfield) latfield = guessLatHeader(parsed[0]); if (!latfield) latfield = guessLatHeader(parsed[0]);
if (!lonfield) lonfield = guessLonHeader(parsed[0]); if (!lonfield) lonfield = guessLonHeader(parsed[0]);
var noGeometry = (!latfield || !lonfield); var noGeometry = (!latfield || !lonfield);
if (noGeometry) { if (noGeometry) {
@ -152,13 +155,15 @@ function csv2geojson(x, options, callback) {
lonf, latf, lonf, latf,
a; a;
a = sexagesimal(lonk, 'EW'); if (options.sexagesimal) {
if (a) lonk = a; a = sexagesimal(lonk, 'EW');
a = sexagesimal(latk, 'NS'); if (a) lonk = a;
if (a) latk = a; a = sexagesimal(latk, 'NS');
if (a) latk = a;
}
lonf = parseFloat(lonk); lonf = options.parseLatLon(lonk);
latf = parseFloat(latk); latf = options.parseLatLon(latk);
if (isNaN(lonf) || if (isNaN(lonf) ||
isNaN(latf)) { isNaN(latf)) {
@ -179,8 +184,8 @@ function csv2geojson(x, options, callback) {
geometry: { geometry: {
type: 'Point', type: 'Point',
coordinates: [ coordinates: [
parseFloat(lonf), lonf,
parseFloat(latf) latf
] ]
} }
}); });