public void Update(IGISFeature feature) { if (feature == null) { throw new ArgumentNullException("feature", "A valid feature is required to be added."); } if (_features == null) { throw new NullReferenceException("Cannot update feature to the InMemoryLayer. The internal list reference is NULL."); } if (FindByKeyValue(_features, feature.Attributes.GetValue(KeyFieldName)) != null) { throw new ArgumentException("Cannot update feature. A feature with the same key already exists."); } MemFeature updateFeature = FindByKeyValue(_features, feature.Attributes.GetValue(KeyFieldName)); if (updateFeature == null) { throw new ArgumentException("Could not update the InMemoryLayer. The feature was not found in the internal list."); } updateFeature.Shape = feature.Shape; foreach (string key in feature.Attributes.GetKeys()) { updateFeature.Attributes.SetValue(key, feature.Attributes.GetValue(key)); } }
public bool MoveNext() { if (_features == null || ++_index >= _features.Count) { return(false); } else { _current = _features[_index]; return(true); } }
/// <summary> /// Determines whether the specified feature is match. /// </summary> /// <param name="feature">The feature.</param> /// <returns> /// <c>true</c> if the specified feature is match; otherwise, <c>false</c>. /// </returns> public bool IsMatch(MemFeature feature) { int totalConditions = 0; int matchedConditions = 0; foreach (KeyValuePair <string, object> condition in _conditions) { totalConditions++; if (condition.Value == feature.Attributes.GetValue(condition.Key)) { matchedConditions++; break; } } return(totalConditions == matchedConditions); }
public void Delete(IGISFeature feature) { if (feature == null) { throw new ArgumentNullException("feature", "A valid feature is required to be added."); } if (_features == null) { throw new NullReferenceException("Cannot delete feature from the InMemoryLayer. The internal list reference is NULL."); } MemFeature mc = FindByKeyValue(_features, feature.Attributes.GetValue(KeyFieldName)); if (mc != null) { _features.Remove(mc); } }
public void FromXML(System.Xml.XmlReader reader) { _source = new List <MemFeature>(); reader.MoveToContent(); if (reader.IsStartElement("Layer")) { reader.ReadStartElement("Layer"); _layerName = reader.GetAttribute("Name"); _keyFieldName = reader.GetAttribute("KeyField"); while (reader.IsStartElement("Feature")) { MemFeature feature = CreateFeature(); feature.FromXML(reader); Add(feature); } reader.ReadEndElement(); } }
public void FromJSON(Jayrock.Json.JsonTextReader jreader) { if (jreader == null) { throw new ArgumentNullException("jreader", "A valid JSON reader object is required."); } if (jreader.MoveToContent() && jreader.TokenClass == JsonTokenClass.Object) { jreader.ReadToken(JsonTokenClass.Object); //Read the 'FeatureCollection' as the type jreader.ReadMember(); //reads 'type' jreader.ReadString(); //reads 'FeatureCollection' //Read the features jreader.ReadMember(); jreader.ReadToken(JsonTokenClass.Array); while (jreader.TokenClass == JsonTokenClass.Object) { MemFeature feature = CreateFeature(); GeoJSONReader.ReadGISFeature(feature, jreader); Add(feature); } jreader.ReadToken(JsonTokenClass.EndArray); //Read the layer name jreader.ReadMember(); _layerName = jreader.ReadString(); //Read the key field jreader.ReadMember(); _keyFieldName = jreader.ReadString(); jreader.ReadToken(JsonTokenClass.EndObject); } }