dynamodb-geo.js icon indicating copy to clipboard operation
dynamodb-geo.js copied to clipboard

Radius Query. Cannot read property 'getRectBound' of undefined

Open ildar-icoosoft opened this issue 6 years ago • 5 comments

I get error "Cannot read property 'getRectBound' of undefined" if radius is greater than 1063652 meters.

Herre is my code:

myGeoTableManager.queryRadius({
    RadiusInMeter: radius,
    CenterPoint: {
        longitude: longitude,
        latitude: latitude,
    }
})

Here is the stack trace:

TypeError: Cannot read property 'getRectBound' of undefined
    at S2LatLngRect.mayIntersectC (/var/task/node_modules/nodes2ts/dist/S2LatLngRect.js:515:39)
    at S2RegionCoverer.newCandidate (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:210:26)
    at S2RegionCoverer.getInitialCandidates (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:341:36)
    at S2RegionCoverer.getCoveringInternal (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:366:14)
    at S2RegionCoverer.getCoveringUnion (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:181:14)
    at S2RegionCoverer.getCoveringCells (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:156:24)
    at GeoDataManager.queryRadius (/var/task/node_modules/dynamodb-geo/dist/GeoDataManager.js:205:82)
    at _callee$ (/var/task/handler.js:138:38)
    at tryCatch (/var/task/node_modules/regenerator-runtime/runtime.js:65:40)
    at GeneratorFunctionPrototype.invoke [as _invoke] (/var/task/node_modules/regenerator-runtime/runtime.js:299:22)

ildar-icoosoft avatar Sep 24 '17 15:09 ildar-icoosoft

I have the same issue. Is there a fix for this issue?

lantikchi avatar Mar 06 '18 06:03 lantikchi

It turns out this is a bug in nodes2ts but the fix is still unreleased.

An ugly-but-effective option is to patch nodes2ts at run-time with:

require('nodes2ts').S2RegionCoverer.FACE_CELLS = [0, 1, 2, 3, 4, 5].map(face => S2Cell.fromFacePosLevel(face, 0, 0));

Running that once before using either radius or rectangle queries should be enough. If the author of nodes2ts doesn't release a new version soon I'll add that patch to this lib.

robhogan avatar Apr 08 '18 17:04 robhogan

Hi sorry for the rookie question, but how do you actually "patch nodes2ts at run-time"? More precisely, where am I supposed to require the following line of code? I get a similar error but with the "queryRectangle()", here is the stack trace:

TypeError: Cannot read property 'getRectBound' of undefined
at S2LatLngRect.mayIntersectC (/var/task/node_modules/nodes2ts/dist/S2LatLngRect.js:515:40)
at S2RegionCoverer.newCandidate (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:210:26)
at S2RegionCoverer.getInitialCandidates (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:341:36)
at S2RegionCoverer.getCoveringInternal (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:366:14)
at S2RegionCoverer.getCoveringUnion (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:181:14)
at S2RegionCoverer.getCoveringCells (/var/task/node_modules/nodes2ts/dist/S2RegionCoverer.js:156:24)
at GeoDataManager.queryRectangle (/var/task/node_modules/dynamodb-geo/dist/GeoDataManager.js:176:82)
at module.exports (/var/task/garden-handler.js:599:26)
at exports.graphqlHandler (/var/task/garden-handler.js:253:9)

Any help would be appreciated!

Sh3nr0n avatar Jul 04 '18 13:07 Sh3nr0n

Put that line in your own app's code, anywhere you like (once per-process should be enough) as long as it's before you call queryRadius or queryRectangle.

You could put it right on the line before your queryRadius call if you like, but somewhere in your app's init might be neater - up to you.

robhogan avatar Jul 04 '18 13:07 robhogan

Thanks for your help, I'll try that!

Sh3nr0n avatar Jul 04 '18 14:07 Sh3nr0n