The ILcd2DAdvancedBinaryTopology
interface
let you perform advanced topology checks.
In the following example, we check whether two shapes intersect or touches.
import com.luciad.geodesy.TLcdEllipsoid;
import com.luciad.geometry.ILcd2DAdvancedBinaryTopology;
import com.luciad.geometry.ILcdIntersectionMatrixPattern;
import com.luciad.geometry.ellipsoidal.TLcdEllipsoidalAdvancedBinaryTopology;
import com.luciad.shape.shape2D.ILcd2DEditablePoint;
import com.luciad.shape.shape2D.TLcd2DEditablePointList;
import com.luciad.shape.shape2D.TLcdLonLatPoint;
import com.luciad.shape.shape2D.TLcdLonLatPolygon;
public class AdvancedBinaryTopologyTutorial {
public static void main(String[] args) {
// Create the ellipsoid.
// For this sample, it is hardcoded here.
// In practice, the ellipsoid used by all shapes in the program should be used.
// In a cartesian topology, no ellipsoid is needed.
TLcdEllipsoid ellipsoid = new TLcdEllipsoid();
// Create two shapes.
// For this sample two simple triangles are created.
// In practice, these ILcdShape instances could originate from any source.
TLcdLonLatPolygon polygon1 = new TLcdLonLatPolygon(new TLcd2DEditablePointList(
new ILcd2DEditablePoint[]{
new TLcdLonLatPoint(0.0, 0.0),
new TLcdLonLatPoint(10.0, 20.0),
new TLcdLonLatPoint(20.0, 10.0)
}, false), ellipsoid);
TLcdLonLatPolygon polygon2 = new TLcdLonLatPolygon(new TLcd2DEditablePointList(
new ILcd2DEditablePoint[]{
new TLcdLonLatPoint(11.0, 12.0),
new TLcdLonLatPoint(5.0, 4.0),
new TLcdLonLatPoint(12.0, 0.0)
}, false), ellipsoid);
// Create the advanced binary topology.
ILcd2DAdvancedBinaryTopology topology =
new TLcdEllipsoidalAdvancedBinaryTopology(ellipsoid);
// Test if the shapes intersect and / or touch.
boolean intersects = topology.checkTopology(
polygon1,
polygon2,
ILcdIntersectionMatrixPattern.INTERSECTS
);
System.out.println("The shapes intersect: " + intersects);
boolean touches = topology.checkTopology(
polygon1,
polygon2,
ILcdIntersectionMatrixPattern.TOUCHES
);
System.out.println("The shapes touch: " + touches);
}
}