Modifying geometries

Geometries are immutable by design, so instances cannot be modified directly. You can programmatically create a modified Geometry instance by:

Note: for interactive creation and editing of geometries (and features), see:

Constraining geometries

The methods on the Geometry classes to make modifications and the GeometryFactory class do not enforce any constraints. It is the user’s responsibility to do so. To help you with this, constraint interfaces are available for every geometry type. See for example

You can implement these, and apply them where needed. This can be done by creating or modifying a geometry, and then applying the constraint.

Program: Constraining a geometry using the API.
// Create a new Polyline and constrain it
auto constraint = std::make_shared<MyPolylineConstraint>();
auto polyline = GeometryFactory::createPolyline(reference, coordinates, LineInterpolationType::Geodesic);
auto constrainedPolyline = constraint->apply(polyline);

// Modify a Polyline and constrain it
auto modifiedPolyline = polyline->translate(translation);
auto polylineChange = PolylineChange();
polylineChange.setTranslation(translation);
constrainedPolyline = constraint->apply(polyline, modifiedPolyline, polylineChange);
// Create a new Polyline and constrain it
var constraint = new MyPolylineConstraint();
var polyline = GeometryFactory.CreatePolyline(reference, coordinates, LineInterpolationType.Geodesic);
var constrainedPolyline = constraint.Apply(polyline);

// Modify a Polyline and constrain it
var modifiedPolyline = polyline.Translate(translation);
var polylineChange = new PolylineChange {Translation = translation};
constrainedPolyline = constraint.Apply(polyline, modifiedPolyline, polylineChange);
// Create a new Polyline and constrain it
MyPolylineConstraint constraint = new MyPolylineConstraint();
Polyline polyline = GeometryFactory.createPolyline(reference, coordinates, LineInterpolationType.Geodesic);
Polyline constrainedPolyline = constraint.apply(polyline);

// Modify a Polyline and constrain it
Polyline modifiedPolyline = polyline.translate(translation);
PolylineChange polylineChange = new PolylineChange();
polylineChange.setTranslation(translation);
constrainedPolyline = constraint.apply(polyline, modifiedPolyline, polylineChange);

Note that interactive editing and creation have out of the box support for constraints. See the related article for more information.