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",
"@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",

View file

@ -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))
}

View file

@ -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
]
}
});