Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm currently writing a program in Java and I'm dealing with polygon objects. I want to create a different color border between touching objects depending on their class (i.e. land, ocean, etc). I need an algorithm for detecting which segments of my ocean border another ocean or land.

Right now I'm trying to do this by detecting which object share coordinates. And creating a total count of each class, and whichever class has the highest count, that is what that segment is bordering. It's too simple and doesn't work in about 40% of the cases, so I need something better.

Can any one recommend a different idea, or a source to look at?

Thanks in advance.

share|improve this question
up vote 2 down vote accepted

I would look at the GeoTools classes that wrap JTS geometries which provide you with a touches method - see for a discussion of all the geometry relates methods,

share|improve this answer

If your spatial data can be converted to a Shapefile, you can explore various techniques such as buffer, intersection, clipping in the desktop application Quantum GIS. Once the workflow is finalized, you can code it using JTS Topology Suite, a Java API available from SourceForge. Also, you could script a simple solution with JEQL, a spatial script engine that runs on the JVM, using JTS.

share|improve this answer
I wanted to make a general case, for an application that I am creating. I've gotten a bit further where instead of a count I am using a ratio. This bring the success up to about 99%. With some tinkering I think I can get it to 100%. – user15689 Mar 3 '13 at 2:42
Perhaps you can answer your own question then (that's perfectly allowed/encouraged)! – blah238 Mar 3 '13 at 10:04
When I get a working solution, I'll post it! – user15689 Mar 3 '13 at 18:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.