MCPcopy Index your code
hub / github.com/SuperMap/iClient-JavaScript / geojson2UGGeometry

Function geojson2UGGeometry

src/common/wasm/util.js:181–344  ·  view source on GitHub ↗
(geojson)

Source from the content-addressed store, hash-verified

179 * @returns {number} A pointer to GEOS geometry
180 */
181export function geojson2UGGeometry(geojson) {
182 if (!geojson) {
183 throw new Error('No GeoJSON object provided')
184 }
185
186 // assume only 2d (x, y) geometries
187 switch (geojson.type) {
188 case 'Feature':
189 return geojson2UGGeometry(geojson.geometry)
190 case 'FeatureCollection':
191 if (geojson.features.length === 0) {
192 return null
193 } else {
194 return geojson2UGGeometry(geojson.features[0].geometry)
195 }
196 // case 'GeometryCollection':
197 // if (geojson.geometries.length === 0) {
198 // return geos.GEOSGeom_createEmptyCollection(7) // geos.GEOS_GEOMETRYCOLLECTION
199 // } else {
200 // const geoms = []
201 // // iterate over each feature
202 // geojson.geometries.forEach((feature) => {
203 // geoms.push(geojsonToGeosGeom(feature, geos))
204 // })
205 // const geomsPtr = geos.window.ugcModule._malloc(geoms.length * 4)
206 // const geomsArr = new Uint32Array(geoms)
207 // geos.window.ugcModule.HEAPU32.set(geomsArr, geomsPtr / 4)
208 // const multiGeomsPtr = geos.GEOSGeom_createCollection(
209 // 7, // geos.GEOS_GEOMETRYCOLLECTION
210 // geomsPtr,
211 // geoms.length
212 // )
213 // geos.window.ugcModule._free(geomsPtr)
214 // return multiGeomsPtr
215 // }
216 case 'Point':
217 if (geojson.coordinates.length === 0) {
218 return window.ugcModule._UGCWasm_GeoPoint_New()
219 } else {
220 return window.ugcModule._UGCWasm_GeoPoint_New2(
221 geojson.coordinates[0],
222 geojson.coordinates[1]
223 )
224 }
225 case 'LineString':
226 if (geojson.coordinates.length === 0) {
227 return window.ugcModule._UGCWasm_GeoLine_New()
228 } else {
229 const pGeoLine = window.ugcModule._UGCWasm_GeoLine_New()
230 const pPoint2Ds = geojsonCoordsToPoint2Ds(geojson.coordinates)
231 window.ugcModule._UGCWasm_GeoLine_AddPart2(pGeoLine, pPoint2Ds, geojson.coordinates.length)
232
233 return pGeoLine
234 }
235 case 'Polygon':
236 if (geojson.coordinates.length === 0) {
237 return window.ugcModule._UGCWasm_GeoRegion_New()
238 } else {

Callers 10

bufferMethod · 0.90
isIdenticalMethod · 0.90
hasIntersectionMethod · 0.90
hasTouchMethod · 0.90
resampleMethod · 0.90
nearestPointToVertexMethod · 0.90
computeGeodesicAreaMethod · 0.90
smoothMethod · 0.90
computeParallelMethod · 0.90

Calls 1

geojsonCoordsToPoint2DsFunction · 0.85

Tested by

no test coverage detected