Пример #1
0
        /// <summary>
        /// This method parses quickly without paying attention to
        /// context validation, polygon boundaries and multi-geometries.
        /// This accelerates the geometry parsing process,
        /// but in scarce cases can lead to errors.
        /// </summary>
        /// <param name="geometryType">The geometry type (Point, LineString, Polygon, MultiPoint, MultiCurve,
        /// MultiLineString (deprecated), MultiSurface, MultiPolygon (deprecated)</param>
        /// <returns>The created geometries</returns>
        internal virtual Collection <IGeometry> createQuickGeometries(string geometryType)
        {
            // Ignore multi-geometries
            if (geometryType.Equals("MultiPointPropertyType"))
            {
                geometryType = "PointPropertyType";
            }
            else if (geometryType.Equals("MultiLineStringPropertyType"))
            {
                geometryType = "LineStringPropertyType";
            }
            else if (geometryType.Equals("MultiPolygonPropertyType"))
            {
                geometryType = "PolygonPropertyType";
            }
            else if (geometryType.Equals("MultiCurvePropertyType"))
            {
                geometryType = "CurvePropertyType";
            }
            else if (geometryType.Equals("MultiSurfacePropertyType"))
            {
                geometryType = "SurfacePropertyType";
            }

            string serviceException = null;

            while (_XmlReader.Read())
            {
                if (_CoordinatesNode.Matches(_XmlReader))
                {
                    try
                    {
                        switch (geometryType)
                        {
                        case "PointPropertyType":
                            _Geoms.Add(Factory.CreatePoint(ParseCoordinates(_XmlReader.ReadSubtree())[0]));
                            break;

                        case "LineStringPropertyType":
                        case "CurvePropertyType":
                            _Geoms.Add(Factory.CreateLineString(ParseCoordinates(_XmlReader.ReadSubtree())));
                            break;

                        case "PolygonPropertyType":
                        case "SurfacePropertyType":
                            _Geoms.Add(Factory.CreatePolygon(
                                           Factory.CreateLinearRing(ParseCoordinates(_XmlReader.ReadSubtree())), null));
                            break;

                        default:
                            break;
                        }
                    }
                    catch (Exception ex)
                    {
                        Trace.TraceError("An exception occured while parsing a " + geometryType + " geometry: " +
                                         ex.Message);
                        throw ex;
                    }
                    continue;
                }

                if (_ServiceExceptionNode.Matches(_XmlReader))
                {
                    serviceException = _XmlReader.ReadInnerXml();
                    Trace.TraceError("A service exception occured: " + serviceException);
                    throw new Exception("A service exception occured: " + serviceException);
                }
            }

            return(_Geoms);
        }
Пример #2
0
        /// <summary>
        /// This method detects the geometry type from 'GetFeature' response and uses a geometry factory to create the
        /// appropriate geometries.
        /// </summary>
        /// <returns></returns>
        internal override Collection <IGeometry> createGeometries()
        {
            GeometryFactory geomFactory = null;

            string geometryTypeString = string.Empty;
            string serviceException   = null;

            if (_QuickGeometries)
            {
                _MultiGeometries = false;
            }

            IPathNode pointNode              = new PathNode(_GMLNS, "Point", (NameTable)_XmlReader.NameTable);
            IPathNode lineStringNode         = new PathNode(_GMLNS, "LineString", (NameTable)_XmlReader.NameTable);
            IPathNode polygonNode            = new PathNode(_GMLNS, "Polygon", (NameTable)_XmlReader.NameTable);
            IPathNode multiPointNode         = new PathNode(_GMLNS, "MultiPoint", (NameTable)_XmlReader.NameTable);
            IPathNode multiLineStringNode    = new PathNode(_GMLNS, "MultiLineString", (NameTable)_XmlReader.NameTable);
            IPathNode multiCurveNode         = new PathNode(_GMLNS, "MultiCurve", (NameTable)_XmlReader.NameTable);
            IPathNode multiLineStringNodeAlt = new AlternativePathNodesCollection(multiLineStringNode, multiCurveNode);
            IPathNode multiPolygonNode       = new PathNode(_GMLNS, "MultiPolygon", (NameTable)_XmlReader.NameTable);
            IPathNode multiSurfaceNode       = new PathNode(_GMLNS, "MultiSurface", (NameTable)_XmlReader.NameTable);
            IPathNode multiPolygonNodeAlt    = new AlternativePathNodesCollection(multiPolygonNode, multiSurfaceNode);

            while (_XmlReader.Read())
            {
                if (_XmlReader.NodeType == XmlNodeType.Element)
                {
                    if (_MultiGeometries)
                    {
                        if (multiPointNode.Matches(_XmlReader))
                        {
                            geomFactory        = new MultiPointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                            geometryTypeString = "MultiPointPropertyType";
                            break;
                        }
                        if (multiLineStringNodeAlt.Matches(_XmlReader))
                        {
                            geomFactory        = new MultiLineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                            geometryTypeString = "MultiLineStringPropertyType";
                            break;
                        }
                        if (multiPolygonNodeAlt.Matches(_XmlReader))
                        {
                            geomFactory        = new MultiPolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                            geometryTypeString = "MultiPolygonPropertyType";
                            break;
                        }
                    }

                    if (pointNode.Matches(_XmlReader))
                    {
                        geomFactory        = new PointFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                        geometryTypeString = "PointPropertyType";
                        break;
                    }
                    if (lineStringNode.Matches(_XmlReader))
                    {
                        geomFactory        = new LineStringFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                        geometryTypeString = "LineStringPropertyType";
                        break;
                    }
                    if (polygonNode.Matches(_XmlReader))
                    {
                        geomFactory        = new PolygonFactory(_HttpClientUtil, _FeatureTypeInfo, _LabelInfo);
                        geometryTypeString = "PolygonPropertyType";
                        break;
                    }
                    if (_ServiceExceptionNode.Matches(_XmlReader))
                    {
                        serviceException = _XmlReader.ReadInnerXml();
                        Trace.TraceError("A service exception occured: " + serviceException);
                        throw new Exception("A service exception occured: " + serviceException);
                    }
                }
            }

            _FeatureTypeInfo.Geometry._GeometryType = geometryTypeString;
            if (geomFactory != null)
            {
                geomFactory.AxisOrder = AxisOrder;

                var res = _QuickGeometries
                    ? geomFactory.createQuickGeometries(geometryTypeString)
                    : geomFactory.createGeometries();

                geomFactory.Dispose();
                return(res);
            }


            return(_Geoms);
        }