mirror of
https://github.com/Fabio286/antares.git
synced 2025-02-17 12:10:39 +01:00
feat(MySQL): support to multi spatial fields export
This commit is contained in:
parent
fd00ea42ee
commit
4be55f3fe9
@ -1,5 +1,5 @@
|
|||||||
import { SqlExporter } from './SqlExporter';
|
import { SqlExporter } from './SqlExporter';
|
||||||
import { BLOB, BIT, DATE, DATETIME, FLOAT, SPATIAL, NUMBER } from 'common/fieldTypes';
|
import { BLOB, BIT, DATE, DATETIME, FLOAT, SPATIAL, IS_MULTI_SPATIAL, NUMBER } from 'common/fieldTypes';
|
||||||
import hexToBinary from 'common/libs/hexToBinary';
|
import hexToBinary from 'common/libs/hexToBinary';
|
||||||
import { getArrayDepth } from 'common/libs/getArrayDepth';
|
import { getArrayDepth } from 'common/libs/getArrayDepth';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
@ -134,15 +134,19 @@ ${footer}
|
|||||||
else if (FLOAT.includes(column.type))
|
else if (FLOAT.includes(column.type))
|
||||||
sqlInsertString += parseFloat(val);
|
sqlInsertString += parseFloat(val);
|
||||||
else if (SPATIAL.includes(column.type)) {
|
else if (SPATIAL.includes(column.type)) {
|
||||||
let geoJson = '';
|
let geoJson;
|
||||||
if (Array.isArray(val)) {
|
if (IS_MULTI_SPATIAL.includes(column.type)) {
|
||||||
if (getArrayDepth(val) === 1)
|
const features = [];
|
||||||
geoJson = lineString(val.reduce((acc, curr) => [...acc, [curr.x, curr.y]], []));
|
for (const element of val)
|
||||||
else
|
features.push(this.getMarkers(element));
|
||||||
geoJson = polygon(val.map(arr => arr.reduce((acc, curr) => [...acc, [curr.x, curr.y]], [])));
|
|
||||||
|
geoJson = {
|
||||||
|
type: 'FeatureCollection',
|
||||||
|
features
|
||||||
|
};
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
geoJson = point([val.x, val.y]);
|
geoJson = this._getGeoJSON(val);
|
||||||
|
|
||||||
sqlInsertString += `ST_GeomFromGeoJSON('${JSON.stringify(geoJson)}')`;
|
sqlInsertString += `ST_GeomFromGeoJSON('${JSON.stringify(geoJson)}')`;
|
||||||
}
|
}
|
||||||
@ -392,4 +396,15 @@ ${footer}
|
|||||||
|
|
||||||
return `'${escapedVal}'`;
|
return `'${escapedVal}'`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_getGeoJSON (val) {
|
||||||
|
if (Array.isArray(val)) {
|
||||||
|
if (getArrayDepth(val) === 1)
|
||||||
|
return lineString(val.reduce((acc, curr) => [...acc, [curr.x, curr.y]], []));
|
||||||
|
else
|
||||||
|
return polygon(val.map(arr => arr.reduce((acc, curr) => [...acc, [curr.x, curr.y]], [])));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return point([val.x, val.y]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user