geofire-js icon indicating copy to clipboard operation
geofire-js copied to clipboard

Polygon shaped geoqueries

Open sauravbiswasiupr opened this issue 10 years ago • 10 comments

What about support for polygon based geoQueries ? The current API seems to provide support only for circular geoQueries.

sauravbiswasiupr avatar Sep 09 '14 23:09 sauravbiswasiupr

Hey @sauravbiswasiupr, mind sharing your use case? We have considered adding rectangular GeoQueries but didn't think there was enough demand for them. I'm interested to hear your thoughts though.

jwngr avatar Sep 10 '14 06:09 jwngr

I too would like polygon search and not just rectangular. I want to draw a polygon around a specific neighborhood and find only data in that polygon for example.

Also I would think rectangular search would be needed in the vast majority of apps that simply want to display data on the current map which is always rectangular.

If polygon search is too hard I could try using https://github.com/firebase/flashlight for polygon search but would much prefer geofire.

jeffcjohnson avatar Oct 30 '14 04:10 jeffcjohnson

Hi @jwngr , sorry for the late reply. Basically consider searching for some location ( lat, lon) that lies inside a polygon of n sides, where n is a finite number. Like @jeffcjohnson mentioned, basically you could draw a polygon of n sides ( say 4 ) on the map, and get a list of vehicles ( or data that you might have stored), in the callback. I think this feature would be pretty cool.

sauravbiswasiupr avatar Oct 30 '14 12:10 sauravbiswasiupr

Thanks for the feedback guys. Polygon-shaped geoqueries are going to be tricky! I think we will most likely implement rectangular geoqueries in the next major release, but I'm not sure exactly how we would implement arbitrary polygon queries. We will definitely need to go back to the drawing board on that one.

If this is really something you want to see, this is an open source project and I would be more than happy to review some code you submit. This is definitely not a small thing to add, but if you need it/want to see it, feel free to throw some code around. I can answer any questions about the code that you have.

I'll keep this issue open until we add some more query types.

jwngr avatar Oct 30 '14 16:10 jwngr

I need to do polygon-based geoqueries too.

What do you think if we reduce this problem to:

  • find a rectangular/circle boundary for the polygon
  • use current geohash method to query for this boundary
  • post-process returned results with a PIP (point in polygon) algorithm?

cxz avatar Feb 14 '15 16:02 cxz

I think that kind of solution would work well in the average case. I unfortunately don't think I'll have a chance to implement this kind of functionality any time soon, but I would gladly review any PRs that come my way.

jwngr avatar Feb 14 '15 18:02 jwngr

Here's an example of how to use Turf.js for reducing a query to a rectangle or polygon shape. Seems like this technique would work well in the Geofire library: http://s.codepen.io/stevepepple/debug/ByVyYX?

Another option would be to take the area of your polygon (or the "extent" of the feature) and create a circle (query) around it.

stevepepple avatar Feb 28 '15 16:02 stevepepple

You guys are talking about a Ray-Casting algorithm found in Google Maps JS API - aka "point in polygon". I agree a feature like this would be absolutely killer.

https://developers.google.com/maps/documentation/javascript/examples/poly-containsLocation

gigablox avatar Oct 02 '15 23:10 gigablox

:+1:

adamduren avatar Jan 09 '16 00:01 adamduren

@gigablox , great suggestion.

Hi @jwngr , we are urrently at the Launch Hackathon, and we could use this feature. Can't you go visit your Google Maps colleagues and ask them how to do it? There a many geodata application which could use this feature.

steffenfrost avatar Feb 27 '16 02:02 steffenfrost