GeoFenceGeoJsonPolygonBuilder(GeoFence, ListGeoFence) Method
Builds a GeoJSON representation of a polygon with an outer boundary (fence) and optional inner boundaries (fences).
The method ensures that the outer fence is right-handed (counterclockwise) and inner fences are left-handed (clockwise),
following GeoJSON conventions for polygons and holes.
Namespace: CoordinateSharpAssembly: CoordinateSharp (in CoordinateSharp.dll) Version: 3.1.1.1
XMLNS for XAML: Not mapped to an xmlns.
public static string GeoJsonPolygonBuilder(
GeoFence outerFence,
List<GeoFence> innerFences
)
- outerFence GeoFence
- The outer boundary of the polygon, which should be right-handed (counterclockwise).
- innerFences ListGeoFence
- A list of inner boundaries (holes), each of which should be left-handed (clockwise).
StringReturns a string representing the GeoJSON format of the polygon with the specified boundaries.
Example usage:
// Create the outer fence (right-handed, closed polygon)
List<Coordinate> outerPoints = new List<Coordinate>()
{
new Coordinate(47.6062, -122.3321), // Seattle
new Coordinate(48.7519, -122.4787), // Bellingham
new Coordinate(47.2529, -122.4443), // Tacoma
new Coordinate(48.0419, -122.9025), // Port Townsend
};
GeoFence outerFence = new GeoFence(outerPoints);
outerFence.OrderPoints_RightHanded();
outerFence.ClosePolygon();
// Create inner fences (left-handed, closed polygons)
List<Coordinate> innerPoints1 = new List<Coordinate>()
{
new Coordinate(46.8523, -121.7603), // Mount Rainier
new Coordinate(46.8625, -121.7401),
new Coordinate(46.8421, -121.7805),
};
GeoFence innerFence1 = new GeoFence(innerPoints1);
innerFence1.OrderPoints_LeftHanded();
innerFence1.ClosePolygon();
List<Coordinate> innerPoints2 = new List<Coordinate>()
{
new Coordinate(47.2331, -119.8529), // Quincy
new Coordinate(47.2400, -119.8700),
new Coordinate(47.2280, -119.8350),
};
GeoFence innerFence2 = new GeoFence(innerPoints2);
innerFence2.OrderPoints_LeftHanded();
innerFence2.ClosePolygon();
// Build the GeoJSON string
string geoJson = GeoFence.GeoJsonPolygonBuilder(outerFence, new List<GeoFence> { innerFence1, innerFence2 });
Console.WriteLine(geoJson);