Beispiel #1
0
 public static void AddOrUpdate(this IAttributesTable attributes, string key, object value)
 {
     if (!attributes.Exists(key))
     {
         attributes.AddAttribute(key, value);
     }
     else
     {
         attributes[key] = value;
     }
 }
Beispiel #2
0
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>
        /// The object value.
        /// </returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            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 && (string)reader.Value != "Feature")
            {
                throw new ArgumentException("Expected value 'Feature' not found.");
            }
            reader.Read();

            object  featureId = null;
            Feature feature   = new Feature();

            while (reader.TokenType == JsonToken.PropertyName)
            {
                string prop = (string)reader.Value;
                switch (prop)
                {
                case "id":
                    reader.Read();
                    featureId = reader.Value;
                    reader.Read();
                    break;

                case "bbox":
                    // Read, but can't do anything with it, assigning Envelopes is impossible without reflection
                    var bbox = serializer.Deserialize <Envelope>(reader);
                    //Debug.WriteLine("BBOX: {0}", bbox.ToString());
                    break;

                case "geometry":
                    reader.Read();
                    if (reader.TokenType == JsonToken.Null)
                    {
                        reader.Read();
                        break;
                    }

                    if (reader.TokenType != JsonToken.StartObject)
                    {
                        throw new ArgumentException("Expected token '{' not found.");
                    }
                    var geometry = serializer.Deserialize <IGeometry>(reader);
                    feature.Geometry = geometry;
                    if (reader.TokenType != JsonToken.EndObject)
                    {
                        throw new ArgumentException("Expected token '}' not found.");
                    }
                    reader.Read();
                    break;

                case "properties":
                    feature.Attributes = serializer.Deserialize <AttributesTable>(reader);
                    break;

                default:
                {
                    reader.Read();     // move next
                    // jump to next property
                    while (reader.TokenType != JsonToken.PropertyName)
                    {
                        reader.Read();
                    }
                    break;
                    //string err = String.Format("token unhandled: {0}.", prop);
                    //throw new ArgumentException(err);
                }
                }
            }

            if (reader.TokenType != JsonToken.EndObject)
            {
                throw new ArgumentException("Expected token '}' not found.");
            }
            reader.Read(); // move next

            IAttributesTable attributes = feature.Attributes;

            if (attributes != null)
            {
                if (featureId != null && !attributes.Exists("id"))
                {
                    attributes.AddAttribute("id", featureId);
                }
            }
            return(feature);
        }
        /// <summary>
        /// Reads the JSON representation of the object.
        /// </summary>
        /// <param name="reader">The <see cref="T:Newtonsoft.Json.JsonReader"/> to read from.</param>
        /// <param name="objectType">Type of the object.</param>
        /// <param name="existingValue">The existing value of object being read.</param>
        /// <param name="serializer">The calling serializer.</param>
        /// <returns>
        /// The object value.
        /// </returns>
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new JsonReaderException("Expected Start object '{' Token");
            }

            bool    read      = reader.Read();
            object  featureId = null;
            Feature feature   = new Feature();

            while (reader.TokenType == JsonToken.PropertyName)
            {
                string prop = (string)reader.Value;
                switch (prop)
                {
                case "type":
                    read = reader.Read();
                    if ((string)reader.Value != "Feature")
                    {
                        throw new ArgumentException("Expected value 'Feature' not found.");
                    }
                    read = reader.Read();
                    break;

                case "id":
                    read      = reader.Read();
                    featureId = reader.Value;
                    read      = reader.Read();
                    break;

                case "bbox":
                    // Read, but can't do anything with it, assigning Envelopes is impossible without reflection
                    Envelope bbox = serializer.Deserialize <Envelope>(reader);
                    feature.BoundingBox = bbox;
                    //Debug.WriteLine("BBOX: {0}", bbox.ToString());
                    break;

                case "geometry":
                    read = reader.Read();
                    if (reader.TokenType == JsonToken.Null)
                    {
                        read = reader.Read();
                        break;
                    }

                    if (reader.TokenType != JsonToken.StartObject)
                    {
                        throw new ArgumentException("Expected token '{' not found.");
                    }
                    IGeometry geometry = serializer.Deserialize <IGeometry>(reader);
                    feature.Geometry = geometry;
                    if (reader.TokenType != JsonToken.EndObject)
                    {
                        throw new ArgumentException("Expected token '}' not found.");
                    }
                    read = reader.Read();
                    break;

                case "properties":
                    read = reader.Read();
                    if (reader.TokenType != JsonToken.Null)
                    {
                        // #120: ensure "properties" isn't "null"
                        if (reader.TokenType != JsonToken.StartObject)
                        {
                            throw new ArgumentException("Expected token '{' not found.");
                        }
                        feature.Attributes = serializer.Deserialize <AttributesTable>(reader);
                        if (reader.TokenType != JsonToken.EndObject)
                        {
                            throw new ArgumentException("Expected token '}' not found.");
                        }
                    }
                    read = reader.Read();
                    break;

                default:
                    read = reader.Read();     // move next
                    // jump to next property
                    while (read && reader.TokenType != JsonToken.PropertyName)
                    {
                        read = reader.Read();
                    }
                    break;
                }
            }

            if (read && reader.TokenType != JsonToken.EndObject)
            {
                throw new ArgumentException("Expected token '}' not found.");
            }

            //read = reader.Read(); // move next

            IAttributesTable attributes = feature.Attributes;

            if (attributes != null)
            {
                if (featureId != null && !attributes.Exists("id"))
                {
                    attributes.AddAttribute("id", featureId);
                }
            }
            return(feature);
        }
