Skip to content

Geometry Types

Shiny.Spatial provides a complete set of immutable geometry types following the OGC Simple Features specification. All types are sealed and thread-safe.

A 2D coordinate pair representing a point in space. This is a value type (struct).

var coord = new Coordinate(x: -104.99, y: 39.74);
// Aliases for geographic coordinates
double lon = coord.Longitude; // same as coord.X
double lat = coord.Latitude; // same as coord.Y
PropertyTypeDescription
XdoubleX coordinate (aliased as Longitude)
YdoubleY coordinate (aliased as Latitude)

Supports equality comparison and ToString().

A bounding box (minimum bounding rectangle) defined by min/max coordinates. This is a value type (struct).

var envelope = new Envelope(minX: -109.05, maxX: -102.05, minY: 37.0, maxY: 41.0);
bool inside = envelope.Contains(new Coordinate(-104.99, 39.74)); // true
bool overlaps = envelope.Intersects(otherEnvelope);
var expanded = envelope.ExpandToInclude(new Coordinate(-110.0, 42.0));
PropertyTypeDescription
MinXdoubleMinimum X value
MaxXdoubleMaximum X value
MinYdoubleMinimum Y value
MaxYdoubleMaximum Y value
WidthdoubleMaxX - MinX
HeightdoubleMaxY - MinY
CenterCoordinateCenter point of the envelope
MethodReturnsDescription
Contains(Coordinate)boolWhether the coordinate is inside the envelope
Intersects(Envelope)boolWhether two envelopes overlap
ExpandToInclude(Coordinate)EnvelopeReturns a new envelope expanded to include the coordinate

The static Envelope.Empty property returns an empty envelope.

All geometry types extend the abstract Geometry class.

Property/MethodTypeDescription
TypeGeometryTypeThe geometry type enum value
IsEmptyboolWhether the geometry contains no coordinates
GetEnvelope()EnvelopeComputes the minimum bounding rectangle
public enum GeometryType
{
Point = 1,
LineString = 2,
Polygon = 3,
MultiPoint = 4,
MultiLineString = 5,
MultiPolygon = 6,
GeometryCollection = 7
}

A single coordinate in space.

var point = new Point(-104.99, 39.74);
double x = point.X; // -104.99
double y = point.Y; // 39.74
var coord = point.Coordinate;
PropertyTypeDescription
CoordinateCoordinateThe point’s coordinate
XdoubleX value
YdoubleY value

An ordered sequence of two or more coordinates forming a line.

var line = new LineString(new[]
{
new Coordinate(0, 0),
new Coordinate(1, 1),
new Coordinate(2, 0)
});
bool closed = line.IsClosed; // false (first != last coordinate)
PropertyTypeDescription
CoordinatesIReadOnlyList<Coordinate>Ordered list of coordinates
IsClosedboolWhether first and last coordinates are equal

A closed shape defined by an exterior ring and optional interior rings (holes).

// Simple polygon (no holes)
var polygon = new Polygon(new[]
{
new Coordinate(-109.05, 37.0),
new Coordinate(-102.05, 37.0),
new Coordinate(-102.05, 41.0),
new Coordinate(-109.05, 41.0),
new Coordinate(-109.05, 37.0) // must close the ring
});
// Polygon with a hole
var withHole = new Polygon(
exteriorRing: new[]
{
new Coordinate(0, 0), new Coordinate(10, 0),
new Coordinate(10, 10), new Coordinate(0, 10),
new Coordinate(0, 0)
},
interiorRings: new[]
{
new[]
{
new Coordinate(2, 2), new Coordinate(8, 2),
new Coordinate(8, 8), new Coordinate(2, 8),
new Coordinate(2, 2)
}
}
);
PropertyTypeDescription
ExteriorRingIReadOnlyList<Coordinate>The outer boundary coordinates
InteriorRingsIReadOnlyList<IReadOnlyList<Coordinate>>Hole boundaries (may be empty)

A collection of Point geometries.

var multiPoint = new MultiPoint(new[]
{
new Point(0, 0),
new Point(1, 1),
new Point(2, 2)
});
PropertyTypeDescription
PointsIReadOnlyList<Point>The collection of points

A collection of LineString geometries.

var multi = new MultiLineString(new[]
{
new LineString(new[] { new Coordinate(0, 0), new Coordinate(1, 1) }),
new LineString(new[] { new Coordinate(2, 2), new Coordinate(3, 3) })
});
PropertyTypeDescription
LineStringsIReadOnlyList<LineString>The collection of line strings

A collection of Polygon geometries.

var multi = new MultiPolygon(new[] { polygon1, polygon2 });
PropertyTypeDescription
PolygonsIReadOnlyList<Polygon>The collection of polygons

A heterogeneous collection of any geometry types.

var collection = new GeometryCollection(new Geometry[]
{
new Point(0, 0),
new LineString(new[] { new Coordinate(1, 1), new Coordinate(2, 2) }),
polygon
});
PropertyTypeDescription
GeometriesIReadOnlyList<Geometry>The collection of mixed geometries