The geometric functionality discussed in this article is part of the |
You can perform constructive geometry calculations with a ConstructiveGeometry
implementation. You create the implementation with a factory method from ConstructiveGeometryFactory
.
import {getReference} from "@luciad/ria/reference/ReferenceProvider.js";
import {createEllipsoidal} from "@luciad/ria-geometry/geometry/constructive/ConstructiveGeometryFactory.js";
import {createPolygon, createPoint} from "@luciad/ria/shape/ShapeFactory.js";
const reference = getReference('CRS:84');
// Create a ConstructiveGeometry instances that uses an ellipsoidal topology
const constructiveGeometry = createEllipsoidal(reference);
//Create 2 polygons
const polygon1 = createPolygon(reference,
createPoint(reference, [0.0, 0.0]),
createPoint(reference, [10.0, 20.0]),
createPoint(reference, [20.0, 10.0]));
const polygon2 = createPolygon(reference,
createPoint(reference, [11.0, 12.0]),
createPoint(reference, [5.0, 4.0]),
createPoint(reference, [12.0, 0.0]));
//Calculate intersections, unions and differences of those polygons
const union = constructiveGeometry.union([polygon1, polygon2]);
const difference = constructiveGeometry.difference([polygon1, polygon2]);
const intersection = constructiveGeometry.intersection([polygon1, polygon2]);