Example #1
0
        /// <summary>
        /// Writes a coordinate reference system to its JSON representation
        /// </summary>
        /// <param name="writer">The writer</param>
        /// <param name="value">The coordinate reference system</param>
        /// <param name="serializer">The serializer</param>
        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }
            if (serializer == null)
            {
                throw new ArgumentNullException("serializer");
            }

            ICRSObject crs = value as ICRSObject;

            if (crs == null)
            {
                writer.WriteToken(JsonToken.Null);
                return;
            }

            writer.WriteStartObject();
            writer.WritePropertyName("type");
            string type = Enum.GetName(typeof(CRSTypes), crs.Type);

            writer.WriteValue(type.ToLowerInvariant());
            CRSBase crsb = value as CRSBase;

            if (crsb != null)
            {
                writer.WritePropertyName("properties");
                serializer.Serialize(writer, crsb.Properties);
            }
            writer.WriteEndObject();
        }
        internal Feature GetFDirTraceAsync(Feature location, Feature mask)
        {
            CRSBase crs = null;

            try
            {
                crs = location.CRS as CRSBase;
                var body = getBody(location, crs.Properties["name"].ToString().Replace("EPSG:", ""), mask);

                JObject    requestResult = this.ExecuteAsync <JObject>(GetResourcrUrl(streamstatsservicetype.e_fdrtrace), new OverRideUrlEncodedContent(body), methodType.e_POST, contentType.JSON).Result;
                LineString result        = requestResult["results"][0].SelectToken("value.trace").ToObject <LineString>();

                Feature traceFeature = new Feature(result, new Dictionary <string, object> {
                    { "method", "streamstats flow direction trace" },
                    { "description", "traverses over flow direction raster to find downstream routing of neighboring cells, feature information/properties inherited from nhd catchment." },
                    { "nhdplus_comid", mask.Properties["featureid"] }
                });
                traceFeature.CRS = location.CRS;

                return(traceFeature);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new ArgumentException("Expected token '{' not found.");
            }
            reader.Read();
            if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "type"))
            {
                throw new ArgumentException("Expected token 'type' not found.");
            }
            reader.Read();
            if (reader.TokenType != JsonToken.String)
            {
                throw new ArgumentException("Expected string value not found.");
            }
            string crsType = (string)reader.Value;

            reader.Read();
            if (!(reader.TokenType == JsonToken.PropertyName && (string)reader.Value == "properties"))
            {
                throw new ArgumentException("Expected token 'properties' not found.");
            }
            reader.Read();
            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new ArgumentException("Expected token '{' not found.");
            }
            Dictionary <string, object> dictionary = serializer.Deserialize <Dictionary <string, object> >(reader);
            CRSBase result = null;

            switch (crsType)
            {
            case "link":
                object href = dictionary["href"];
                object type = dictionary["type"];
                result = new LinkedCRS((string)href, type != null ? (string)type : "");
                break;

            case "name":
                object name = dictionary["name"];
                result = new NamedCRS((string)name);
                break;
            }
            if (reader.TokenType != JsonToken.EndObject)
            {
                throw new ArgumentException("Expected token '}' not found.");
            }
            reader.Read();
            if (reader.TokenType != JsonToken.EndObject)
            {
                throw new ArgumentException("Expected token '}' not found.");
            }
            reader.Read();
            return(result);
        }
Example #4
0
 private void WriteCrs(CRSBase crs)
 {
     WritePropertyName("crs");
     WriteStartObject();
     WritePropertyName("properties");
     WriteStartObject();
     WritePropertyName("name");
     WriteValue(crs.Properties["name"]);
     WriteEndObject();
     WritePropertyName("type");
     WriteValue("Name");
     WriteEndObject();
 }
        /// <summary>
        /// Parses the CRS information.
        /// </summary>
        /// <param name="jsonObject">The json object.</param>
        /// <returns>A NamedCRS, LinkedCRS or Null.</returns>
        public static ICRSObject ParseCrs(JObject jsonObject)
        {
            if (jsonObject == null || !jsonObject.HasValues)
            {
                return(null);
            }

            JProperty typeProperty = jsonObject.Property("type");

            if (typeProperty != null)
            {
                string  type = typeProperty.Value.ToObjectOrDefault <string>().ToLower().Trim();
                CRSBase crs  = null;
                if (type == "name")
                {
                    crs = new NamedCRS();
                }
                else if (type == "link")
                {
                    crs = new LinkedCRS();
                }
                else if (type == "epsg")
                {
                    crs = new EPSGCRS();
                }
                else
                {
                    return(null);
                }

                if (jsonObject.Property("properties") != null)
                {
                    foreach (JToken jToken in jsonObject.Property("properties").Value)
                    {
                        var    item = (JProperty)jToken;
                        string key  = item.Name;
                        object val  = item.Value.ToObjectOrDefault <object>();
                        crs.Properties.Add(key, val);
                    }
                }

                if (crs.Properties.Count == 0)
                {
                    return(null);
                }

                return(crs);
            }

            return(null);
        }
Example #6
0
        public FeatureCollection GetLocalCatchmentAsync(Point location)
        {
            CRSBase crs = null;

            try
            {
                crs = location.CRS as CRSBase;

                var reqInfo       = GetRequestInfo(nldiservicetype.e_catchment, new object[] { crs.Properties["name"], location.Coordinates.Longitude, location.Coordinates.Latitude });
                var requestResult = this.ExecuteAsync <FeatureCollection>(reqInfo).Result;

                return(requestResult);
            }
            catch (Exception ex)
            {
                throw;
            }
        }