public Feature CreateZustandsabschnittFeature(ZustandsabschnittGIS zustandsabschnitt, Guid inspektionsrouteid) { Feature zaFeature = new Feature(); IAttributesTable zaAttributes = new AttributesTable(); zaFeature.Geometry = zustandsabschnitt.Shape; //ID zaAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.ZustandsabschnittID), zustandsabschnitt.Id.ToString()); //StrassenabschnittID zaAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.StrassenabschnittGISID), zustandsabschnitt.StrassenabschnittGIS.Id.ToString()); //inspektionsRouteID zaAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.InspektionsRouteID), inspektionsrouteid.ToString()); //Zustandsindex //zaAttributes.AddAttribute(CheckOutGISDefaults.ZustandsIndex, zustandsabschnitt.Zustandsindex.ToString().Replace('.', ',')); if (zustandsabschnitt.Zustandsindex != null) { zaAttributes.AddAttribute(CheckOutGISDefaults.ZustandsIndex, double.Parse(zustandsabschnitt.Zustandsindex.ToString())); } else { zaAttributes.AddAttribute(CheckOutGISDefaults.ZustandsIndex, double.Parse("-1")); } zaFeature.Attributes = zaAttributes; return(zaFeature); }
public string GenerateGeoJsonStringFromEntity(InspektionsRouteGIS inspektionsroute) { if (inspektionsroute == null) { return("{ \"type\": \"FeatureCollection\", \"features\": []}"); } FeatureWithID feature = new FeatureWithID(); IAttributesTable attributes = new AttributesTable(); IList <FeatureWithID> strassenabschnitte = new List <FeatureWithID>(); feature.Id = inspektionsroute.Id.ToString(); feature.Geometry = inspektionsroute.Shape; attributes.AddAttribute(geoJSONAttribute_InspektionsrouteID, inspektionsroute.Id); attributes.AddAttribute(geoJSONAttribute_InspektionsrouteBezeichnung, inspektionsroute.Bezeichnung); attributes.AddAttribute(geoJSONAttribute_IsLocked, inspektionsroute.IsLocked); //GEOJSON PROPERTIES: Strassenabschnitte foreach (InspektionsRtStrAbschnitte inspektionsrouteStrassenabschnitt in inspektionsroute.InspektionsRtStrAbschnitteList) { FeatureWithID featureIrs = new FeatureWithID(); IAttributesTable attributeIrs = new AttributesTable(); IList <AchsenReferenz> achsenreferenzenIrs = achsenReferenzService.GetAchsenReferenzGruppe(inspektionsrouteStrassenabschnitt.StrassenabschnittGIS.ReferenzGruppe.Id); IList <FeatureWithID> achsenreferenzen = new List <FeatureWithID>(); featureIrs.Id = inspektionsrouteStrassenabschnitt.StrassenabschnittGIS.Id.ToString(); featureIrs.Geometry = inspektionsrouteStrassenabschnitt.StrassenabschnittGIS.Shape; foreach (AchsenReferenz achsenreferenz in achsenreferenzenIrs) { FeatureWithID featAr = new FeatureWithID(); IAttributesTable attAr = new AttributesTable(); featAr.Id = achsenreferenz.Id.ToString(); featAr.Geometry = achsenreferenz.Shape; attAr.AddAttribute(geoJSONAttribute_AchsenSegmentId, achsenreferenz.AchsenSegment.Id); featAr.Attributes = attAr; achsenreferenzen.Add(featAr); } attributeIrs.AddAttribute(geoJSONAttribute_childs, achsenreferenzen); featureIrs.Attributes = attributeIrs; strassenabschnitte.Add(featureIrs); } attributes.AddAttribute(geoJSONAttribute_Strassenabschnitte, strassenabschnitte); feature.Attributes = attributes; TextWriter sw = new StringWriter(); GeoJSONWriter.WriteWithID(feature, sw); string geoJSONstring = sw.ToString(); return(geoJSONstring); }
public FeatureCollection GetBestObvFeatures(List <Network> networks) { var features = new List <Feature>(networks.Count); for (int i = 0; i < networks.Count; i++) { var net = networks[i]; Location bestObv = PickBestObservation(net); if (bestObv == null) { //cell tower? continue; } var atts = new AttributesTable(); atts.AddAttribute("ssid", net.ssid); atts.AddAttribute("bssid", net.bssid); atts.AddAttribute("accuracy", bestObv.accuracy); atts.AddAttribute("level", bestObv.level); var f = new Feature(bestObv.GetPoint(), atts); features.Add(f); } return(new FeatureCollection(new Collection <Feature>(features))); }
public void write_polygon_with_hole() { Coordinate c0 = new Coordinate(10.1, 10); Coordinate c1 = new Coordinate(20.2, 20); Coordinate c2 = new Coordinate(30.3, 30); ILinearRing shell = Factory.CreateLinearRing(new[] { c0, c1, c2, c0 }); Coordinate h0 = new Coordinate(15, 15); Coordinate h1 = new Coordinate(17, 15); Coordinate h2 = new Coordinate(15, 17); ILinearRing hole = Factory.CreateLinearRing(new[] { h0, h1, h2, h0 }); IGeometry geometry = Factory.CreatePolygon(shell, new[] { hole }); AttributesTable attributes = new AttributesTable(); attributes.AddAttribute("prop0", "value0"); attributes.AddAttribute("prop1", "value1"); IFeature feature = new Feature(geometry, attributes); TopoJsonWriter writer = new TopoJsonWriter(); string actual = writer.Write(feature); Assert.That(actual, Is.Not.Null); Assert.That(actual, Is.Not.Empty); Console.WriteLine(actual); Assert.That(actual, Is.EqualTo(TopoWriterData.PolygonWithHole)); }
static void Main(string[] args) { FeatureCollection features = new FeatureCollection(); // Polygon 1 List <Coordinate> coords = new List <Coordinate>(); coords.Add(new Coordinate(0, 0)); coords.Add(new Coordinate(0, 10)); coords.Add(new Coordinate(10, 10)); coords.Add(new Coordinate(10, 0)); coords.Add(new Coordinate(0, 0)); LinearRing ring = new LinearRing(coords.ToArray()); Polygon poly = new Polygon(ring); // Polygon1 attributes AttributesTable attr = new AttributesTable(); attr.AddAttribute("Column1", "HELLO"); attr.AddAttribute("Column2", "WORLD !"); Feature featureForPolygon = new Feature(poly, attr); features.Add(featureForPolygon); ShapefileDataWriter writer = new ShapefileDataWriter(@"%userprofile%\documents\outFile"); writer.Header = new DbaseFileHeader(); writer.Header.AddColumn("Column1", 'C', 10, 0); writer.Header.AddColumn("Column2", 'C', 10, 0); writer.Write(features.Features); }
/// <summary> /// Gets a feature collection with features representing the stop links. /// </summary> /// <returns></returns> public static FeatureCollection GetStopLinks(this MultimodalDb db, Profile profile, uint stopId) { var features = new FeatureCollection(); var stopEnumerator = db.TransitDb.GetStopsEnumerator(); if (stopEnumerator.MoveTo(stopId)) { var stopLocation = new GeoAPI.Geometries.Coordinate(stopEnumerator.Longitude, stopEnumerator.Latitude); var attributes = new AttributesTable(); attributes.AddAttribute("stop_id", stopId); features.Add(new Feature(new Point(stopLocation), attributes)); var stopLinksDb = db.GetStopLinksDb(profile).GetEnumerator(); stopLinksDb.MoveTo(stopId); while (stopLinksDb.MoveNext()) { var routerPoint = new RouterPoint(0, 0, stopLinksDb.EdgeId, stopLinksDb.Offset); var linkLocation = routerPoint.LocationOnNetwork(db.RouterDb).ToCoordinate(); attributes = new AttributesTable(); attributes.AddAttribute("edge_id", stopLinksDb.EdgeId.ToInvariantString()); attributes.AddAttribute("offset", stopLinksDb.Offset.ToInvariantString()); features.Add(new Feature(new Point(linkLocation), attributes)); features.Add(new Feature(new LineString(new GeoAPI.Geometries.Coordinate[] { stopLocation, linkLocation }), new AttributesTable())); } } return(features); }
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); }
private static AttributesTable CreateAttributes(int id, string label) { var res = new AttributesTable(); res.AddAttribute("id", id); res.AddAttribute("label", label); return(res); }
public string GetNearestAchsenSegment(double x, double y, double tolerance) { IGeometry clickedPoint = EMSG.Business.Services.GIS.GISService.CreateGeometryFactory().CreatePoint(new Coordinate((double)x, (double)y, 0)); var buffer = clickedPoint.Buffer(tolerance); IList <AchsenSegment> achsegmentList = GetCurrentEntityListBySpatialFilter(buffer); AchsenSegment selectedAchsensegment = gisService.GetNearestGeometry(clickedPoint, achsegmentList); TextWriter tw = new StringWriter(); IAttributesTable table = new AttributesTable(); //GEOJSON PROPERTIES: STRASSENABSCHNITTE List <FeatureWithID> features = new List <FeatureWithID>(); if (selectedAchsensegment == null) { return(GeoJSONStrings.GeoJSONFailure("No Achsen found")); } foreach (AchsenReferenz achsenreferenz in selectedAchsensegment.AchsenReferenzen.Where(ar => ar.Erfassungsperiod == historizationService.GetCurrentErfassungsperiod())) { if (achsenreferenz.ReferenzGruppe.StrassenabschnittGIS != null) { FeatureWithID feat = new FeatureWithID(); IAttributesTable att = new AttributesTable(); feat.Id = achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Id.ToString(); feat.Geometry = achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Shape; feat.Attributes = att; if (!features.Contains(feat)) { features.Add(feat); } } } table.AddAttribute("Strassenabschnitte", features); table.AddAttribute("AchsenId", selectedAchsensegment.Achse.Id); table.AddAttribute("AchsenName", selectedAchsensegment.Achse.Name); table.AddAttribute("IsInverted", selectedAchsensegment.IsInverted); FeatureWithID feature = new FeatureWithID(); feature.Id = selectedAchsensegment.Id.ToString(); feature.Geometry = selectedAchsensegment.Shape; feature.Attributes = table; TextWriter sw = new StringWriter(); GeoJSONWriter.WriteFeatureWithID(feature, sw); return(sw.ToString()); }
/// <summary> /// Advances the IDataReader to the next record. /// </summary> /// <returns>true if there are more rows; otherwise, false.</returns> public bool Read() { if (RecordCount == 0) { return(false); } bool moreDbfRecords = _dbfEnumerator.MoveNext(); bool moreShpRecords = _shpEnumerator.MoveNext(); /* * if (!moreDbfRecords) * { * int a = 0; * a++; * } * if (!moreShpRecords) * { * int b = 0; * b++; * } */ _moreRecords = moreDbfRecords && moreShpRecords; // get current shape geometry = (IGeometry)_shpEnumerator.Current; // get current dbase record var columnValues = (ArrayList)_dbfEnumerator.Current; _columnValues = new ArrayList(1 + columnValues.Count); _columnValues.Add(geometry /*.AsBinary()*/); _columnValues.AddRange(columnValues); //_columnValues = (ArrayList)_dbfEnumerator.Current; IAttributesTable tbl = new AttributesTable(); ArrayList data = _columnValues; if (!_hasFID) { tbl.AddAttribute("FID", _currentIndex); } else { } for (int i = 0; i < DbaseHeader.Fields.Length; i++) { tbl.AddAttribute(DbaseHeader.Fields[i].Name, data[i + 1]); } attributeTable = tbl; _currentIndex++; return(_moreRecords); // moreDbfRecords && moreShpRecords; }
//returns geoJSON of boundaries from DB filters by type public string GetGeoJsonCollectionFromBoundaryCollection(ICollection <Boundary> collectionOfBoundaries, BoundaryType boundaryType) { //create GeoJSON writer GeoJsonWriter geoJsonWriter = new GeoJsonWriter(); //create WKT Binary reader WKBReader wKBReader = new WKBReader(); //create empty feature collection FeatureCollection features = new FeatureCollection(); //setup return boundary flag bool returnBoundary = false; //iterate through collection foreach (Boundary boundary in collectionOfBoundaries) { returnBoundary = false; switch (boundaryType) { case BoundaryType.ALL: returnBoundary = true; break; case BoundaryType.COVERAGE: if (boundary.isCoverageArea) { returnBoundary = true; } break; case BoundaryType.DISPLAY: if (boundary.displayOnMap) { returnBoundary = true; } break; } if (returnBoundary) { //set up feature attributes table AttributesTable attributesTable = new AttributesTable(); //add attributes to table from boundary attributesTable.AddAttribute("id", boundary.BoundaryId); attributesTable.AddAttribute("Name", boundary.Name); //convert DbGeometry to GeoApi.IGeometry IGeometry iGeom = wKBReader.Read(boundary.Area.AsBinary()); //create feature from geom and attributes Feature feature = new Feature(iGeom, attributesTable); //add feature to feature collection features.Add(feature); } } return(geoJsonWriter.Write(features)); }
public void WriteJsonTest() { AttributesTableConverter target = new AttributesTableConverter(); StringBuilder sb = new StringBuilder(); JsonTextWriter writer = new JsonTextWriter(new StringWriter(sb)); AttributesTable value = new AttributesTable(); value.AddAttribute("test1", "value1"); value.AddAttribute("test2", "value2"); JsonSerializer serializer = new JsonSerializer(); target.WriteJson(writer, value, serializer); writer.Flush(); Assert.AreEqual("\"properties\":{\"test1\":\"value1\",\"test2\":\"value2\"}", sb.ToString()); }
public IEnumerable <TimeZoneFeature> ReadShapeFile() { var factory = new GeometryFactory(); using (var reader = new ShapefileDataReader(_shapeFile, factory)) { var header = reader.DbaseHeader; while (reader.Read()) { var attributes = new AttributesTable(); for (int i = 0; i < header.NumFields; i++) { var name = header.Fields[i].Name; var value = reader.GetValue(i); attributes.AddAttribute(name, value); } // skip uninhabited areas var zone = (string)attributes["TZID"]; if (zone.Equals("uninhabited", StringComparison.OrdinalIgnoreCase)) { continue; } var geometry = reader.Geometry; yield return(new TimeZoneFeature { TzName = zone, Geometry = geometry, }); } } }
public static string ToGeoJson(this IGeometry geometry, int srId, KeyValuePair <string, object>[] attributes = null) { var attributesTable = new AttributesTable(); if (attributes != null) { foreach (var attribute in attributes) { attributesTable.AddAttribute(attribute.Key, attribute.Value); } } var feature = new Feature(geometry, attributesTable); var featureCollection = new FeatureCollection() { CRS = new NamedCRS(string.Format("EPSG:{0}", srId)), Features = { feature } }; var geoJsonSerializer = new GeoJsonSerializer(geometry.Factory); var stringBuilder = new StringBuilder(); using (var sw = new StringWriter(stringBuilder)) geoJsonSerializer.Serialize(sw, featureCollection); return(stringBuilder.ToString()); }
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); }
public List <Feature> LoadFeatureList(string filename) { List <Feature> features = new List <Feature>(); if (File.Exists(filename)) { using (ShapefileDataReader sdr = new ShapefileDataReader(filename, GeometryFactory.Default)) { DbaseFileHeader header = sdr.DbaseHeader; while (sdr.Read()) { Feature feature = new Feature(); AttributesTable attributesTable = new AttributesTable(); string[] keys = new string[header.NumFields]; Geometry geometry = (Geometry)sdr.Geometry; for (int i = 0; i < header.NumFields; i++) { DbaseFieldDescriptor fldDescriptor = header.Fields[i]; keys[i] = fldDescriptor.Name; attributesTable.AddAttribute(fldDescriptor.Name, sdr.GetValue(i)); } feature.Geometry = geometry; feature.Attributes = attributesTable; features.Add(feature); } } } return(features); }
/// <summary> /// Builds from the given provider. /// </summary> /// <param name="provider"> /// The base <see cref="SharpMap.Data.Providers.IProvider"/> /// from witch initialize the <see cref="NtsProvider"/> instance. /// </param> private void BuildFromProvider(IProvider provider) { // Features list initialization _features = new List <Feature>(provider.GetFeatureCount()); try { // Load all features from the given provider provider.Open(); Collection <uint> ids = provider.GetObjectIDsInView(provider.GetExtents()); foreach (uint id in ids) { FeatureDataRow dataRow = provider.GetFeature(id); GeoAPI.Geometries.IGeometry geometry = GeometryConverter.ToNTSGeometry(dataRow.Geometry, _geometryFactory); AttributesTable attributes = new AttributesTable(); foreach (DataColumn column in dataRow.Table.Columns) { if (dataRow[column] == null || dataRow[column] is DBNull) { throw new ApplicationException("Null values not supported"); } attributes.AddAttribute(column.ColumnName, dataRow[column]); } _features.Add(new Feature(geometry, attributes)); } } finally { if (provider.IsOpen) { provider.Close(); } } }
private void TestShapeCreation() { var points = new Coordinate[3]; points[0] = new Coordinate(0, 0); points[1] = new Coordinate(1, 0); points[2] = new Coordinate(1, 1); var line_string = new LineString(points); var attributes = new AttributesTable(); attributes.AddAttribute("FOO", "FOO"); var feature = new Feature(Factory.CreateMultiLineString(new ILineString[] { line_string }), attributes); var features = new Feature[1]; features[0] = feature; var shp_writer = new ShapefileDataWriter("line_string") { Header = ShapefileDataWriter.GetHeader(features[0], features.Length) }; shp_writer.Write(features); }
public IAttributesTable ReadEntry(int index) { if (m_IsDisposed) { throw new InvalidOperationException("Reader was disposed, cannot read from a disposed reader"); } if (index < 0) { throw new ArgumentException("Index must be positive", "index"); } int seekLocation = m_Header.HeaderLength + (index * m_Header.RecordLength); if (seekLocation >= m_FileReader.BaseStream.Length) { throw new ArgumentOutOfRangeException("index", "No DBF entry with index " + index); } m_FileReader.BaseStream.Seek(seekLocation, SeekOrigin.Begin); AttributesTable tbl = new AttributesTable(); ArrayList data = ReadCurrentEntry(); for (int i = 0; i < data.Count; i++) { tbl.AddAttribute(m_Header.Fields[i].Name, data[i]); } return(tbl); }
private static object InternalReadJson(JsonReader reader, JsonSerializer serializer) { // TODO: refactor to remove check when reading TopoJSON if (reader.TokenType == JsonToken.StartArray) { reader.Read(); // move to first item IList <object> array = new List <object>(); do { object inner = InternalReadJson(reader, serializer); array.Add(inner); reader.Read(); // move to next item } while (reader.TokenType != JsonToken.EndArray); return(array); } if (reader.TokenType != JsonToken.StartObject) { throw new ArgumentException("Expected token '{' not found."); } reader.Read(); AttributesTable attributesTable = new AttributesTable(); while (reader.TokenType == JsonToken.PropertyName) { string attributeName = (string)reader.Value; reader.Read(); object attributeValue; if (reader.TokenType == JsonToken.StartObject) { // inner object attributeValue = InternalReadJson(reader, serializer); } else if (reader.TokenType == JsonToken.StartArray) { reader.Read(); // move to first item IList <object> array = new List <object>(); do { object inner = InternalReadJson(reader, serializer); array.Add(inner); reader.Read(); // move to next item } while (reader.TokenType != JsonToken.EndArray); attributeValue = array; } else { attributeValue = reader.Value; } attributesTable.AddAttribute(attributeName, attributeValue); reader.Read(); } // TODO: refactor to remove check when reading TopoJSON if (reader.TokenType != JsonToken.EndObject) { throw new ArgumentException("Expected token '}' not found."); } return(attributesTable); }
private static object InternalReadJson(JsonReader reader, JsonSerializer serializer) { if (reader.TokenType != JsonToken.StartObject) { throw new ArgumentException("Expected token '{' not found."); } reader.Read(); AttributesTable attributesTable = new AttributesTable(); while (reader.TokenType == JsonToken.PropertyName) { string attributeName = (string)reader.Value; reader.Read(); object attributeValue; if (reader.TokenType == JsonToken.StartObject) { // inner object attributeValue = InternalReadJson(reader, serializer); } else { attributeValue = reader.Value; } attributesTable.AddAttribute(attributeName, attributeValue); reader.Read(); } return(attributesTable); }
public static List <Feature> ReadShapefile(string shpFilename, int max = int.MaxValue) { var features = new List <Feature>(); using (ShapefileDataReader dr = new ShapefileDataReader(shpFilename, new GeometryFactory())) { DbaseFileHeader header = dr.DbaseHeader; int n = 0; while (dr.Read()) { n++; if (n > max) { break; } AttributesTable attributesTable = new AttributesTable(); for (int i = 0; i < header.NumFields; i++) { attributesTable.AddAttribute(header.Fields[i].Name, dr.GetValue(i)); } features.Add(new Feature(dr.Geometry, attributesTable)); } } return(features); }
public void GeoJsonWriterWriteAnyObjectTest() { AttributesTable attributes = new AttributesTable(); DateTime Date = new DateTime(2012, 8, 8).Date; JsonSerializer g = new GeoJsonSerializer { NullValueHandling = NullValueHandling.Ignore }; StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) g.Serialize(sw, Date); string expectedDateString = sb.ToString(); string expectedResult = "{\"featureCollection\":{\"type\":\"FeatureCollection\",\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[23.0,56.0]},\"properties\":{\"test1\":\"value1\"}}],\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"name1\"}}},\"Date\":" + expectedDateString + "}"; attributes.AddAttribute("test1", "value1"); IFeature feature = new Feature(new Point(23, 56), attributes); FeatureCollection featureCollection = new FeatureCollection(new Collection <IFeature> { feature }) { CRS = new NamedCRS("name1") }; var gjw = new GeoJsonWriter(); gjw.SerializerSettings.NullValueHandling = NullValueHandling.Ignore; string actual = gjw.Write(new { featureCollection, Date = Date }); Assert.AreEqual(expectedResult, actual); }
public void LoadCountries(string path) { iso2Countries = new Dictionary <string, Feature>(); iso3Countries = new Dictionary <string, Feature>(); countryFeatures = new ArrayList(); countriesDt = new System.Data.DataTable(); GeometryFactory factory = new GeometryFactory(); using (ShapefileDataReader reader = new ShapefileDataReader(path, factory)) { foreach (var f in reader.DbaseHeader.Fields) { countriesDt.Columns.Add(f.Name, f.Type); } var keyCol = countryDtKeyCandidates .Intersect(countriesDt.Columns.OfType <System.Data.DataColumn>().Select(col => col.ColumnName)) .FirstOrDefault(); if (keyCol != null) { countriesDt.PrimaryKey = new System.Data.DataColumn[] { countriesDt.Columns[keyCol] }; } countriesDt.Columns.Add("WKT", typeof(string)); while (reader.Read()) { Feature feature = new Feature(); AttributesTable attributesTable = new AttributesTable(); string[] keys = new string[reader.DbaseHeader.NumFields]; IGeometry geometry = (Geometry)reader.Geometry; System.Data.DataRow row = countriesDt.NewRow(); for (int i = 0; i < reader.DbaseHeader.NumFields; i++) { DbaseFieldDescriptor fldDescriptor = reader.DbaseHeader.Fields[i]; keys[i] = fldDescriptor.Name; attributesTable.AddAttribute(fldDescriptor.Name, reader.GetValue(i)); row[i] = reader.GetValue(i); } row["WKT"] = geometry.AsText(); countriesDt.Rows.Add(row); feature.Geometry = geometry; feature.Attributes = attributesTable; if (feature.Attributes.Exists("ISO2") && feature.Attributes.Exists("ISO3")) { int index = countryFeatures.Add(feature); var iso2 = (string)feature.Attributes["ISO2"]; var iso3 = (string)feature.Attributes["ISO3"]; iso2Countries.Add(iso2, feature); iso3Countries.Add(iso3, feature); } } reader.Close(); } }
public void write_simple_point() { IPoint geometry = Factory.CreatePoint(new Coordinate(23.4, 56.7)); AttributesTable attributes = new AttributesTable(); attributes.AddAttribute("prop0", "value0"); attributes.AddAttribute("prop1", "value1"); IFeature feature = new Feature(geometry, attributes); TopoJsonWriter writer = new TopoJsonWriter(); string actual = writer.Write(feature); Assert.That(actual, Is.Not.Null); Assert.That(actual, Is.Not.Empty); Console.WriteLine(actual); Assert.That(actual, Is.EqualTo(TopoWriterData.SimplePoint)); }
public Feature CreateAchsenReferenzFeature(AchsenReferenz achsenreferenz, Guid inspektionsrouteid) { Feature arFeature = new Feature(); IAttributesTable saArAttributes = new AttributesTable(); arFeature.Geometry = achsenreferenz.Shape; //ID saArAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.AchsenreferenzID), achsenreferenz.Id.ToString()); //AchsenID saArAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.AchsensegmentID), achsenreferenz.AchsenSegment.Id.ToString()); //ReferenzgruppeID saArAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.ReferenzgruppeID), achsenreferenz.ReferenzGruppe.Id.ToString()); //inspektionsRouteID saArAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.InspektionsRouteID), inspektionsrouteid.ToString()); //ZustandsabschnittID if Achsenreferenz belongs to a Zustandsabschnitt else StrassenabschnittsID (belongs to Strassenabschnitt) if (achsenreferenz.ReferenzGruppe.ZustandsabschnittGIS != null) { saArAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.ZustandsabschnittID), achsenreferenz.ReferenzGruppe.ZustandsabschnittGIS.Id.ToString()); saArAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.StrassenabschnittGISID), achsenreferenz.ReferenzGruppe.ZustandsabschnittGIS.StrassenabschnittGIS.Id.ToString()); } else if (achsenreferenz.ReferenzGruppe.StrassenabschnittGIS != null) { saArAttributes.AddAttribute(checkStringLengthforDBF(CheckOutGISDefaults.StrassenabschnittGISID), achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Id.ToString()); } arFeature.Attributes = saArAttributes; return(arFeature); }
public string GetAchsensegmentCollection(string achsensegmentIds) { var splitachsensegmentIds = achsensegmentIds.Split(','); List <FeatureWithID> achsensegmente = new List <FeatureWithID>(); StringWriter sw = new StringWriter(); foreach (string achsensegmentId in splitachsensegmentIds) { AchsenSegment aseg = GetEntityById(Guid.Parse(achsensegmentId)); FeatureWithID feat = new FeatureWithID(); IAttributesTable att = new AttributesTable(); List <FeatureWithID> strassenabschnitte = new List <FeatureWithID>(); foreach (AchsenReferenz achsenreferenz in aseg.AchsenReferenzen.Where(a => a.Erfassungsperiod == historizationService.GetCurrentErfassungsperiod())) { if (achsenreferenz.ReferenzGruppe.StrassenabschnittGIS != null) { FeatureWithID strabsfeat = new FeatureWithID(); IAttributesTable strabsatt = new AttributesTable(); strabsfeat.Id = achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Id.ToString(); strabsfeat.Geometry = achsenreferenz.ReferenzGruppe.StrassenabschnittGIS.Shape; strabsfeat.Attributes = strabsatt; if (!strassenabschnitte.Contains(strabsfeat)) { strassenabschnitte.Add(strabsfeat); } } } att.AddAttribute("AchsenId", aseg.Achse.Id); att.AddAttribute("AchsenName", aseg.Achse.Name); att.AddAttribute("IsInverted", aseg.IsInverted); att.AddAttribute("Strassenabschnitte", strassenabschnitte); feat.Geometry = aseg.Shape; feat.Id = aseg.Id.ToString(); feat.Attributes = att; achsensegmente.Add(feat); } GeoJSONWriter.WritewithID(achsensegmente, sw); sw.Flush(); return(sw.ToString()); }
/// <summary> /// Gets a features representing the vertex with the given id. /// </summary> public static Feature GetFeatureForVertex(this RouterDb routerDb, uint vertex) { var coordinate = routerDb.Network.GetVertex(vertex).ToCoordinate(); var attributes = new AttributesTable(); attributes.AddAttribute("id", vertex); return(new Feature(new Point(coordinate), attributes)); }
public void GeoJsonWriterWriteAttributesTest() { AttributesTable attributes = new AttributesTable(); attributes.AddAttribute("test1", "value1"); string actual = new GeoJsonWriter().Write(attributes); Assert.AreEqual("{\"test1\":\"value1\"}", actual); }
/// <summary> /// Converts to instructions to features. /// </summary> public static FeatureCollection ToFeatureCollection(this IList <Instruction> instructions, Route route) { var features = new FeatureCollection(); for (var i = 0; i < instructions.Count; i++) { var instruction = instructions[i]; var coordinate = route.Shape[instruction.Shape].ToCoordinate(); var attributes = new AttributesTable(); attributes.AddAttribute("text", instruction.Text); attributes.AddAttribute("type", instruction.Type.ToInvariantString().ToLowerInvariant()); var point = new Point(coordinate); features.Add(new Feature(point, attributes)); } return(features); }
/// <summary> /// Builds from the given provider. /// </summary> /// <param name="provider"> /// The base <see cref="SharpMap.Data.Providers.IProvider"/> /// from witch initialize the <see cref="NtsProvider"/> instance. /// </param> private void BuildFromProvider(IProvider provider) { // Features list initialization _features = new List<Feature>(provider.GetFeatureCount()); try { // Load all features from the given provider provider.Open(); var ids = provider.GetOidsInView(provider.GetExtents()); foreach (var id in ids) { var dataRow = provider.GetFeatureByOid(id); var geometry = dataRow.Geometry; AttributesTable attributes = new AttributesTable(); var att = dataRow.Attributes; foreach (var column in dataRow.Factory.AttributesDefinition) { var attName = column.AttributeName; if (att[attName] == null || att[attName] is DBNull) throw new ApplicationException("Null values not supported"); attributes.AddAttribute(attName, att[column.AttributeName]); } _features.Add(new Feature(geometry, attributes)); } } finally { if (provider.IsOpen) provider.Close(); } }
/// <summary> /// Builds from the given provider. /// </summary> /// <param name="provider"> /// The base <see cref="SharpMap.Data.Providers.IProvider"/> /// from witch initialize the <see cref="NtsProvider"/> instance. /// </param> private void BuildFromProvider(IProvider provider) { // Features list initialization _features = new List<Feature>(provider.GetFeatureCount()); try { // Load all features from the given provider provider.Open(); Collection<uint> ids = provider.GetObjectIDsInView(provider.GetExtents()); foreach (uint id in ids) { var dataRow = provider.GetFeature(id); var geometry = dataRow.Geometry; AttributesTable attributes = new AttributesTable(); foreach (DataColumn column in dataRow.Table.Columns) { if (dataRow[column] == null || dataRow[column] is DBNull) throw new ApplicationException("Null values not supported"); attributes.AddAttribute(column.ColumnName, dataRow[column]); } _features.Add(new Feature(geometry, attributes)); } } finally { if (provider.IsOpen) provider.Close(); } }