/// <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); }
public void ReadJsonWithArrayWithTwoObjectsTest() { const string json = "{\"test1\":\"value1\",\"test2\": [{ \"innertest1\":\"innervalue1\" }, { \"innertest2\":\"innervalue2\", \"innertest3\":\"innervalue3\"}]}}"; AttributesTableConverter target = new AttributesTableConverter(); using (JsonTextReader reader = new JsonTextReader(new StringReader(json))) { JsonSerializer serializer = new JsonSerializer(); // read start object token and prepare the next token reader.Read(); AttributesTable result = (AttributesTable) target.ReadJson(reader, typeof(AttributesTable), new AttributesTable(), serializer); Assert.IsNotNull(result); Assert.AreEqual(2, result.Count); Assert.AreEqual("value1", result["test1"]); Assert.IsNotNull(result["test2"]); Assert.IsInstanceOf <IList <object> >(result["test2"]); IList <object> list = (IList <object>)result["test2"]; Assert.IsNotEmpty(list); Assert.AreEqual(2, list.Count); Assert.IsInstanceOf <IAttributesTable>(list[0]); Assert.IsInstanceOf <IAttributesTable>(list[1]); IAttributesTable first = (IAttributesTable)list[0]; Assert.AreEqual(1, first.Count); Assert.AreEqual("innervalue1", first["innertest1"]); IAttributesTable second = (IAttributesTable)list[1]; Assert.AreEqual(2, second.Count); Assert.AreEqual("innervalue2", second["innertest2"]); Assert.AreEqual("innervalue3", second["innertest3"]); } }
///<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()); }
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(); }
/// <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> /// /// </summary> /// <param name="geometry"></param> /// <param name="attributes"></param> public FeatureWithID(IGeometry geometry, IAttributesTable attributes, string id) : this() { this.geometry = geometry; this.attributes = attributes; this.id = id; }
public static IAttributesTable ReadAttributesTable(JsonTextReader jreader) { if (jreader == null) { throw new ArgumentNullException("jreader", "A valid JSON reader object is required."); } IAttributesTable attributes = null; if (jreader.MoveToContent() && jreader.TokenClass == JsonTokenClass.Object) { attributes = new AttributesTable(); jreader.ReadToken(JsonTokenClass.Object); while (jreader.TokenClass == JsonTokenClass.Member) { string key = jreader.ReadMember(); string value = jreader.ReadString(); if (!attributes.Exists(key)) { attributes.AddAttribute(key, null); } attributes[key] = value; } jreader.ReadToken(JsonTokenClass.EndObject); } 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); }
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(); }
public void ReadByGeoFilter_ReadDbfDataAfterReaderObjectDisposed_ShouldThrowException() { Envelope boundsWithWholeTriangle = new Envelope(-1.17459, -1.00231, -1.09803, -0.80861); // Arrange. m_TempFiles = new TempFileWriter[] { new TempFileWriter(".shp", ShpFiles.Read("UnifiedChecksMaterial")), new TempFileWriter(".dbf", DbfFiles.Read("UnifiedChecksMaterial")), }; m_shapeDataReader = new ShapeDataReader(m_TempFiles[0].Path); // Act. IEnumerable <IShapefileFeature> results = m_shapeDataReader.ReadByMBRFilter(boundsWithWholeTriangle); // Assert. Assert.IsNotNull(results); IShapefileFeature result = results.Single(); // Dispose of the reader object. m_shapeDataReader.Dispose(); // Try reading dbf data. Assert.Catch <InvalidOperationException>(() => { IAttributesTable table = result.Attributes; }); }
public void ReadJsonWithInnerObjectTest() { const string json = "{\"properties\":{\"test1\":\"value1\",\"test2\": { \"innertest1\":\"innervalue1\" }}}"; AttributesTableConverter target = new AttributesTableConverter(); using (JsonTextReader reader = new JsonTextReader(new StringReader(json))) { JsonSerializer serializer = new JsonSerializer(); // read start object token and prepare the next token reader.Read(); reader.Read(); AttributesTable result = (AttributesTable) target.ReadJson(reader, typeof(AttributesTable), new AttributesTable(), serializer); Assert.IsFalse(reader.Read()); // read the end of object and ensure there are no more tokens available Assert.IsNotNull(result); Assert.AreEqual(2, result.Count); Assert.AreEqual("value1", result["test1"]); Assert.IsNotNull(result["test2"]); Assert.IsInstanceOf <IAttributesTable>(result["test2"]); IAttributesTable inner = (IAttributesTable)result["test2"]; Assert.AreEqual(1, inner.Count); Assert.AreEqual("innervalue1", inner["innertest1"]); } }
public static IFeature FromByteBuffer(ByteBuffer bb, GeometryType geometryType, byte dimensions, IList <ColumnMeta> columns = null) { var feature = Feature.GetRootAsFeature(bb); IAttributesTable attributesTable = null; var propertiesArray = feature.GetPropertiesArray(); if (propertiesArray != null && propertiesArray.Length > 0) { var memoryStream = new MemoryStream(propertiesArray); var reader = new BinaryReader(memoryStream); attributesTable = new AttributesTable(); while (memoryStream.Position < memoryStream.Length) { ushort i = reader.ReadUInt16(); var column = columns[i]; var type = column.Type; var name = column.Name; switch (type) { case ColumnType.Bool: attributesTable.AddAttribute(name, reader.ReadBoolean()); break; case ColumnType.Int: attributesTable.AddAttribute(name, reader.ReadInt32()); break; case ColumnType.Long: attributesTable.AddAttribute(name, reader.ReadInt64()); break; case ColumnType.Double: attributesTable.AddAttribute(name, reader.ReadDouble()); break; case ColumnType.String: int len = reader.ReadInt32(); var str = Encoding.UTF8.GetString(memoryStream.ToArray(), (int)memoryStream.Position, len); memoryStream.Position += len; attributesTable.AddAttribute(name, str); break; default: throw new ApplicationException("Unknown type"); } } } IGeometry geometry = null; if (feature.Geometry.HasValue) { geometry = GeometryConversions.FromFlatbuf(feature.Geometry.Value, geometryType); } var f = new NetTopologySuite.Features.Feature(geometry, attributesTable); return(f); }
/// <summary> /// Attempts to convert this table to a strongly-typed value, if the table came from this /// library. /// <para> /// This is essentially just a way of calling /// <see cref="JsonSerializer.Deserialize{TValue}(ref Utf8JsonReader, JsonSerializerOptions)"/> /// on a Feature's <c>"properties"</c> object. /// </para> /// <para> /// <c>System.Text.Json</c> intentionally omits the functionality that would let us do this /// automatically, for security reasons, so this is the workaround for now. /// </para> /// <para> /// This will always return <see langword="false"/> for tables that were not created by the /// converters that this library adds via <see cref="GeoJsonConverterFactory"/>. /// </para> /// </summary> /// <typeparam name="T"> /// The type of object to convert to. /// </typeparam> /// <param name="table"> /// This table. /// </param> /// <param name="options"> /// The <see cref="JsonSerializerOptions"/> to use for the deserialization. /// </param> /// <param name="deserialized"> /// Receives the converted value on success, or the default value on failure. /// </param> /// <returns> /// A value indicating whether or not the conversion succeeded. /// </returns> public static bool TryDeserializeJsonObject <T>(this IAttributesTable table, JsonSerializerOptions options, out T deserialized) { if (!(table is StjAttributesTable ourAttributesTable)) { deserialized = default; return(false); } return(TryDeserializeElement(ourAttributesTable.RootElement, options, out deserialized)); }
public static void AddOrUpdate(this IAttributesTable attributes, string key, object value) { if (!attributes.Exists(key)) { attributes.Add(key, value); } else { attributes[key] = value; } }
public void ReadEntry_ReadNonExistantKeyFromEntry_ShoudReturnCorrectValues() { // Arrange m_TmpFile = new TempFileWriter("data.dbf", DbfFiles.Read("point_ed50_geo")); m_Reader = new DbaseReader(m_TmpFile.Path); IAttributesTable results = m_Reader.ReadEntry(0); // Act. object a = results["a"]; }
/// <summary> /// Attempts to get a strongly-typed value for that corresponds to a property of this table, /// if the table came from this library. /// <para> /// This is essentially just a way of calling /// <see cref="JsonSerializer.Deserialize{TValue}(ref Utf8JsonReader, JsonSerializerOptions)"/> /// on one of the individual items from a Feature's <c>"properties"</c>. /// </para> /// <para> /// <c>System.Text.Json</c> intentionally omits the functionality that would let us do this /// automatically, for security reasons, so this is the workaround for now. /// </para> /// <para> /// This will always return <see langword="false"/> for tables that were not created by the /// converters that this library adds via <see cref="GeoJsonConverterFactory"/>. /// </para> /// </summary> /// <typeparam name="T"> /// The type of object to retrieve. /// </typeparam> /// <param name="table"> /// This table. /// </param> /// <param name="propertyName"> /// The name of the property in this table to get as the specified type. /// </param> /// <param name="options"> /// The <see cref="JsonSerializerOptions"/> to use for the deserialization. /// </param> /// <param name="deserialized"> /// Receives the converted value on success, or the default value on failure. /// </param> /// <returns> /// A value indicating whether or not the conversion succeeded. /// </returns> public static bool TryGetJsonObjectPropertyValue <T>(this IAttributesTable table, string propertyName, JsonSerializerOptions options, out T deserialized) { if (!(table is StjAttributesTable ourAttributesTable && ourAttributesTable.RootElement.TryGetProperty(propertyName, out var elementToTransform))) { deserialized = default; return(false); } return(TryDeserializeElement(elementToTransform, options, out deserialized)); }
private static void ValidateData(IDictionary <string, FeatureCollection> coll) { Assert.That(coll, Is.Not.Null); Assert.That(coll, Is.Not.Empty); Assert.That(coll.Keys, Is.Not.Empty); Assert.That(coll.Keys.Count, Is.EqualTo(1)); Assert.That(coll.ContainsKey("example"), Is.True); FeatureCollection fc = coll["example"]; Assert.That(fc, Is.Not.Null); Assert.That(fc.Count, Is.EqualTo(3)); IFeature f1 = fc[0]; Assert.That(f1, Is.Not.Null); Assert.That(f1.Geometry, Is.Not.Null); Assert.That(f1.Geometry.Factory, Is.EqualTo(Factory)); Assert.That(f1.Geometry, Is.InstanceOf <IPoint>()); Assert.That(f1.Geometry.AsText(), Is.EqualTo("POINT (102 0.5)")); Assert.That(f1.Attributes, Is.Not.Null); Assert.That(f1.Attributes.Count, Is.EqualTo(1)); Assert.That(f1.Attributes.Exists("prop0"), Is.True); Assert.That(f1.Attributes["prop0"], Is.EqualTo("value0")); IFeature f2 = fc[1]; Assert.That(f2, Is.Not.Null); Assert.That(f2.Geometry, Is.Not.Null); Assert.That(f2.Geometry.Factory, Is.EqualTo(Factory)); Assert.That(f2.Geometry, Is.InstanceOf <ILineString>()); Assert.That(f2.Geometry.AsText(), Is.EqualTo("LINESTRING (102 0, 103 1, 104 0, 105 1)")); Assert.That(f2.Attributes, Is.Not.Null); Assert.That(f2.Attributes.Count, Is.EqualTo(0)); IFeature f3 = fc[2]; Assert.That(f3, Is.Not.Null); Assert.That(f3.Geometry, Is.Not.Null); Assert.That(f3.Geometry.Factory, Is.EqualTo(Factory)); Assert.That(f3.Geometry, Is.InstanceOf <IPolygon>()); Assert.That(f3.Geometry.AsText(), Is.EqualTo("POLYGON ((100 0, 100 1, 101 1, 101 0, 100 0))")); Assert.That(f3.Attributes, Is.Not.Null); Assert.That(f3.Attributes.Count, Is.EqualTo(2)); Assert.That(f3.Attributes.Exists("prop0"), Is.True); Assert.That(f3.Attributes["prop0"], Is.EqualTo("value0")); Assert.That(f3.Attributes.Exists("prop1"), Is.True); Assert.That(f3.Attributes["prop1"], Is.InstanceOf <IAttributesTable>()); IAttributesTable inner = (IAttributesTable)f3.Attributes["prop1"]; Assert.That(inner.Count, Is.EqualTo(1)); Assert.That(inner.Exists("this"), Is.True); Assert.That(inner["this"], Is.EqualTo("that")); }
public static object GetOptionalValue(this IAttributesTable attributes, string attributeName) { object result = null; if (attributes.Exists(attributeName)) { result = attributes[attributeName]; } return(result); }
/// <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); }
public RoundTripBase() { LayerName = "water"; FeatureProperties = new AttributesTable(new[] { new KeyValuePair <string, object>(UID, 123U), new KeyValuePair <string, object>("foo", "bar"), new KeyValuePair <string, object>("baz", "foo"), }); FeatureGeometry = Reader.Read("POLYGON ((0 0, 0 1, 1 1, 1 0, 0 0))"); }
/// <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> public static string GetByLanguage(this IAttributesTable attributes, string key, string language) { if (attributes.Exists(key + ":" + language)) { return(attributes[key + ":" + language].ToString()); } if (attributes.Exists(key)) { return(attributes[key].ToString()); } return(string.Empty); }
/// <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); }
/// <summary> /// Writes the specified feature collection. /// </summary> /// <param name="featureCollection">The feature collection.</param> public virtual void Write(IList featureCollection) { // Test if the Header is initialized if (Header == null) { throw new ApplicationException("Header must be set first!"); } // Test if all elements of the collections are features foreach (object obj in featureCollection) { if (obj.GetType() != typeof(Feature)) { throw new ArgumentException("All the elements in the given collection must be " + typeof(Feature).Name); } } try { // Write shp and shx Geometry[] geometries = new Geometry[featureCollection.Count]; int index = 0; foreach (Feature feature in featureCollection) { geometries[index++] = feature.Geometry; } shapeWriter.Write(shpFile, new GeometryCollection(geometries, geometryFactory)); // Write dbf dbaseWriter.Write(Header); foreach (Feature feature in featureCollection) { IAttributesTable attribs = feature.Attributes; ArrayList values = new ArrayList(); for (int i = 0; i < Header.NumFields; i++) { values.Add(attribs[Header.Fields[i].Name]); } dbaseWriter.Write(values); } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } finally { // Close dbf writer dbaseWriter.Close(); } }
public void ReadEntry_ReadNonExistantKeyFromEntry_ShoudReturnCorrectValues() { // Arrange m_TmpFile = new TempFileWriter(".dbf", DbfFiles.Read("point_ed50_geo")); m_Reader = new DbaseReader(m_TmpFile.Path); IAttributesTable results = m_Reader.ReadEntry(0); // Act. Assert.Catch <ArgumentException>(() => { object a = results["a"]; }); }
public static void Write(IAttributesTable attributes, TextWriter writer) { if (attributes == null) { return; } if (writer == null) { throw new ArgumentNullException("writer", "A valid text writer object is required."); } JsonTextWriter jwriter = new JsonTextWriter(writer); Write(attributes, jwriter); }
/// <summary> /// Returns true if this table contains the given attribute and value. /// </summary> public static bool Contains(this IAttributesTable table, string attribute, object value) { if (!table.Exists(attribute)) { return(false); } var existing = table[attribute]; if (existing == null && value == null) { return(true); } return(existing.Equals(value)); }
/// <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); }
public TopoBuilder(string type, long id, IAttributesTable properties, double[][] coordinates, int[][][] arcs, TopoObject[] geometries) { if (String.IsNullOrEmpty(type)) throw new ArgumentNullException("type", "type null"); _type = type; _id = id; _properties = properties ?? new AttributesTable(); _coordinates = coordinates; _arcs = arcs; _geometries = geometries; }
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> /// /// </summary> /// <param name="geometry"></param> /// <param name="attributes"></param> public NTSFeature(Geometry geometry, IAttributesTable attributes) : this() { this.geometry = geometry; this.attributes = attributes; }
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 void ReadEntry_ReadEntryValues_ShoudReturnCorrectValues() { // Arrange m_TmpFile = new TempFileWriter("data.dbf", DbfFiles.Read("point_ed50_geo")); m_Reader = new DbaseReader(m_TmpFile.Path); var expectedTable = new { Ids = new double[] { 3, 2, 1 }, Strings = new string[] { "str3", "str2", "str1" }, WholeNums = new double[] { 3, 2, 1 }, DecNums = new double[] { 3, 2, 1 }, }; // Act. IAttributesTable[] results = new IAttributesTable[] { m_Reader.ReadEntry(0), m_Reader.ReadEntry(1), m_Reader.ReadEntry(2) }; // Assert. int currResIndex = 0; foreach (IAttributesTable res in results) { object id = res["id"]; object str = res["str"]; object wholeNum = res["wholeNum"]; object decNum = res["decNum"]; object date = res["dt"]; Assert.IsNotNull(id); Assert.IsNotNull(str); Assert.IsNotNull(wholeNum); Assert.IsNotNull(decNum); Assert.IsNotNull(date); Assert.IsInstanceOf<double>(id); Assert.IsInstanceOf<string>(str); Assert.IsInstanceOf<double>(wholeNum); Assert.IsInstanceOf<double>(decNum); Assert.IsInstanceOf<DateTime>(date); Assert.AreEqual(id, expectedTable.Ids[currResIndex]); Assert.AreEqual(str, expectedTable.Strings[currResIndex]); Assert.AreEqual(wholeNum, expectedTable.WholeNums[currResIndex]); Assert.AreEqual(decNum, expectedTable.DecNums[currResIndex]); Assert.AreEqual(date, DATE_SAVED_IN_DBF); currResIndex++; } }
/// <summary> /// /// </summary> /// <param name="geometry"></param> /// <param name="attributes"></param> public Feature(IGeometry geometry, IAttributesTable attributes) : this() { _geometry = geometry; _attributes = attributes; }
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(); }
public static void Write(IAttributesTable attributes, TextWriter writer) { if (attributes == null) return; if (writer == null) throw new ArgumentNullException("writer", "A valid text writer object is required."); JsonTextWriter jwriter = new JsonTextWriter(writer); Write(attributes, jwriter); }