@team-geospan/structuresio 0.0.5 → 0.0.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/geojson.js +42 -0
- package/package.json +1 -1
package/lib/geojson.js
CHANGED
|
@@ -154,3 +154,45 @@ export const toLineStringGeoJSON = (collection) => {
|
|
|
154
154
|
features: allFeatures.flatMap((v) => v),
|
|
155
155
|
};
|
|
156
156
|
};
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Convert a single structure into a list of GeoJSON Features
|
|
160
|
+
* which have Point geometries for accessories.
|
|
161
|
+
*/
|
|
162
|
+
const structureAccessoriesToPointFeature = ({ points }) => {
|
|
163
|
+
const features = Object.keys(points)
|
|
164
|
+
// only convert the accessories to features
|
|
165
|
+
.filter((ea) => points[ea].kind == "accessory")
|
|
166
|
+
.map((pointId) => {
|
|
167
|
+
return {
|
|
168
|
+
type: "Feature",
|
|
169
|
+
properties: {
|
|
170
|
+
id: pointId,
|
|
171
|
+
layer: "accessories",
|
|
172
|
+
kind: "accessory",
|
|
173
|
+
color: points[pointId].color,
|
|
174
|
+
label: points[pointId].label,
|
|
175
|
+
},
|
|
176
|
+
geometry: {
|
|
177
|
+
type: "Point",
|
|
178
|
+
coordinates: points[pointId].coordinates,
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
});
|
|
182
|
+
return features;
|
|
183
|
+
};
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @return A FeatureCollection of the accessories as GeoJSON Point.
|
|
187
|
+
*/
|
|
188
|
+
export const accessoriesToPointGeoJSON = (collection) => {
|
|
189
|
+
// handle either a collection or single structure
|
|
190
|
+
const allFeatures = isCollection(collection)
|
|
191
|
+
? collection.structures.map(structureAccessoriesToPointFeature)
|
|
192
|
+
: [structureAccessoriesToPointFeature(collection)];
|
|
193
|
+
|
|
194
|
+
return {
|
|
195
|
+
type: "FeatureCollection",
|
|
196
|
+
features: allFeatures.flatMap((v) => v),
|
|
197
|
+
};
|
|
198
|
+
};
|