///<inheritdoc/> public (double SearchFactor, IconColorCategory IconColorCategory) GetInfo(IAttributesTable attributesTable) { if (attributesTable.GetNames().Any(k => k.Equals("place", StringComparison.OrdinalIgnoreCase))) { var category = attributesTable.GetNames().Any(k => k.StartsWith(FeatureAttributes.WIKIPEDIA)) ? Categories.WIKIPEDIA : Categories.NONE; return(1, new IconColorCategory("icon-home", category)); } var iconTags = _categories.SelectMany(c => c.Items) .FirstOrDefault(i => i.Tags .Any(t => attributesTable.Exists(t.Key) && attributesTable[t.Key].ToString() == t.Value)); if (iconTags != null) { return(1, iconTags.IconColorCategory); } if (attributesTable.GetNames().Any(k => k.StartsWith(FeatureAttributes.WIKIPEDIA))) { return(1, new IconColorCategory("icon-wikipedia-w", Categories.WIKIPEDIA)); } if (attributesTable.GetNames().Any(k => k.Equals("highway", StringComparison.OrdinalIgnoreCase))) { var icon = attributesTable["highway"].ToString() == "bus_stop" ? new IconColorCategory("icon-bus-stop") : new IconColorCategory("icon-map-signs"); return(_options.SearchFactor, icon); } return(_options.SearchFactor, new IconColorCategory()); }
/// <summary> /// Get an attribute by language, this is relevant to OSM attributes convetion /// </summary> /// <param name="attributes">The attributes table</param> /// <param name="key">The attribute name</param> /// <param name="language">The user interface language</param> /// <returns></returns> protected string GetAttributeByLanguage(IAttributesTable attributes, string key, string language) { if (attributes.GetNames().Contains(key + ":" + language)) { return(attributes[key + ":" + language].ToString()); } if (attributes.GetNames().Contains(key)) { return(attributes[key].ToString()); } return(string.Empty); }
/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (writer == null) { throw new ArgumentNullException("writer"); } IAttributesTable attributes = value as IAttributesTable; if (attributes == null) { writer.WriteNull(); return; } writer.WriteStartObject(); string[] names = attributes.GetNames(); foreach (string name in names) { // skip id if (name == "id") { continue; } writer.WritePropertyName(name); object val = attributes[name]; serializer.Serialize(writer, val); } writer.WriteEndObject(); }
/// <summary> /// Converts an NTS attributes table to an attributes collection. /// </summary> public static IAttributeCollection ToAttributesCollection(this IAttributesTable table) { if (table == null) { return(null); } var attributes = new AttributeCollection(); var name = table.GetNames(); var values = table.GetValues(); for (var i = 0; i < name.Length; i++) { var value = values[i]; if (value == null) { attributes.AddOrReplace(name[i], string.Empty); } else { attributes.AddOrReplace(name[i], value.ToInvariantString()); } } return(attributes); }
/// <summary> /// This is an extention method to attribute table to get the wikipedia page title by language /// </summary> /// <param name="attributes">The attributes table</param> /// <param name="language">The required language</param> /// <returns>The page title, empty if none exist</returns> public static string GetWikipediaTitle(this IAttributesTable attributes, string language) { if (!attributes.GetNames().Any(n => n.StartsWith(FeatureAttributes.WIKIPEDIA))) { return(string.Empty); } var wikiWithLanguage = FeatureAttributes.WIKIPEDIA + ":" + language; if (attributes.Exists(wikiWithLanguage)) { return(attributes[wikiWithLanguage].ToString()); } if (!attributes.Exists(FeatureAttributes.WIKIPEDIA)) { return(string.Empty); } var titleWithLanguage = attributes[FeatureAttributes.WIKIPEDIA].ToString(); var languagePrefix = language + ":"; if (titleWithLanguage.StartsWith(languagePrefix)) { return(titleWithLanguage.Substring(languagePrefix.Length)); } return(string.Empty); }
private static void AddAttributes(List <uint> tags, Dictionary <string, uint> keys, Dictionary <Tile.Value, uint> values, IAttributesTable attributes) { if (attributes == null || attributes.Count == 0) { return; } var aKeys = attributes.GetNames(); var aValues = attributes.GetValues(); for (var a = 0; a < aKeys.Length; a++) { var key = aKeys[a]; if (string.IsNullOrEmpty(key)) { continue; } var tileValue = ToTileValue(aValues[a]); if (tileValue == null) { continue; } tags.Add(keys.AddOrGet(key)); tags.Add(values.AddOrGet(tileValue)); } }
/// <summary> /// Writes the JSON representation of the object. /// </summary> /// <param name="writer">The <see cref="T:Newtonsoft.Json.JsonWriter"/> to write to.</param> /// <param name="value">The value.</param> /// <param name="serializer">The calling serializer.</param> public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) { if (writer == null) { throw new ArgumentNullException("writer"); } IAttributesTable attributes = value as IAttributesTable; if (attributes == null) { return; } writer.WritePropertyName("properties"); writer.WriteStartObject(); string[] names = attributes.GetNames(); foreach (string name in names) { writer.WritePropertyName(name); writer.WriteValue(attributes[name]); } writer.WriteEndObject(); }
public static void WritewithID(IAttributesTable attributes, JsonTextWriter jwriter) { if (attributes == null) { return; } if (jwriter == null) { throw new ArgumentNullException("jwriter", "A valid JSON writer object is required."); } jwriter.WriteStartObject(); string[] names = attributes.GetNames(); foreach (string name in names) { jwriter.WriteMember(name); var attr = attributes[name]; if (attr is IEnumerable <FeatureWithID> ) { IEnumerable <FeatureWithID> fcoll = (IEnumerable <FeatureWithID>)attr; WritewithID(fcoll, jwriter); } else { // TODO: Numerische Attribute? jwriter.WriteString(attributes[name] != null?attributes[name].ToString():""); } } jwriter.WriteEndObject(); }
private void CheckAttributes(IAttributesTable expected, IAttributesTable parsed) { Assert.Equal(expected.Count, parsed.Count); string[] expectedNames = expected.GetNames(); string[] parsedNames = expected.GetNames(); for (int i = 0; i < expectedNames.Length; i++) { Assert.Equal(expectedNames[i], parsedNames[i]); if (expectedNames[i] != UID) { Assert.Equal(expected[expectedNames[i]], parsed[parsedNames[i]]); } else { Assert.Equal((ulong)(uint)expected[expectedNames[i]], parsed[parsedNames[i]]); } } }
/// <summary> /// Returns true if the given table contains the given attribute with the given value. /// </summary> public static bool Contains(this IAttributesTable table, string name, object value) { var names = table.GetNames(); for (var i = 0; i < names.Length; i++) { if (names[i] == name) { return(value.Equals(table.GetValues()[i])); } } return(false); }
private LogEventPropertyValue WriteAttributes(ILogEventPropertyValueFactory propertyValueFactory, IAttributesTable value) { var props = new List <LogEventProperty>(); foreach (var propertyName in value.GetNames()) { // skip id if (propertyName != _idPropertyName) { props.Add(new LogEventProperty(propertyName, propertyValueFactory.CreatePropertyValue(value[propertyName], true))); } } return(new StructureValue(props)); }
/// <summary> /// Tries to get a value from the attribute table. /// </summary> public static bool TryGetValue(this IAttributesTable table, string name, out object value) { var names = table.GetNames(); for (var i = 0; i < names.Length; i++) { if (names[i] == name) { value = table.GetValues()[i]; return(true); } } value = null; return(false); }
///<inheritdoc/> public (double SearchFactor, IconColorCategory IconColorCategory) GetInfo(IAttributesTable attributesTable) { if (attributesTable.GetNames().Any(k => k.Equals("place", StringComparison.OrdinalIgnoreCase))) { return(1, new IconColorCategory("icon-home")); } var iconTags = _iconsToTags.Values.FirstOrDefault(i => i.Tags.FirstOrDefault( t => attributesTable.Exists(t.Key) && attributesTable[t.Key].ToString() == t.Value) .Equals(default(KeyValuePair <string, string>)) == false); if (iconTags != null) { return(1, iconTags.IconColorCategory); } if (attributesTable.GetNames().Any(k => k.Equals("highway", StringComparison.OrdinalIgnoreCase))) { var icon = attributesTable["highway"].ToString() == "bus_stop" ? new IconColorCategory("icon-bus-stop") : new IconColorCategory("icon-map-signs"); return(_options.SearchFactor, icon); } return(_options.SearchFactor, new IconColorCategory()); }
public static string CreateTableColumns(IAttributesTable columnAttributes, DbaseFieldDescriptor[] fieldsInformation) { string[] tableColumns = columnAttributes.GetNames(); string columnInformation = ""; for (int i = 0; i < tableColumns.Length; i++) { columnInformation += tableColumns[i] + " " + SetSqlDataType(fieldsInformation[i].Length, fieldsInformation[i].DecimalCount, fieldsInformation[i].DbaseType) + ", "; } columnInformation = columnInformation.TrimEnd(',', ' '); string createTableString = "CREATE TABLE TestTable ( OBJECTID_1 int IDENTITY (1,1) PRIMARY KEY, Shape geometry, " + columnInformation + "); "; return(createTableString); }
/// <summary> /// Method to merge this attribute table with another attribute table /// </summary> /// <param name="other">The other attribute table</param> /// <param name="preferThis">A value indicating if values in this attribute table are preferable /// over those in <paramref name="other"/>. The default is <value>true</value>. /// </param> public void MergeWith(IAttributesTable other, bool preferThis = true) { foreach (var name in other.GetNames()) { if (!Exists(name)) { Add(name, other[name]); } else { if (!preferThis) { this[name] = other[name]; } } } }
/// <summary> /// Returns the first element that satisfies the given predicate or throw an exception with the given message if nothing is found. /// </summary> public static object FirstOrException(this IAttributesTable attributes, Func <string, bool> isFirst, string message) { if (attributes == null) { throw new ArgumentNullException("attributes"); } var names = attributes.GetNames(); for (var i = 0; i < names.Length; i++) { if (isFirst(names[i])) { return(attributes.GetValues()[i]); } } throw new Exception(message); }
/// <summary> /// Gets the stub header. /// </summary> /// <param name="feature">The feature.</param> /// <param name="count">The count.</param> /// <returns></returns> public static DbaseFileHeader GetHeader(IFeature feature, int count) { IAttributesTable attribs = feature.Attributes; string[] names = attribs.GetNames(); DbaseFileHeader header = new DbaseFileHeader(); header.NumRecords = count; foreach (string name in names) { Type type = attribs.GetType(name); if (type == typeof(double) || type == typeof(float)) { header.AddColumn(name, 'N', DoubleLength, DoubleDecimals); } else if (type == typeof(short) || type == typeof(ushort) || type == typeof(int) || type == typeof(uint)) { header.AddColumn(name, 'N', IntLength, IntDecimals); } else if (type == typeof(long) || type == typeof(ulong)) { header.AddColumn(name, 'N', LongLength, IntDecimals); } else if (type == typeof(string)) { header.AddColumn(name, 'C', StringLength, StringDecimals); } else if (type == typeof(bool)) { header.AddColumn(name, 'L', BoolLength, BoolDecimals); } else if (type == typeof(DateTime)) { header.AddColumn(name, 'D', DateLength, DateDecimals); } else { throw new ArgumentException("Type " + type.Name + " not supported"); } } return(header); }
private static void AddAttributes(List <uint> tags, Dictionary <string, uint> keys, Dictionary <string, uint> values, IAttributesTable attributes) { if (attributes == null) { return; } var aKeys = attributes.GetNames(); var aValues = attributes.GetValues(); for (var a = 0; a < aKeys.Length; a++) { var key = aKeys[a]; var value = aValues[a]; tags.Add(keys.AddOrGet(key)); tags.Add(values.AddOrGet(value?.ToString())); } }
/// <summary> /// Tries to get the value for the given key. /// </summary> public static bool TryGetValue(this IAttributesTable attributes, string key, out object value) { if (attributes == null) { throw new ArgumentNullException("attributes"); } var names = attributes.GetNames(); for (var i = 0; i < names.Length; i++) { if (names[i].Equals(key)) { value = attributes.GetValues()[i]; return(true); } } value = null; return(false); }
/// <summary> /// Returns true if the attribute table contains the given attribute and it's value. /// </summary> public static bool Contains(this IAttributesTable attributes, string key, object value) { if (attributes == null) { throw new ArgumentNullException("attributes"); } var names = attributes.GetNames(); for (var i = 0; i < names.Length; i++) { if (names[i].Equals(key)) { if (attributes.GetValues()[i] != null) { return(attributes.GetValues()[i].ToInvariantString().Equals(value)); } } } return(false); }
public static void Write(IAttributesTable attributes, JsonTextWriter jwriter) { if (attributes == null) { return; } if (jwriter == null) { throw new ArgumentNullException("jwriter", "A valid JSON writer object is required."); } jwriter.WriteStartObject(); string[] names = attributes.GetNames(); foreach (string name in names) { jwriter.WriteMember(name); jwriter.WriteString(attributes[name].ToString()); } jwriter.WriteEndObject(); }
/// <summary> /// Tries to get a value as a string from the attribute table. /// </summary> public static bool TryGetValueAsString(this IAttributesTable table, string name, out string value) { var names = table.GetNames(); for (var i = 0; i < names.Length; i++) { if (names[i] == name) { var objValue = table.GetValues()[i]; if (objValue == null) { value = null; } else { value = objValue.ToInvariantString(); } return(true); } } value = null; return(false); }
private static IEnumerable <KeyValuePair <string, object> > AttributesTableToDictionary(IAttributesTable attributesTable) { foreach (var attributeName in attributesTable.GetNames()) { var attributeValue = attributesTable[attributeName]; if (attributeName.ToLower() == "id") { continue; } if (attributeValue == null) { continue; } if (attributeValue is IAttributesTable) { continue; } attributeValue = attributeValue is string valuestr?valuestr.Trim() : attributeValue; yield return(new KeyValuePair <string, object>(attributeName, attributeValue)); } }
private static PropertiesData FindPropertiesData(IAttributesTable attributesTable, List<PropertiesData> priorityData) { return attributesTable.GetNames().Select(key => priorityData.FirstOrDefault(p => { if (key.Equals(p.Key, StringComparison.InvariantCultureIgnoreCase) == false) { return false; } return p.IsAnyValue || attributesTable[key].ToString().Equals(p.Value, StringComparison.CurrentCultureIgnoreCase); })).FirstOrDefault(data => data != null); }
public static void Write(IAttributesTable attributes, JsonTextWriter jwriter) { if (attributes == null) return; if (jwriter == null) throw new ArgumentNullException("jwriter", "A valid JSON writer object is required."); jwriter.WriteStartObject(); string[] names = attributes.GetNames(); foreach (string name in names) { jwriter.WriteMember(name); jwriter.WriteString(attributes[name].ToString()); } jwriter.WriteEndObject(); }