pelias / polygon-lookup

Fast point-in-polygon intersection for large numbers of polygons.
72 stars 17 forks source link

TypeError if a GeometryCollection is passed #28

Closed simonepri closed 6 years ago

simonepri commented 6 years ago

If this is passed to the constructor, the package throws an error: { type: 'GeometryCollection', geometries: [ { type: 'MultiPolygon', coordinates: [Array] } ] }

TypeError: Cannot read property 'forEach' of undefined
    at PolygonLookup.loadFeatureCollection (./is-land/node_modules/polygon-lookup/index.js:169:22)
    at new PolygonLookup (./is-land/node_modules/polygon-lookup/index.js:23:10)
    at isLand (./is-land/index.js:20:18)
    at repl:1:1
    at ContextifyScript.Script.runInThisContext (vm.js:44:33)
    at REPLServer.defaultEval (repl.js:239:29)
    at bound (domain.js:301:14)
    at REPLServer.runBound [as eval] (domain.js:314:12)
    at REPLServer.onLine (repl.js:433:10)
    at emitOne (events.js:120:20)
missinglink commented 6 years ago

hi @simonepri, the library currently only supports FeatureCollections not GeometryCollections but we would be happy to review a PR to add this functionality.

simonepri commented 6 years ago

This should be enough:

function geometryCollection2featureCollection(geojson) {
  const feats = geojson.geometries.map(geom => {
    return {
      type: 'Feature',
      geometry: geom
    };
  });
  return {type: 'FeatureCollection', features: feats};
}

I'll open a PR soon

simonepri commented 6 years ago

Hi @missinglink, since I found difficult to improve this package without change everything I've decided to build a new package from scratch that supports more types of lookups.

You can find it here: https://github.com/simonepri/geojson-geometries-lookup

I think we can close this issue.