//GET /api/routing?from=31.8239,35.0375&to=31.8213,35.0965&type=f public async Task<IHttpActionResult> GetRouting(string from, string to, string type) { LineString lineString; var profile = ConvertProfile(type); var pointFrom = await GetGeographicPosition(from); var pointTo = await GetGeographicPosition(to); if (ModelState.IsValid == false) { return BadRequest(ModelState); } if (profile == ProfileType.None) { lineString = new LineString(new[] { pointFrom, pointTo }); } else { lineString = await _routingGateway.GetRouting(new RoutingGatewayRequest { From = from, To = to, Profile = profile, }); } var table = new AttributesTable(); table.AddAttribute("Name", "Routing from " + from + " to " + to + " profile type: " + profile); table.AddAttribute("Creator", "IsraelHikingMap"); var feature = new Feature(lineString, table); return Ok(new FeatureCollection(new Collection<IFeature> { 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) { 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(); if (!(reader.TokenType == JsonToken.PropertyName && (string) reader.Value == "geometry")) throw new ArgumentException("Expected token 'geometry' not found."); reader.Read(); if (reader.TokenType != JsonToken.StartObject) throw new ArgumentException("Expected token '{' not found."); Feature feature = new Feature {Geometry = serializer.Deserialize<Geometry>(reader)}; if (reader.TokenType != JsonToken.EndObject) throw new ArgumentException("Expected token '}' not found."); reader.Read(); if (reader.TokenType == JsonToken.PropertyName && (string) reader.Value == "properties") feature.Attributes = serializer.Deserialize<AttributesTable>(reader); if (reader.TokenType != JsonToken.EndObject) throw new ArgumentException("Expected token '}' not found."); reader.Read(); return feature; }
public void AddTest() { FeatureCollection target = new FeatureCollection(); IFeature feature = new Feature(); target.Add(feature); Assert.AreEqual(feature, target.Features[0]); }
void AddFeature(NetTopologySuite.Features.Feature feature, Color color, float elev) { Vector3[] points = null; if (feature.Geometry is NetTopologySuite.Geometries.LineString) { var linear = (NetTopologySuite.Geometries.LineString)feature.Geometry; if (!linear.IsValid) { return; } points = new Vector3[linear.Count]; for (int i = 0; i < points.Length; ++i) { var geographicCoordinates = new GeographicCoordinates(linear[i].Y, linear[i].X); var cartesianCoordinates = geographicCoordinates.TransformedWith(Database.Projection); points[i] = new Vector3((float)cartesianCoordinates.X, elev, (float)cartesianCoordinates.Y); } } if (points == null) { return; } var featureGameObject = new GameObject(); featureGameObject.transform.SetParent(Database.gameObject.transform); LineRenderer lineRenderer = featureGameObject.AddComponent <LineRenderer>(); lineRenderer.positionCount = points.Length; lineRenderer.SetPositions(points); lineRenderer.startWidth = 0.1f; lineRenderer.endWidth = 0.1f; lineRenderer.startColor = color; lineRenderer.endColor = color; lineRenderer.sharedMaterial = LineMaterial; }
private void TestWriteZMValuesShapeFile(bool testM) { var points = new Coordinate[3]; points[0] = new Coordinate(0, 0); points[1] = new Coordinate(1, 0); points[2] = new Coordinate(1, 1); var csFactory = DotSpatialAffineCoordinateSequenceFactory.Instance; var sequence = csFactory.Create(3, Ordinates.XYZM); for (var i = 0; i < 3; i++) { sequence.SetOrdinate(i, Ordinate.X, points[i].X); sequence.SetOrdinate(i, Ordinate.Y, points[i].Y); sequence.SetOrdinate(i, Ordinate.Z, 1 + i); if (testM) sequence.SetOrdinate(i, Ordinate.M, 11 + i); } var lineString = Factory.CreateLineString(sequence); var attributes = new AttributesTable(); attributes.AddAttribute("FOO", "Trond"); var feature = new Feature(Factory.CreateMultiLineString(new[] { lineString }), attributes); var features = new Feature[1]; features[0] = feature; var shpWriter = new ShapefileDataWriter("ZMtest", Factory) { Header = ShapefileDataWriter.GetHeader(features[0], features.Length) }; shpWriter.Write(features); // Now let's read the file and verify that we got Z and M back var factory = new GeometryFactory(DotSpatialAffineCoordinateSequenceFactory.Instance); using (var reader = new ShapefileDataReader("ZMtest", factory)) { reader.Read(); var geom = reader.Geometry; for (var i = 0; i < 3; i++) { var c = geom.Coordinates[i]; Assert.AreEqual(i + 1, c.Z); } if (testM) { sequence = ((ILineString)geom).CoordinateSequence; for (var i = 0; i < 3; i++) { Assert.AreEqual(sequence.GetOrdinate(i, Ordinate.M), 11 + i); } } // Run a simple attribute test too var v = reader.GetString(0); Assert.AreEqual(v, "Trond"); } }
/// <summary> /// Gets the stub header. /// </summary> /// <param name="feature">The feature.</param> /// <param name="count">The count.</param> /// <returns></returns> public static DbaseFileHeader GetHeader(Feature 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) || type == typeof(long) || type == typeof(ulong)) header.AddColumn(name, 'N', IntLength, 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; }
public FeatureCollection ToGeoJson(gpxType gpx) { var collection = new FeatureCollection(); var points = gpx.wpt ?? new wptType[0]; var pointsFeatures = points.Select(point => new Feature(new Point(CreateGeoPosition(point)), CreateNameProperties(point.name))); pointsFeatures.ToList().ForEach(f => collection.Features.Add(f)); var routes = gpx.rte ?? new rteType[0]; var routesFeatures = routes.Select(route => new Feature(new LineString(route.rtept.Select(CreateGeoPosition).ToArray()), CreateNameProperties(route.name))); routesFeatures.ToList().ForEach(f => collection.Features.Add(f)); foreach (var track in gpx.trk ?? new trkType[0]) { if (track.trkseg.Length == 1) { var lineStringFeature = new Feature(new LineString(track.trkseg[0].trkpt.Select(CreateGeoPosition).ToArray()), CreateNameProperties(track.name)); collection.Features.Add(lineStringFeature); continue; } var lineStringList = track.trkseg.Select(segment => new LineString(segment.trkpt.Select(CreateGeoPosition).ToArray()) as ILineString).ToArray(); var feature = new Feature(new MultiLineString(lineStringList), CreateMultiLineProperties(track.name, gpx.creator)); collection.Features.Add(feature); } return collection; }
NetTopologySuite.Features.Feature MakeFeature(string wkt) { var reader = new WKTReader(); var geometry = reader.Read(wkt); var feature = new NetTopologySuite.Features.Feature(geometry, null); return(feature); }
public void RemoveAtTest() { IFeature feature = new Feature(); FeatureCollection target = new FeatureCollection(new Collection<IFeature> { feature }); const int index = 0; target.RemoveAt(index); Assert.AreEqual(0, target.Count); }
public async Task AddExternalPoi(Feature feature) { if (_elasticClient.IndexExists(EXTERNAL_POIS).Exists == false) { await CreateExternalPoisIndex(); } await _elasticClient.IndexAsync(feature, r => r.Index(EXTERNAL_POIS).Id(feature.GetId())); }
public void GeoJsonWriterWriteFeatureTest() { AttributesTable attributes = new AttributesTable(); attributes.AddAttribute("test1", "value1"); IFeature feature = new Feature(new Point(23, 56), attributes); string actual = new GeoJsonWriter().Write(feature); Assert.AreEqual("{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[23.0,56.0]},\"properties\":{\"test1\":\"value1\"}}", actual); }
public static NetTopologySuite.Features.Feature MakeFeature(string wkt, Dictionary <string, object> attr = null) { var reader = new WKTReader(_services); var geometry = reader.Read(wkt); var feature = new NetTopologySuite.Features.Feature(geometry, attr != null ? new AttributesTable(attr) : null); return(feature); }
NetTopologySuite.Features.Feature MakeFeature(IDictionary <string, object> attributes) { var attributesTable = new AttributesTable(attributes); var factory = new GeometryFactory(); var point = factory.CreatePoint(new Coordinate(1, 1)); var feature = new NetTopologySuite.Features.Feature(point, attributesTable); return(feature); }
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); }
public void GeoJsonWriterWriteFeatureCollectionTest() { AttributesTable attributes = new AttributesTable(); 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") }; string actual = new GeoJsonWriter().Write(featureCollection); Assert.AreEqual("{\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[23.0,56.0]},\"properties\":{\"test1\":\"value1\"}}],\"type\":\"FeatureCollection\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"name1\"}}}", actual); }
public void RemoveTest() { IFeature feature = new Feature(); FeatureCollection target = new FeatureCollection(new Collection<IFeature> { feature }); const bool expected = true; bool actual = target.Remove(feature); Assert.AreEqual(expected, actual); Assert.AreEqual(0, target.Count); }
public static FeatureCollection MakeFeatureCollection(NetTopologySuite.Features.Feature f) { var fc = new FeatureCollection { f }; return(fc); }
public void shapefile_with_empty_attributes_table_should_not_thrown_errors() { IFeature feature = new Feature(new Point(0, 0), new AttributesTable()); IList<IFeature> features = new List<IFeature> { feature }; string path = CreateShapefilePath(); DbaseFileHeader header = ShapefileDataWriter.GetHeader(feature, features.Count); ShapefileDataWriter writer = new ShapefileDataWriter(path) { Header = header }; writer.Write(features); Assert.That(File.Exists(Path.ChangeExtension(path, ".shp")), Is.True); }
public void GeoJsonSerializerFeatureTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); AttributesTable attributes = new AttributesTable(); attributes.AddAttribute("test1", "value1"); IFeature feature = new Feature(new Point(23, 56), attributes); GeoJsonSerializer serializer = new GeoJsonSerializer(); serializer.Serialize(writer, feature); writer.Flush(); Assert.AreEqual("{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[23.0,56.0]},\"properties\":{\"test1\":\"value1\"}}", sb.ToString()); }
public void WriteJsonWithArrayTest() { FeatureConverter target = new FeatureConverter(); StringBuilder sb = new StringBuilder(); JsonTextWriter writer = new JsonTextWriter(new StringWriter(sb)); AttributesTable attributes = new AttributesTable(); attributes.AddAttribute("test1", new [] { "value1", "value2" }); IFeature value = new Feature(new Point(23, 56), attributes); JsonSerializer serializer = new GeoJsonSerializer(); target.WriteJson(writer, value, serializer); writer.Flush(); Assert.AreEqual("{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[23.0,56.0]},\"properties\":{\"test1\":[\"value1\",\"value2\"]}}", sb.ToString()); }
ToNtsFeature(this CoreSpatial.IFeature feature, List <string> fieldNames) { NetTopologySuite.Geometries.Geometry geometry = null; var geo = feature.Geometry; switch (geo.GeometryType) { case GeometryType.Point: { var basicGeometry = (GeoPoint)geo.BasicGeometry; geometry = (NetTopologySuite.Geometries.Geometry)ToNtsPoint(basicGeometry); break; } case GeometryType.MultiPoint: { var basicGeometry = (CoreSpatial.BasicGeometrys.MultiPoint)geo.BasicGeometry; geometry = ToNtsMultiPoint(basicGeometry); break; } case GeometryType.PolyLine: { var basicGeometry = (CoreSpatial.BasicGeometrys.PolyLine)geo.BasicGeometry; geometry = basicGeometry.IsLineRing ? ToNtsLinearRing(basicGeometry) : ToNtsLineString(basicGeometry); break; } case GeometryType.MultiPolyLine: { var basicGeometry = (CoreSpatial.BasicGeometrys.MultiPolyLine)geo.BasicGeometry; geometry = ToNtsMultiLineString(basicGeometry); break; } case GeometryType.Polygon: { var basicGeometry = (CoreSpatial.BasicGeometrys.Polygon)geo.BasicGeometry; geometry = ToNtsPolygon(basicGeometry); break; } default: throw new Exception("not support GeometryType"); } var attrTable = feature.ToNtsAttributeTable(fieldNames); var result = new NetTopologySuite.Features.Feature(geometry, attrTable); return(result); }
public void ok_when_writing_shapefile_with_features() { DbaseFileHeader header = new DbaseFileHeader(); header.AddColumn("X", 'C', 10, 0); ShapefileDataWriter writer = new ShapefileDataWriter(@"issue36") { Header = header }; IAttributesTable attributesTable = new AttributesTable(); attributesTable.AddAttribute("X", "y"); IFeature feature = new Feature(new Point(1, 2), attributesTable); IList<IFeature> features = new List<IFeature>(); features.Add(feature); writer.Write(features); }
public void GeoJsonSerializerFeatureCollectionTest() { StringBuilder sb = new StringBuilder(); StringWriter writer = new StringWriter(sb); AttributesTable attributes = new AttributesTable(); 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")}; GeoJsonSerializer serializer = new GeoJsonSerializer(); serializer.Serialize(writer, featureCollection); writer.Flush(); Assert.AreEqual("{\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[23.0,56.0]},\"properties\":{\"test1\":\"value1\"}}],\"type\":\"FeatureCollection\",\"crs\":{\"type\":\"name\",\"properties\":{\"name\":\"name1\"}}}", sb.ToString()); }
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 static PropertiesData FindPropertiesData(Feature feature) { PropertiesData data = null; if (feature.Geometry is MultiPolygon || feature.Geometry is MultiLineString) { data = FindPropertiesData(feature.Attributes, Relations); } if (feature.Geometry is LineString || feature.Geometry is Polygon) { data = FindPropertiesData(feature.Attributes, Ways); } if (feature.Geometry is Point) { data = FindPropertiesData(feature.Attributes, Nodes); } return data; }
public void write_simple_polygon() { Coordinate c0 = new Coordinate(10.1, 10); Coordinate c1 = new Coordinate(20.2, 20); Coordinate c2 = new Coordinate(30.3, 30); IPolygon geometry = Factory.CreatePolygon(new[] { c0, c1, c2, c0 }); 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.SimplePolygon)); }
public void GeoJsonWriterWriteAnyObjectTest() { AttributesTable attributes = new AttributesTable(); DateTime Date = new DateTime(2012, 8, 8).Date; GeoJsonSerializer g = new GeoJsonSerializer(); StringBuilder sb = new StringBuilder(); using (StringWriter sw = new StringWriter(sb)) g.Serialize(sw, Date); string expectedDateString = sb.ToString(); string expectedResult = "{\"featureCollection\":{\"features\":[{\"type\":\"Feature\",\"geometry\":{\"type\":\"Point\",\"coordinates\":[23.0,56.0]},\"properties\":{\"test1\":\"value1\"}}],\"type\":\"FeatureCollection\",\"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") }; string actual = new GeoJsonWriter().Write(new { featureCollection, Date = Date }); Assert.AreEqual(expectedResult, actual); }
public void BuildStradeFixed() { var path = "strade" + shp; Assert.IsTrue(File.Exists(path)); var reader = new ShapefileDataReader(path, factory); var features = new List<IFeature>(reader.RecordCount); while (reader.Read()) { var feature = new Feature(reader.Geometry, new AttributesTable()); var values = new object[reader.FieldCount - 1]; reader.GetValues(values); for (var i = 0; i < values.Length; i++) { var name = reader.GetName(i + 1); var value = values[i]; feature.Attributes.AddAttribute(name, value); } features.Add(feature); } Assert.AreEqual(703, features.Count); var shapepath = "strade_fixed"; if (File.Exists(shapepath + shp)) File.Delete(shapepath + shp); Assert.IsFalse(File.Exists(shapepath + shp)); if (File.Exists(shapepath + shx)) File.Delete(shapepath + shx); Assert.IsFalse(File.Exists(shapepath + shx)); if (File.Exists(shapepath + dbf)) File.Delete(shapepath + dbf); Assert.IsFalse(File.Exists(shapepath + dbf)); var header = reader.DbaseHeader; var writer = new ShapefileDataWriter(shapepath, factory) {Header = header}; writer.Write(features); Assert.IsTrue(File.Exists(shapepath + shp)); Assert.IsTrue(File.Exists(shapepath + shx)); Assert.IsTrue(File.Exists(shapepath + dbf)); }
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 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)); }
private void SerializeFeature(Feature feature) { Writer.WriteStartObject(); Writer.WritePropertyName("type"); Writer.WriteValue("Feature"); Writer.WritePropertyName("properties"); Writer.WriteStartObject(); var attributeNames = feature.Attributes.GetNames(); foreach (var attrName in attributeNames) { Writer.WritePropertyName(attrName); Writer.WriteValue(feature.Attributes[attrName]); } Writer.WriteEndObject(); Writer.WritePropertyName("geometry"); _geometrySerializer.SerializeGeometry(feature.Geometry); Writer.WriteEndObject(); }
public void CountTest() { IFeature feature = new Feature(); FeatureCollection target = new FeatureCollection(new Collection<IFeature> { feature }); Assert.AreEqual(1, target.Count); }
public Task UpdateNamesData(Feature feature) { return(UpdateData(new List <Feature> { feature }, OSM_NAMES_ALIAS)); }
private string GetId(Feature feature) { return(feature.Geometry.GeometryType + "_" + GetId(feature.Attributes[FeatureAttributes.POI_SOURCE]?.ToString() ?? string.Empty, feature.Attributes[FeatureAttributes.ID]?.ToString() ?? string.Empty)); }
private ArrayList GetPointFeatures(IEnumerable<TtPoint> points, bool adjusted, DataAccessLayer DAL, Dictionary<string, TtMetaData> metas) { ArrayList features = new ArrayList(); Feature feat; AttributesTable attPointTable = new AttributesTable(); foreach (TtPoint p in points) { TtMetaData tmpMeta = metas[p.MetaDefCN]; attPointTable = new AttributesTable(); attPointTable.AddAttribute("PID", p.PID); attPointTable.AddAttribute("Op", p.op.ToString()); attPointTable.AddAttribute("Index", p.Index); attPointTable.AddAttribute("PolyName", p.PolyName); attPointTable.AddAttribute("DateTime", p.Time.ToString("MM/dd/yyyy hh:mm:ss tt")); /* if (metas.ContainsKey(p.MetaDefCN)) attPointTable.AddAttribute("MetaData", tmpMeta.Name); else attPointTable.AddAttribute("MetaData", String.Empty); */ attPointTable.AddAttribute("OnBnd", p.OnBnd); //attPointTable.AddAttribute("GroupName", p.GroupName); attPointTable.AddAttribute("AdjX", p.AdjX); attPointTable.AddAttribute("AdjY", p.AdjY); attPointTable.AddAttribute("AdjZ", p.AdjZ); attPointTable.AddAttribute("UnAdjX", p.UnAdjX); attPointTable.AddAttribute("UnAdjY", p.UnAdjY); attPointTable.AddAttribute("UnAdjZ", p.UnAdjZ); if (p.IsGpsType()) { GpsPoint gps = (GpsPoint)p; //attPointTable.AddAttribute("X", gps.X); //attPointTable.AddAttribute("Y", gps.X); //attPointTable.AddAttribute("Z", gps.Z); attPointTable.AddAttribute("RMSEr", gps.RMSEr.dNoNull()); attPointTable.AddAttribute("ManAcc", gps.ManualAccuracy.dNoNull()); } else { //attPointTable.AddAttribute("X", String.Empty); //attPointTable.AddAttribute("Y", String.Empty); //attPointTable.AddAttribute("Z", String.Empty); attPointTable.AddAttribute("RMSEr", String.Empty); attPointTable.AddAttribute("ManAcc", String.Empty); } /* if (p.IsTravType()) { SideShotPoint ssp = (SideShotPoint)p; attPointTable.AddAttribute("FwdAz", ssp.ForwardAz.dNoNull()); attPointTable.AddAttribute("BkAz", ssp.BackwardAz.dNoNull()); attPointTable.AddAttribute("SlopeDist", TtUtils.ConvertDistance(ssp.SlopeDistance, tmpMeta.uomDistance, UomDistance.Meters).ToString()); attPointTable.AddAttribute("HorzDist", TtUtils.ConvertDistance(ssp.HorizontalDistance, tmpMeta.uomDistance, UomDistance.Meters).ToString()); attPointTable.AddAttribute("DistType", tmpMeta.uomDistance.ToString()); attPointTable.AddAttribute("SlopeAngle", ssp.SlopeAngle); attPointTable.AddAttribute("AngleType", tmpMeta.uomSlope.ToString()); } else { attPointTable.AddAttribute("FwdAz", String.Empty); attPointTable.AddAttribute("BkAz", String.Empty); attPointTable.AddAttribute("SlopeDist", String.Empty); attPointTable.AddAttribute("HorzDist", String.Empty); attPointTable.AddAttribute("DistType", String.Empty); attPointTable.AddAttribute("SlopeAngle", String.Empty); attPointTable.AddAttribute("AngleType", String.Empty); } */ if (p.op == OpType.Quondam) { QuondamPoint q = (QuondamPoint)p; attPointTable.AddAttribute("ParentName", q.ParentPID); } else { attPointTable.AddAttribute("ParentName", String.Empty); } attPointTable.AddAttribute("Comment", p.Comment == null ? String.Empty : p.Comment); feat = new Feature(); feat.Geometry = (adjusted) ? new NetTopologySuite.Geometries.Point(p.AdjX, p.AdjY, p.AdjZ) : new NetTopologySuite.Geometries.Point(p.UnAdjX, p.UnAdjY, p.UnAdjZ); feat.Attributes = attPointTable; features.Add(feat); } return features; }
private string GetId(Feature feature) { return(GetId(feature.Attributes[FeatureAttributes.POI_SOURCE]?.ToString() ?? string.Empty, feature.Attributes[FeatureAttributes.ID]?.ToString() ?? string.Empty)); }
public void GivenAGeoJsonReaderAndWriter() { _reader = new GeoJsonReader(); _writer = new GeoJsonWriter(); var geometry = new Point(1, 2); _feature = new Feature(geometry, new AttributesTable()); }
public void ItemTest() { IFeature feature = new Feature(); FeatureCollection target = new FeatureCollection(new Collection<IFeature> { feature }); IFeature actual = target[0]; Assert.AreSame(feature, actual); }
private void ReadFromShapeFile() { var featureCollection = new ArrayList(); const string filename = @"country"; if (!File.Exists(filename + ".dbf")) throw new FileNotFoundException(filename + " not found at " + Environment.CurrentDirectory); var dataReader = new ShapefileDataReader(filename, new GeometryFactory()); while (dataReader.Read()) { var feature = new Feature {Geometry = dataReader.Geometry}; var length = dataReader.DbaseHeader.NumFields; var keys = new string[length]; for (var i = 0; i < length; i++) keys[i] = dataReader.DbaseHeader.Fields[i].Name; feature.Attributes = new AttributesTable(); for (var i = 0; i < length; i++) { var val = dataReader.GetValue(i); feature.Attributes.AddAttribute(keys[i], val); } featureCollection.Add(feature); } var index = 0; Console.WriteLine("Elements = " + featureCollection.Count); foreach (IFeature feature in featureCollection) { Console.WriteLine("Feature " + index++); var table = feature.Attributes as AttributesTable; foreach (var name in table.GetNames()) Console.WriteLine(name + ": " + table[name]); } //Directory var dir = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, string.Format(@"..{0}..{0}..{0}NetTopologySuite.Samples.Shapefiles{0}", Path.DirectorySeparatorChar)); // Test write with stub header var file = dir + "testWriteStubHeader"; if (File.Exists(file + ".shp")) File.Delete(file + ".shp"); if (File.Exists(file + ".shx")) File.Delete(file + ".shx"); if (File.Exists(file + ".dbf")) File.Delete(file + ".dbf"); var dataWriter = new ShapefileDataWriter(file); dataWriter.Header = ShapefileDataWriter.GetHeader(featureCollection[0] as IFeature, featureCollection.Count); dataWriter.Write(featureCollection); // Test write with header from a existing shapefile file = dir + "testWriteShapefileHeader"; if (File.Exists(file + ".shp")) File.Delete(file + ".shp"); if (File.Exists(file + ".shx")) File.Delete(file + ".shx"); if (File.Exists(file + ".dbf")) File.Delete(file + ".dbf"); dataWriter = new ShapefileDataWriter(file) { Header = ShapefileDataWriter.GetHeader(dir + "country.dbf") }; dataWriter.Write(featureCollection); }
private void WriteWayPoints(string file, List<WayPoint> points, TtMetaData md) { #if !(PocketPC || WindowsCE || Mobile) string FileName = file + "_WayPoints"; GeometryFactory geoFac = new GeometryFactory(); ShapefileDataWriter sdw = new ShapefileDataWriter(FileName, geoFac); ArrayList features = new ArrayList(); AttributesTable attTable; Feature feat = new Feature(); DbaseFileHeader dbh; foreach (WayPoint point in points) { feat = new Feature(); attTable = new AttributesTable(); attTable.AddAttribute("PID", point.PID); attTable.AddAttribute("Comment", point.Comment ?? String.Empty); attTable.AddAttribute("CN", point.CN); attTable.AddAttribute("Group", point.GroupName ?? String.Empty); attTable.AddAttribute("RMSEr", point.RMSEr ?? -1); attTable.AddAttribute("UnAdjX", point.UnAdjX); attTable.AddAttribute("UnAdjY", point.UnAdjY); attTable.AddAttribute("UnAdjZ", point.UnAdjZ); feat.Geometry = new NetTopologySuite.Geometries.Point(point.UnAdjX, point.UnAdjY, point.UnAdjZ); feat.Attributes = attTable; features.Add(feat); } dbh = ShapefileDataWriter.GetHeader((Feature)features[0], features.Count); sdw.Header = dbh; sdw.Write(features); WriteProjection(FileName, md.Zone); #endif }
/// <summary> /// Returns MarkerType property for legend. /// </summary> /// <param name="colorRepo"></param> /// <param name="resultDir"></param> /// <param name="fi"></param> /// <param name="resultName"></param> /// <returns></returns> private static void ProcessVectorFile(IColorRepository colorRepo, DirectoryInfo resultDir, FileInfo fi, string resultName) { string localFileName = fi.Name; string localResultName = resultName; Console.WriteLine(string.Format("Processing {0} into {1}...", localFileName, localResultName)); StringBuilder bldr = new StringBuilder(); NetTopologySuite.IO.ShapefileDataReader dataReader = new NetTopologySuite.IO.ShapefileDataReader(fi.FullName, new GeometryFactory()); NetTopologySuite.Features.FeatureCollection featureCollection = new NetTopologySuite.Features.FeatureCollection(); List<string> csvHdr = dataReader.DbaseHeader.Fields.Select(a => a.Name).ToList(); csvHdr.Add(appColorNamspace); bldr.AppendLine(string.Join(",", csvHdr)); //write csv file header while (dataReader.Read()) { NetTopologySuite.Features.Feature feature = new NetTopologySuite.Features.Feature(); feature.Geometry = dataReader.Geometry; int numFields = dataReader.DbaseHeader.NumFields + 1; string[] keys = new string[numFields]; int colorValueField = -1; for (int i = 0; i < numFields - 1; i++) { keys[i] = dataReader.DbaseHeader.Fields[i].Name; if (keys[i].Equals(colorRepo.ColorFieldForOutput(localFileName, localResultName))) { colorValueField = i; } } //add attributes from source attribute table feature.Attributes = new AttributesTable(); List<string> csvLine = new List<string>(); for (int i = 0; i < numFields - 1; i++) { object val = dataReader.GetValue(i); feature.Attributes.AddAttribute(keys[i], val); csvLine.Add(val.ToString()); } if (colorRepo.MapColorsToThisResult(localFileName, localResultName)) { //mark outline colors in a different attribute than fill colors string colorNs = colorRepo.IsOutlinedNotFilled(localFileName, localResultName) ? appOutlineNamespace : appColorNamspace; keys[numFields - 1] = colorNs; //add additional attribute for color binding string hexClr = colorRepo.SingleColorForFile(localFileName, localResultName); //only path where colorValueField, i.e. ColorMap.clrField can be unpopulated. if (string.IsNullOrEmpty(hexClr) && colorValueField > -1) { if (colorRepo.IsCategoricalMap(localFileName, resultName)) { //categorical color map hexClr = colorRepo.ColorsOfValueInFile(localFileName, localResultName, dataReader.GetString(colorValueField)).HexColor; } else { //numerical range color map hexClr = colorRepo.ColorsOfValueInFile(localFileName, localResultName, dataReader.GetDouble(colorValueField)).HexColor; } } if (string.IsNullOrEmpty(hexClr)) // else if (string.IsNullOrEmpty(hexClr) && colorValueField < 0) { throw new NotSupportedException("Cannot color a file with no attributes to bind to and no single-color given."); } csvLine.Add(hexClr); feature.Attributes.AddAttribute(colorNs, hexClr); } bldr.AppendLine(string.Join(",", csvLine)); featureCollection.Add(feature); } GeoJsonWriter wtr = new GeoJsonWriter(); string layerJson = wtr.Write(featureCollection); File.WriteAllText(resultDir.FullName + localResultName, layerJson); File.WriteAllText(resultDir.FullName + localResultName.Replace(".json", ".csv"), bldr.ToString()); }
public static IFeature FromByteBuffer(ByteBuffer bb, Header header) { // TODO: introspect which layer var columnsLayer = header.Layers(0).Value; IList <Column> columns = null; if (columnsLayer.ColumnsLength > 0) { columns = new List <Column>(); for (int i = 0; i < columnsLayer.ColumnsLength; i++) { var column = columnsLayer.Columns(i).Value; columns.Add(column); } } var feature = Feature.GetRootAsFeature(bb); IAttributesTable attributesTable = null; if (feature.ValuesLength > 0) { attributesTable = new AttributesTable(); } var layer = header.Layers((int)feature.Layer).Value; for (int i = 0; i < feature.ValuesLength; i++) { var value = feature.Values(i).Value; var column = columns[value.ColumnIndex]; switch (column.Type) { case ColumnType.Bool: attributesTable.AddAttribute(column.Name, value.BoolValue); break; case ColumnType.Int: attributesTable.AddAttribute(column.Name, value.IntValue); break; case ColumnType.Long: attributesTable.AddAttribute(column.Name, value.LongValue); break; case ColumnType.Double: attributesTable.AddAttribute(column.Name, value.DoubleValue); break; case ColumnType.String: attributesTable.AddAttribute(column.Name, value.StringValue); break; default: throw new ApplicationException("Unknown type"); } } var geometry = GeometryConversions.FromFlatbuf(feature.Geometry.Value, layer.GeometryType, layer.Dimensions); var f = new NetTopologySuite.Features.Feature(geometry, attributesTable); return(f); }
public static TEntityGeo ToEntityGeo <TEntityGeo>(this Feature feature) where TEntityGeo : EntityGeo, new() { return(GeoJsonModelToEntityGeo <TEntityGeo>(feature)); }