Handle LandXML CgPoints

This commit is contained in:
2021-01-22 15:56:02 +01:00
parent 4a4a26c2bd
commit 988ec50368
8 changed files with 122 additions and 18 deletions

64
lib/cg-point.js Normal file
View File

@ -0,0 +1,64 @@
import { getProp, parseSequence, getColor } from './util'
import { polygon } from '@turf/helpers';
import union from '@turf/union';
import proj4 from 'proj4';
export const LANDXML_POINT = 'cg_point';
export function convertCGPoints(xmlObj, projection, opts) {
const features = [];
const pointsContainerNodes = getProp(xmlObj, "LandXML", "CgPoints");
if (!pointsContainerNodes) return features;
pointsContainerNodes.forEach(pc => {
const attrs = (pc.$ || {});
const baseProps = {
name: attrs.name || "",
description: attrs.description || "",
};
const pointNodes = getProp(pc, "CgPoint");
if (!Array.isArray(pointNodes)) return;
pointNodes.forEach(p => {
const name = baseProps.name ? ( baseProps.name + ' - ' + p.$.name ) : p.$.name;
const description = baseProps.description ? ( baseProps.description + ' - ' + p.$.desc ) : p.$.desc;
const featureProps = {
name: name,
description: description,
landxmlType: LANDXML_POINT,
"stroke-width": 0,
"color": "transparent",
"fill": getColor(`point-${name}`, opts.colorOpts),
"fill-opacity": 0.3,
};
const pointFeature = convertPoint(p, projection, featureProps, opts);
features.push(pointFeature)
});
});
return features;
}
function convertPoint(cgPoint, projection, featureProps) {
let pointCoords = parseSequence(cgPoint._).map(v => parseFloat(v));
pointCoords = [pointCoords[1], pointCoords[0], pointCoords[2]];
pointCoords = proj4(projection, 'WGS84', pointCoords);
return {
type: "Feature",
geometry: {
type: "Point",
coordinates: [...pointCoords, pointCoords[2]],
},
properties: {
...featureProps,
}
};
}

View File

@ -1,8 +1,8 @@
/// #if target == 'native'
import xml2js from 'react-native-xml2js';
import xml2js from 'react-native-xml2js';
/// #else
import xml2js from 'xml2js';
import xml2js from 'xml2js';
/// #endif
import { featureCollection } from '@turf/helpers';
@ -14,16 +14,19 @@ import { getProp } from './util';
import { convertSurfaces } from './surface';
import { convertParcels } from './parcel';
import { convertPipeNetworks } from './pipe-network';
import { convertCGPoints } from './cg-point';
export const PROJECTION_AUTO_DETECT = 'auto_detect';
export const CONVERT_SURFACES = 'surfaces';
export const CONVERT_PARCELS = 'parcels';
export const CONVERT_PIPE_NETWORKS = 'pipe_networks';
export const CONVERT_CG_POINTS = 'cg_points';
const converters = {
[CONVERT_PARCELS]: convertParcels,
[CONVERT_SURFACES]: convertSurfaces,
[CONVERT_PIPE_NETWORKS]: convertPipeNetworks,
[CONVERT_CG_POINTS]: convertCGPoints,
}
// Based on alexgleith's preliminary work
@ -32,7 +35,7 @@ export class Converter {
defaultOptions = {
projection: PROJECTION_AUTO_DETECT,
enabledConverters: [ CONVERT_SURFACES, CONVERT_PARCELS, CONVERT_PIPE_NETWORKS ],
enabledConverters: [ CONVERT_SURFACES, CONVERT_PARCELS, CONVERT_PIPE_NETWORKS, CONVERT_CG_POINTS ],
parser: {
normalize: true
},