PolygonClipOperator Class
Clips features with polygons.
NuGet/Assembly: Carmenta.Engine.5.16.2.nupkg (in the CEOperators assembly)
Syntax
public class PolygonClipOperator : Operator
Remarks
The features from ObjectInput (here called objects) are clipped by the polygon features from ClipperInput (here called clippers). The clipping is controlled by tags:
For each object, an ObjectTag is evaluated, and for each clipper, an InsideClipperTag is evaluated. For each possible pair of object and clipper, with the ObjectTag equal to the InsideClipperTag, clipping is done: the object parts inside the clipper are sent to the output. When the tags differ, nothing is sent to the output (from this pair).
Also, a background clipper is computed to be the area that is outside all clippers. For each object, with the ObjectTag equal to the OutsideClippersTag, the object parts inside the background clipper are sent to the output.
Note that if two clippers intersect, then the object parts in the intersection will appear twice in the output (if the tags match), since each clipper clips individually. The intersection must have positive area to duplicate points, polygons, or meshes, but a zero-area intersection (a shared border of two adjacent clippers) can duplicate lines. If you want to merge clippers that have equal tags, use a ConnectPolygonOperator to preprocess them. If the clippers are only approximately adjacent, you may make them adjacent with a BorderSnapOperator.
To gain speed, both the objects and the clippers should be simplified by a RectangleClipOperator and thinned by a LineThinningOperator before they are passed to the PolygonClipOperator.
Output parts will get attributes from both objects and clippers, as shown in the examples. See ClipperAttributeSuffix for details.
Example 1
![]() |
Lines from ObjectInput are clipped by four clippers from ClipperInput. The default tags are used. Each clipper has a string attribute, Code (either "C", "L", "I", or "P"), which is transferred to the clipped lines. To demonstrate this, the clipped lines have been rendered with the following color in the LineVisualizer:
Code | Color |
---|---|
"C" | Crimson |
"L" | Lime |
"I" | Indigo |
"P" | Pink |
Example 2
![]() |
If we instead want to keep the lines that are outside the clippers, we can just change the ObjectTag to "outside". The important thing is that the ObjectTag now equals the OutsideClippersTag. The clipped lines do not get any attributes from the clippers, in this case.
Example 3
![]() |
If we want to keep lines on the inside as well as the outside, we can change InsideClipperTag, ObjectTag, and OutsideClippersTag to "anyside". The important thing is that all three are equal. We have used two LineVisualizer objects the output. One visualizer takes its color from the clipper Code as in Example 1 and has a condition that the line indeed has a Code attribute. The other visualizer has a condition that the line lacks the Code attribute and its color is always black (its width is increased as well, since it is hard to see the difference between indigo and black).
Example 4
A data provider sells geodata in province chunks. For good measure, the geodata for each province extend 500 m into the neighboring provinces. However, you need to use the geodata countrywide, and the overlap along the province borders causes trouble. For example, if you display lines with anti-alias, then overlapping lines become darker, and if you use a LineThinningOperator to remove unnecessary points, then the result is not consistent for the overlap. But if the geodata for each province has a string attribute provinceCode that uniquely identifies the province, and if you also have the provinces as polygons with the same unique attributes, then a PolygonClipOperator can remove the overlap by clipping the geodata with the province polygons, provided the tag of each object and each clipper is the same as its provinceCode.
![]() |
If the input to the PolygonClipOperator contains some other features that lack the provinceCode attribute, then the ObjectTag above cannot be evaluated for them. Instead, their tag will default to "outside", the value of OutsideClippersTag. Such features will survive the PolygonClipOperator only where they are outside all the province polygons (assuming no provinceCode happens to be the string "outside").
Example 5
![]() |
The picture shows a ground mesh that has been clipped into pieces by terrain-type polygons (water polygons, forest polygons, etc). Each mesh piece gets a terrain-type attribute from its clipper, and the MeshVisualizer uses the attribute to select an appropriate Material for the piece.
Limitations
Before the clipping is done, all objects and clippers are reprojected to the coordinate reference system of the first input object. The clipping is supported for all geometry types, but with some limitations:
Geometry type | Limitations |
---|---|
Point feature | A point that is exactly on an edge of a clipper is regarded as inside the clipper if the outside of the clipper is to the left of the edge, or if the edge is exactly horizontal and the outside is below it. This means that if the clippers cover the plane with no overlaps, each point will be inside exactly one polygon. |
Line feature | A line piece that is exactly on a clipper boundary is regarded as inside the clipper. So if a river defines the border between two clipping country polygons, then the river as a line feature is inside both countries and will appear twice in the output. If you want to make the borders of adjacent clippers into unique lines, you can use a BorderMergeOperator instead. |
Polygon feature | Polygons or polygon parts that have a horizontal area of zero will disappear in the output. Also, the z-coordinates in the output pieces will become zero. |
Raster feature | Since a raster geometry is always rectangular, the raster cells that should be clipped away cannot literally be removed, but will be filled with something invisible. For an RGB or RGBA raster, this will be a completely transparent color, so an RGB raster is automatically converted to RGBA before clipping. For a purely numeric raster or a raster containing indexes into a color table, the invisible value will be the UndefinedValue. If an Undefined value is not specified for the input raster, the operator will specify the largest representable cell value as the Undefined value of the output raster. While doing this, the operator will also, if possible, extend the bit depth of the raster from 8 to 16 bit or from 16 to 32 bit, to avoid specifying an Undefined value that may occur in the input raster. For efficiency, and also because raster features are usually not assigned attributes, a raster object that shall be clipped to the inside of the clipping polygons is treated slightly differently from vector data objects. For each such raster feature, the operator collects all clipping polygons whose InsideClipperTag equals the raster ObjectTag, and clips the raster by this polygon collection using the even-odd rule. The effect is that raster cells that are inside an odd number of polygons remain visible, and the input raster gives rise to at most one clipped output raster, which does not get attributes from the clipping polygon features. This behavior should normally be what you want, and the difference from the behavior for vector data objects is noticeable only when the clipping polygons overlap each other. If you really want to clip a raster by the union of possibly overlapping polygons, you have to calculate the union first by a ConnectPolygonOperator. |
Mesh feature | The clipping does not work if the visualization requires a Material with an explicit MapApplier. |
Inheritance Hierarchy
System.Object (not available in C#)
EngineObject
Operator
PolygonClipOperator
Platforms
Windows, Linux, Android
PolygonClipOperator Members
The PolygonClipOperator type has the following members.
Constructors
Name | Description |
---|---|
PolygonClipOperator | Initializes a new instance of the PolygonClipOperator class. |
Properties
Name | Description |
---|---|
ClipperAttributeSuffix | Gets or sets a suffix to avoid attribute conflicts in clipped features. |
ClipperInput | Gets or sets the input Operator that provides the clipper polygons. |
Description | Gets or sets a short description of the operator. Inherited from Operator |
DisplayName | Gets or sets a display name for the operator. Inherited from Operator |
InsideClipperTag | Gets or sets a value that determines which clipper clips which object. |
IsDisposed | Gets a value that tells whether the current PolygonClipOperator has been disposed. Inherited from EngineObject |
IsoMetadataDocument | Gets or sets the path to an ISO 19139 metadata document for the operator. Inherited from Operator |
Name | Gets or sets the name of the operator. Inherited from Operator |
NativeHandle | Gets the native Carmenta Engine kernel object the current PolygonClipOperator represents. Inherited from EngineObject |
ObjectInput | Gets or sets the input Operator that provides the objects that will clipped by the PolygonClipOperator. |
ObjectTag | Gets or sets a value that determines which object is clipped by which clipper. |
OutsideClippersTag | Gets or sets a value that determines which objects are clipped by the background clipper. |
IUserProperties.UserProperties | Gets the AttributeSet that contains the user properties. Inherited from IUserProperties |
Methods
Name | Description |
---|---|
Clone | Creates a copy of an object. Inherited from EngineObject |
Dispose | Releases the reference to the native Carmenta Engine kernel instance the EngineObject represents. Inherited from EngineObject |
Equals | Determines whether this instance is equal to another. Inherited from EngineObject |
FindChildObject | Overloaded. Finds the child object with the specified name. Inherited from Operator |
FlushCache | Marks the layer as flushed which will release cached resources during the next update. Inherited from Operator |
GetChildObjects | Overloaded. Gets the child objects of the current object. Inherited from Operator |
GetFeatures | Overloaded. Gets features from the operator chain. Inherited from Operator |
GetLocalizedDescription | Gets a localized version of the operator description in a specific language. Inherited from Operator |
GetLocalizedDisplayName | Gets a localized version of the operator display name in a specific language. Inherited from Operator |
GetLocalizedIsoMetadataDocument | Gets the path to an ISO 19139 metadata document for a specific language. Inherited from Operator |
GetRasterFeature | Overloaded. Gets raster features from the operator chain and merges them into a single raster. Inherited from Operator |
HasLocalizedDescription | Checks if a localized version of the operator description is available in a specific language. Inherited from Operator |
HasLocalizedDisplayName | Checks if a localized version of the operator display name is available in a specific language. Inherited from Operator |
HasLocalizedIsoMetadataDocument | Checks if an ISO 19139 metadata document is available for a specific language. Inherited from Operator |
SetLocalizedDescription | Sets a operator description in a specific language. Inherited from Operator |
SetLocalizedDisplayName | Sets a operator display name in a specific language. Inherited from Operator |
SetLocalizedIsoMetadataDocument | Sets the path to an ISO 19139 metadata document for the operator, for a specific language. Inherited from Operator |