Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java way to quickly find if a point falls in a country (polygon) [closed]

I'm hoping someone can point me in the right direction.

We have millions of records flowing/streaming through where we need to do a quick lookup to determine which country polygon they fall into.

Could someone recommend a complete JAVA based approach to do this. From what I can tell I would use JTS and/or geotools? My thoughts are to take all of the country polygons and possibly split them up using like a FishNet or Grid to make them smaller for better performance. I would then load these into a java based in-memory spatial index...As the records stream through I would do a lookup into the java spatial index to see what country they fall into. (Maybe like a Spatial Feature collection).

Does this approach sound resonable for lots of data? From a java standpoint how would I implement this? Is this just using JTS and/or Geotools? What type of index would I create. (The polygon data will be static after loading as it will just contain country borders)

From reading geotools documentation its hard to decipher the spatial index and how well it performs and whether it should be used?

Any help or guidance would be appreciated.

Thanks

like image 766
user2092856 Avatar asked Oct 01 '22 14:10

user2092856


1 Answers

The problem you're trying to solve is called the point in polygon problem. A previous answer gave an example of testing if one point is in one polygon, using JTS (Java Topology Suite).

I don't know if there's a more efficient solution for multiple polygons. You might want to test the polygons in turn, sorted by distance from your point.

like image 175
Stuart Caie Avatar answered Oct 05 '22 11:10

Stuart Caie