Read() public abstract method

public abstract Read ( ) : bool
return bool
Ejemplo n.º 1
0
        public IGeometry Read(XmlReader reader)
        {
            if (reader.NodeType == XmlNodeType.EndElement)
                throw new ArgumentException("EndElement node type cannot be read by GMLReader.");

            if (IsStartElement(reader, "Point"))
                return ReadPoint(reader);
            if (IsStartElement(reader, "LineString"))
                return ReadLineString(reader);
            if (IsStartElement(reader, "Polygon"))
                return ReadPolygon(reader);
            if (IsStartElement(reader, "MultiPoint"))
                return ReadMultiPoint(reader);
            if (IsStartElement(reader, "MultiLineString"))
                return ReadMultiLineString(reader);
            if (IsStartElement(reader, "MultiPolygon"))
                return ReadMultiPolygon(reader);
            if (IsStartElement(reader, "MultiGeometry"))
                return ReadGeometryCollection(reader);

            // Go away until something readable is found...
            reader.Read();
            return Read(reader);
        }
Ejemplo n.º 2
0
        protected IMultiPolygon ReadMultiPolygon(XmlReader reader)
        {
            List<IPolygon> polygons = new List<IPolygon>();
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (IsStartElement(reader, "polygonMember"))
                            polygons.Add(ReadPolygon(reader));
                        break;

                    case XmlNodeType.EndElement:
                        string name = reader.Name;
                        if (name == "MultiPolygon" || 
                            name == GMLElements.gmlPrefix + ":MultiPolygon")
                            return Factory.CreateMultiPolygon(polygons.ToArray());
                        break;
                }
            }
            throw new ArgumentException("ShouldNeverReachHere!");
        }
Ejemplo n.º 3
0
        protected IGeometryCollection ReadGeometryCollection(XmlReader reader)
        {
            List<IGeometry> collection = new List<IGeometry>();
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (IsStartElement(reader, "Point"))
                            collection.Add(ReadPoint(reader));
                        else if (IsStartElement(reader, "LineString"))
                            collection.Add(ReadLineString(reader));
                        else if (IsStartElement(reader, "Polygon"))
                            collection.Add(ReadPolygon(reader));
                        else if (IsStartElement(reader, "MultiPoint"))
                            collection.Add(ReadMultiPoint(reader));
                        else if (IsStartElement(reader, "MultiLineString"))
                            collection.Add(ReadMultiLineString(reader));
                        else if (IsStartElement(reader, "MultiPolygon"))
                            collection.Add(ReadMultiPolygon(reader));
                        else if (IsStartElement(reader, "MultiGeometry"))
                            collection.Add(ReadGeometryCollection(reader));
                        break;

                    case XmlNodeType.EndElement:
                        string name = reader.Name;
                        if (name == "MultiGeometry" ||
                            name == GMLElements.gmlPrefix + ":MultiGeometry")
                            return Factory.CreateGeometryCollection(collection.ToArray());
                        break;
                }
            }
            throw new ArgumentException("ShouldNeverReachHere!");
        }
Ejemplo n.º 4
0
        protected IMultiLineString ReadMultiLineString(XmlReader reader)
        {
            List<ILineString> lines = new List<ILineString>();
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (IsStartElement(reader, "lineStringMember"))
                            lines.Add(ReadLineString(reader));
                        break;

                    case XmlNodeType.EndElement:
                        string name = reader.Name;
                        if (name == "MultiLineString" || 
                            name == GMLElements.gmlPrefix + ":MultiLineString")
                            return Factory.CreateMultiLineString(lines.ToArray());
                        break;
                }
            }
            throw new ArgumentException("ShouldNeverReachHere!");
        }
Ejemplo n.º 5
0
        protected IPolygon ReadPolygon(XmlReader reader)
        {
            ILinearRing exterior = null;
            List<ILinearRing> interiors = new List<ILinearRing>();
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (IsStartElement(reader, "outerBoundaryIs") ||
                            IsStartElement(reader, "exterior"))
                            exterior = ReadLinearRing(reader);// as LinearRing;
                        else if (IsStartElement(reader, "innerBoundaryIs") ||
                            IsStartElement(reader, "interior"))
                            interiors.Add(ReadLinearRing(reader));
                        break;

                    case XmlNodeType.EndElement:
                        string name = reader.Name;
                        if (name == "Polygon" ||
                            name == GMLElements.gmlPrefix + ":Polygon")
                            return Factory.CreatePolygon(exterior, interiors.ToArray());
                        break;
                }
            }
            throw new ArgumentException("ShouldNeverReachHere!");
        }
Ejemplo n.º 6
0
        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!");
        }
Ejemplo n.º 7
0
 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!");
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Reads the coordinate.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns></returns>
        protected Coordinate ReadCoordinate(XmlReader reader)
        {
            double x = 0, y = 0;
            while (reader.Read())
            {
                switch (reader.NodeType)
                {
                    case XmlNodeType.Element:
                        if (IsStartElement(reader, "X"))
                        {
                            reader.Read(); // Jump to X value
                            x = XmlConvert.ToDouble(reader.Value);
                        }
                        else if (IsStartElement(reader, "Y"))
                        {
                            reader.Read(); // Jump to Y value
                            y = XmlConvert.ToDouble(reader.Value);
                        }
                        break;

                    case XmlNodeType.EndElement:
                        if (reader.Name == GMLElements.gmlPrefix + ":coord")
                            return new Coordinate(x, y);
                        break;
                }
            }
            throw new ArgumentException("ShouldNeverReachHere!");
        }