views:

69

answers:

3

I'm looking for a Java library that is capable of performing spatial calculations on sets of lat/lon data. Here are some of the functions that I'm looking for:

  • Calculate the Great Circle distance between two points
  • Determine if a point lies within a simple closed polygon, where the polygon is defined by an ordered list of points
  • Determine if the line between point "A" and point "B" intersects a simple closed polygon, where the polygon is defined by an ordered list of points
  • Determine if point "A" is within a certain radius of point "B"

What I'm NOT looking for:

  • I don't want a library that is dependent upon a database geospatial component, such as Oracle Spatial, and cannot function independently.
  • I don't want a library whose purpose is to generate graphics/maps/etc. I am building an analysis module for an existing application and the end goal is not to create pretty pictures.
  • I don't want a library for searching large amounts of spatial data. If it also happens to do this, that's ok, but I'm not going to use that feature.

The organization is planning to acquire a license for Oracle Spatial eventually (so spatial searching will be covered at that point), but for now I need to implement the analysis functions that I have mentioned above on small data sets without relying on database-supplied spatial support.

A: 

In spite of your desire to avoid a library that is used to draw maps, I'd recommend OpenMap. The com.bbn.openmap.geo package of that library does most if not all of the things you are asking for.

Jay R.
+2  A: 

I believe GeoTools would satisfy your requirements. Note that it does have facilities for doing graphics/maps, but they can be left unused easily enough.

Reed Copsey
I'm setting up GeoTools now. It is somewhat annoying that they can't take a few minutes to fix all the mistakes in their GeoTools Quickstart tutorial page. Not a nice way to entice newcomers. I wasn't using Maven on this project, so I need to set that up also in order to use GeoTools. Not a big deal if the product does what I need.
Jim Tough
@ReedCopsey The GeoTools kit seems to cover all my requirements. The JTS library that is packaged with GeoTools appears to cover all my needs for "point/shape A" interacts with "point/shape B" use cases. The GeoTools GeodeticCalculator class handles Great Circle distance calculations in the getOrthodromicDistance() method. Maven 2 is pretty much required to setup the JAR dependencies, but I'll just have to sell that to the powers-that-be on the project. Thanks for the recommendation!
Jim Tough
+1  A: 

I once had similar requirements to you on a project under a government contract and this library seemed right on target:

Spheres

http://geospatialmethods.org/spheres/

...

Basic class descriptions:

  • Point
  • LongitudeRange
  • Sphere
  • SphericalPolygon
  • LatLonBoundingBox
  • GreatCircle
  • GreatCircleArc
  • Orbit
  • Scene

Algorithm descriptions:

  • Great Circle intersects Great Circle
  • Great Circle Arc intersects Great Circle Arc
  • Great Circle intersects Latitude
  • Great Circle Arc intersects Latitude Segment

  • SphericalPolygon contains Point

  • SphericalPolygon overlaps SphericalPolygon
  • SphericalPolygon overlaps LatLonBoundingBox
  • SphericalPolygon overlaps Scene

Unfortunately for us, the library was GPL, which made it incompatible for use on that government project (no way would I be allowed to license the applet under GPL). I also was unable to get the copyright holder to create a release under LGPL for us and it was before the creation of the famous "Sun" classpath exception. Hopefully, the license won't trip you up like it did us.

Bert F