/// <summary> /// Converts from Mapsui Geometry type to NetTopologySuite Geometry type, then converts to GeoJSON. /// Writes the point list to wkt format, the uses Geometry2GeoJSON to convert to geojson /// </summary> /// <param name="pointList"></param> /// <returns>GeoJSON</returns> public static string CoordinatesToGeoJSON(List <Mapsui.Geometries.Point> pointList) { var wkt = ""; if (pointList.Count == 1) { var point = pointList[0]; wkt = Mapsui.Geometries.WellKnownText.GeometryToWKT.Write(point); } else if (pointList[0] == pointList[pointList.Count - 1]) { var polygon = new Mapsui.Geometries.Polygon(); foreach (var coord in pointList) { polygon.ExteriorRing.Vertices.Add(new Mapsui.Geometries.Point(coord.X, coord.Y)); } wkt = Mapsui.Geometries.WellKnownText.GeometryToWKT.Write(polygon); } else { var line = new Mapsui.Geometries.LineString(pointList); wkt = Mapsui.Geometries.WellKnownText.GeometryToWKT.Write(line); } WKTReader reader = new WKTReader(); NetTopologySuite.Geometries.Geometry geom = reader.Read(wkt); var geojson = DataDAO.Geometry2GeoJSON(geom); return(geojson); }
public Mapsui.Geometries.Polygon ToPolygon() { var polygon = new Mapsui.Geometries.Polygon(); foreach (Location point in Points) { polygon.ExteriorRing.Vertices.Add(point.ToMapsuiPoint()); } return(polygon); }