Beispiel #4
0
        private IAttributesTable writeBaseTroittoir(IAttributesTable attributes, ZustandsabschnittGIS zab)
        {
            attributes.AddAttribute(TrottoirShapeFileConstants.StrassenabschnittID, this.guidToOracleRaw(zab.StrassenabschnittGIS.Id));
            attributes.AddAttribute(TrottoirShapeFileConstants.Strassenname, zab.StrassenabschnittGIS.Strassenname);
            attributes.AddAttribute(TrottoirShapeFileConstants.StrassenabschnittBezeichnungvon, zab.StrassenabschnittGIS.BezeichnungVon != null ? zab.StrassenabschnittGIS.BezeichnungVon : string.Empty);
            attributes.AddAttribute(TrottoirShapeFileConstants.StrassenabschnittBezeichnungbis, zab.StrassenabschnittGIS.BezeichnungBis != null ? zab.StrassenabschnittGIS.BezeichnungBis : string.Empty);
            attributes.AddAttribute(TrottoirShapeFileConstants.Eigentuemer, StrabShapeFileConstants.getOwner(zab.StrassenabschnittGIS.Strasseneigentuemer));
            attributes.AddAttribute(TrottoirShapeFileConstants.Ortsbezeichnung, zab.StrassenabschnittGIS.Ortsbezeichnung != null ? zab.StrassenabschnittGIS.Ortsbezeichnung : string.Empty);

            attributes.AddAttribute(TrottoirShapeFileConstants.ID, this.guidToOracleRaw(Guid.NewGuid()));
            attributes.AddAttribute(TrottoirShapeFileConstants.ZustandsAbschnittID, this.guidToOracleRaw(zab.Id));
            attributes.AddAttribute(TrottoirShapeFileConstants.Bezeichnungvon, zab.BezeichnungVon != null ? zab.BezeichnungVon : string.Empty);
            attributes.AddAttribute(TrottoirShapeFileConstants.Bezeichnungbis, zab.BezeichnungBis != null ? zab.BezeichnungBis : string.Empty);
            attributes.AddAttribute(TrottoirShapeFileConstants.Laenge, (double)zab.Laenge);
            attributes.AddAttribute(TrottoirShapeFileConstants.Aufnahmedatum, zab.Aufnahmedatum);
            attributes.AddAttribute(TrottoirShapeFileConstants.Aufnahmeteam, zab.Aufnahmeteam != null ? zab.Aufnahmeteam : string.Empty);
            return(attributes);
        }