/// <summary> /// LineString from WKT. /// </summary> /// <returns>The LineString</returns> /// <param name="wkt">WKT.</param> public static LineString LineStringFromWKT(string wkt) { var terms = wkt.TrimStart('(').TrimEnd(')').Split(','); string[] values; var positions = new List <IPosition>(terms.Length); GeographicPosition prevgeopos = null; for (var i = 0; i < terms.Length; i++) { values = terms[i].Trim(' ').Split(' '); var z = (values.Length > 2 ? values[2] : null); var geopos = new GeographicPosition(values[1], values[0], z); try { if (prevgeopos != null && Enumerable.SequenceEqual(geopos.Coordinates, prevgeopos.Coordinates)) { continue; } } catch { } positions.Add(geopos); prevgeopos = geopos; } var test = new LineString(positions); return(test); }
/// <summary> /// Point from WK. /// </summary> /// <returns>The Point</returns> /// <param name="wkt">WKT.</param> public static Point PointFromWKT(string wkt) { string[] values; values = wkt.Trim(' ').Split(' '); var z = (values.Length > 2 ? values[2] : null); var geopos = new GeographicPosition(values[1], values[0], z); return(new Point(geopos)); }
/// <summary> /// MultiPoint from WK. /// </summary> /// <returns>The MultiPoint</returns> /// <param name="wkt">WKT.</param> public static MultiPoint MultiPointFromWKT(string wkt) { var terms = wkt.TrimStart('(').TrimEnd(')').Trim(' ').Split(','); string[] values; var points = new List <IPosition>(terms.Length); for (var i = 0; i < terms.Length; i++) { values = terms[i].TrimStart('(').TrimEnd(')').Split(' '); var z = (values.Length > 2 ? values[2] : null); var geopos = new GeographicPosition(values[1], values[0], z); points.Add(geopos); } return(new MultiPoint(points)); }
public static List <LineString> SplitWorldExtent(LineString lineString) { List <LineString> newLineStrings = new List <LineString>(); LineString currentLineString = new LineString(); newLineStrings.Add(currentLineString); GeographicPosition previous_position = (GeographicPosition)lineString.Positions[0]; currentLineString.Positions.Add(previous_position); int currentPosition = 0; int dayline = 0; for (int i = 1; i < lineString.Positions.Count; i++) { GeographicPosition current_position = (GeographicPosition)lineString.Positions[i]; if ((current_position.Longitude != 180 && previous_position.Longitude != 180) || (current_position.Longitude != -180 && previous_position.Longitude != -180)) { if ((current_position.Longitude - previous_position.Longitude < -90) || (current_position.Longitude - previous_position.Longitude > 90)) { LineString newLineString = currentLineString; if (current_position.Longitude - previous_position.Longitude > 90) { dayline--; if (currentPosition == 0) { newLineString = new LineString(); newLineStrings.Insert(0, newLineString); } else { newLineString = newLineStrings[--currentPosition]; } } if (current_position.Longitude - previous_position.Longitude < -90) { dayline++; if (newLineStrings.Count <= currentPosition + 1) { newLineString = new LineString(); newLineStrings.Add(newLineString); } else { newLineString = newLineStrings[currentPosition + 1]; } currentPosition++; } double new_longitude; double new_latitude; double?new_altitude; double new_longitude2; double new_latitude2; double?new_altitude2; if (previous_position.Longitude > 0) { new_longitude = 180; new_longitude2 = -180; } else { new_longitude = -180; new_longitude2 = 180; } // Calaculate the latitude to be linear with the next point if ((current_position.Longitude - previous_position.Longitude + 2 * new_longitude) == 0) { new_latitude = (current_position.Latitude - previous_position.Latitude) * (-1 * new_longitude - previous_position.Longitude + 2 * new_longitude) + previous_position.Latitude; } else { new_latitude = (current_position.Latitude - previous_position.Latitude) * (-1 * new_longitude - previous_position.Longitude + 2 * new_longitude) / (current_position.Longitude - previous_position.Longitude + 2 * new_longitude) + previous_position.Latitude; } new_latitude2 = new_latitude; new_altitude = new_altitude2 = current_position.Altitude; GeographicPosition new_position1 = new GeographicPosition(new_latitude, new_longitude, new_altitude); GeographicPosition new_position2 = new GeographicPosition(new_latitude2, new_longitude2, new_altitude2); newLineString.Positions.Add(new_position2); currentLineString.Positions.Add(new_position1); if (dayline == 0) { currentLineString.Positions.Add(currentLineString.Positions[0]); } currentLineString = newLineString; } } currentLineString.Positions.Add(current_position); previous_position = current_position; } return(newLineStrings); }