protected ILineString ReadLineString(XmlReader reader) { List<Coordinate> coordinates = new List<Coordinate>(); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (IsStartElement(reader, "coord")) { coordinates.Add(ReadCoordinate(reader)); } else if (IsStartElement(reader, "pos")) { reader.Read(); string ordinates = reader.ReadContentAsString(); coordinates.Add(ReadPosAsCoordinate(ordinates.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))); } else if (IsStartElement(reader, "coordinates")) { reader.Read(); // Jump to values string value = reader.Value; string cleaned = value.Replace("\n", " ").Replace("\t", " "); string[] coords = cleaned.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); foreach (string coord in coords) { if (String.IsNullOrEmpty(coord)) continue; Coordinate c = ReadCoordinates(coord); coordinates.Add(c); } return Factory.CreateLineString(coordinates.ToArray()); } else if (IsStartElement(reader, "posList")) { string tmp = reader.GetAttribute("srsDimension"); if (string.IsNullOrEmpty(tmp)) tmp = "2"; reader.Read(); coordinates.AddRange(ReadPosListAsCoordinates(XmlConvert.ToInt32(tmp), reader.ReadContentAsString().Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries))); reader.ReadEndElement(); return Factory.CreateLineString(coordinates.ToArray()); } break; case XmlNodeType.EndElement: return Factory.CreateLineString(coordinates.ToArray()); } } throw new ArgumentException("ShouldNeverReachHere!"); }
protected IPoint ReadPoint(XmlReader reader) { string numOrdinatesText = reader.GetAttribute("srsDimension"); while (reader.Read()) { switch (reader.NodeType) { case XmlNodeType.Element: if (IsStartElement(reader, "coord")) return Factory.CreatePoint(ReadCoordinate(reader)); if (IsStartElement(reader, "pos")) { reader.Read(); // Jump to values string[] coords = reader.Value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (!string.IsNullOrEmpty(numOrdinatesText)) { int numOrdinates = XmlConvert.ToInt32(numOrdinatesText); Assert.IsTrue(coords.Length == numOrdinates, "srsDimension doen't match number of provided ordinates"); } return Factory.CreatePoint(ReadPosAsCoordinate(coords)); } if (IsStartElement(reader, "coordinates")) { reader.Read(); // Jump to values string[] coords = reader.Value.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries); if (coords.Length != 1) throw new ApplicationException("Should never reach here!"); Coordinate c = ReadCoordinates(coords[0]); return Factory.CreatePoint(c); } break; } } throw new ArgumentException("ShouldNeverReachHere!"); }