Beispiel #1
0
        private GeometryPolygon ParseGeometry(XmlNode node)
        {
            var gmlNode = node["bag_LVC:pandGeometrie"].FirstChild;

            OverrideSrsNameAttribute(gmlNode);

            var reader = new XmlNodeReader(gmlNode);

            return(_gmlFormatter.Read <GeometryPolygon>(reader));
        }
Beispiel #2
0
 public Geography GeographyFromGml(string gml)
 {
     try
     {
         GmlFormatter gmlFormatter = GmlFormatter.Create();
         TextReader   reader       = new StringReader(gml);
         var          r            = XmlReader.Create(reader);
         return(gmlFormatter.Read <Geography>(r));
     }
     catch
     {
         return(null);
     }
 }
Beispiel #3
0
        private static JsonObject ReadJsonSpatialProperty(XElement container, XElement gmlValue, bool isGeography)
        {
            GmlFormatter           gmlFormatter  = GmlFormatter.Create();
            GeoJsonObjectFormatter jsonformatter = GeoJsonObjectFormatter.Create();

            bool ignoreCrc = !gmlValue.Attributes().Any(a => a.Name.LocalName == "srsName");

            ISpatial spatialValue;

            if (isGeography)
            {
                spatialValue = gmlFormatter.Read <Geography>(gmlValue.CreateReader());
            }
            else
            {
                spatialValue = gmlFormatter.Read <Geometry>(gmlValue.CreateReader());
            }

            IDictionary <string, object> geoJsonData = jsonformatter.Write(spatialValue);
            JsonObject json = new JsonObject();

            Queue <object> geoJsonScopes = new Queue <object>();
            Queue <object> jsonScopes    = new Queue <object>();

            geoJsonScopes.Enqueue(geoJsonData);
            jsonScopes.Enqueue(json);

            Func <object, object> convertScope = (scope) =>
            {
                object newScope =
                    scope is List <object> || scope is object[] ? (object)new List <Object>() :
                    scope is IDictionary <string, object>?(object)new JsonObject() :
                        null;

                if (newScope != null)
                {
                    geoJsonScopes.Enqueue(scope);
                    jsonScopes.Enqueue(newScope);
                }

                return(newScope ?? scope);
            };

            while (jsonScopes.Count > 0)
            {
                if (jsonScopes.Peek() is JsonObject)
                {
                    var currentGeoJson = (IDictionary <string, object>)geoJsonScopes.Dequeue();
                    var currentJson    = (JsonObject)jsonScopes.Dequeue();

                    foreach (var item in currentGeoJson)
                    {
                        if (!ignoreCrc || item.Key != "crs")
                        {
                            currentJson[item.Key] = convertScope(item.Value);
                        }
                    }
                }
                else
                {
                    var currentGeoJson = (IEnumerable <object>)geoJsonScopes.Dequeue();
                    var currentJson    = (List <object>)jsonScopes.Dequeue();

                    foreach (var item in currentGeoJson)
                    {
                        currentJson.Add(convertScope(item));
                    }
                }
            }
            json["__metadata"] = ReaderUtils.CreateEntryPropertyMetadata(GetTypeAttribute(container), false);
            return(json);
        }