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.

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.

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%.
–
user15689Mar 3 '13 at 2:42