private static string ConvertWkt(string s) { var wkt = new WktText(s); string result = ""; if (wkt.Type == WktType.GeometryCollection) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var geometry in wkt.Token.Tokens) { string text = geometry.Text.Substring(geometry.StartIndex, 1 + geometry.EndIndex - geometry.StartIndex); Console.WriteLine(text); //throw an error if geometry zm != geometry collection zm result += ConvertWkt(text) + ", "; } result += ")"; } //if (wkt.Type == WktType.Tin) //if (wkt.Type == WktType.PolyhedralSurface) if (wkt.Type == WktType.MultiPolygon) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var polygon in wkt.Token.Tokens) { result += "("; foreach (var ring in polygon.Tokens) { result += "("; foreach (var point in ring.Tokens) { result += FixPoint(point.Coords, wkt.CoordinateCount) + ", "; } result += "), "; } result += "), "; } result += ")"; } //if (wkt.Type == WktType.MultiLineString) //if (wkt.Type == WktType.Triangle) if (wkt.Type == WktType.Polygon) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var ring in wkt.Token.Tokens) { result += "("; foreach (var point in ring.Tokens) { result += FixPoint(point.Coords, wkt.CoordinateCount) + ", "; } result += "), "; } result += ")"; } if (wkt.Type == WktType.LineString) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var point in wkt.Token.Tokens) { result += FixPoint(point.Coords, wkt.CoordinateCount) + ", "; } result += ")"; } if (wkt.Type == WktType.MultiLineString) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var path in wkt.Token.Tokens) { result += "("; foreach (var point in path.Tokens) { result += FixPoint(point.Coords, wkt.CoordinateCount) + ", "; } result += "), "; } result += ")"; } if (wkt.Type == WktType.MultiPoint) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); result = wkt.Token.Tokens .Select(point => FixPoint(point.Coords, wkt.CoordinateCount)) .Aggregate(result, (current, coordtext) => current + "(" + coordtext + "), "); result = result.Substring(0, result.Length - 2) + ")"; } if (wkt.Type == WktType.Point) { var coordtext = FixPoint(wkt.Token.Coords, wkt.CoordinateCount); result = string.Format("{0} {1} ({2})", wkt.Type, wkt.ZmText, coordtext); } return result; }
private static string ConvertWkt(string s) { var wkt = new WktText(s); string result = ""; if (wkt.Type == WktType.GeometryCollection) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var geometry in wkt.Token.Tokens) { string text = geometry.Text.Substring(geometry.StartIndex, 1 + geometry.EndIndex - geometry.StartIndex); Console.WriteLine(text); //throw an error if geometry zm != geometry collection zm result += ConvertWkt(text) + ", "; } result += ")"; } //if (wkt.Type == WktType.Tin) //if (wkt.Type == WktType.PolyhedralSurface) if (wkt.Type == WktType.MultiPolygon) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var polygon in wkt.Token.Tokens) { result += "("; foreach (var ring in polygon.Tokens) { result += "("; foreach (var point in ring.Tokens) { result += FixPoint(point.Coords, wkt.CoordinateCount) + ", "; } result += "), "; } result += "), "; } result += ")"; } //if (wkt.Type == WktType.MultiLineString) //if (wkt.Type == WktType.Triangle) if (wkt.Type == WktType.Polygon) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var ring in wkt.Token.Tokens) { result += "("; foreach (var point in ring.Tokens) { result += FixPoint(point.Coords, wkt.CoordinateCount) + ", "; } result += "), "; } result += ")"; } if (wkt.Type == WktType.LineString) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var point in wkt.Token.Tokens) { result += FixPoint(point.Coords, wkt.CoordinateCount) + ", "; } result += ")"; } if (wkt.Type == WktType.MultiLineString) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); foreach (var path in wkt.Token.Tokens) { result += "("; foreach (var point in path.Tokens) { result += FixPoint(point.Coords, wkt.CoordinateCount) + ", "; } result += "), "; } result += ")"; } if (wkt.Type == WktType.MultiPoint) { result = string.Format("{0} {1} (", wkt.Type, wkt.ZmText); result = wkt.Token.Tokens .Select(point => FixPoint(point.Coords, wkt.CoordinateCount)) .Aggregate(result, (current, coordtext) => current + "(" + coordtext + "), "); result = result.Substring(0, result.Length - 2) + ")"; } if (wkt.Type == WktType.Point) { var coordtext = FixPoint(wkt.Token.Coords, wkt.CoordinateCount); result = string.Format("{0} {1} ({2})", wkt.Type, wkt.ZmText, coordtext); } return(result); }