Esempio n. 1
0
 private static JsonObject ReadExtensionAttribute(XAttribute attribute)
 {
     return(ReaderUtils.CreateExtension(attribute.Name.LocalName, attribute.BaseUri, attribute.Value));
 }
Esempio n. 2
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);
        }
Esempio n. 3
0
 private static JsonObject ReadExtension(KeyValuePair <XmlQualifiedName, string> pair)
 {
     return(ReaderUtils.CreateExtension(pair.Key.Name, pair.Key.Namespace, pair.Value));
 }