public Geometry GetGeometryByID(uint oid) { Geometry geom = null; using (SQLiteConnection conn = new SQLiteConnection(_connectionString)) { string strSQL = "SELECT " + GeometryColumn + " AS Geom FROM " + Table + " WHERE " + ObjectIdColumn + "='" + oid.ToString() + "'"; conn.Open(); using (SQLiteCommand command = new SQLiteCommand(strSQL, conn)) { using (SQLiteDataReader dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { geom = GeometryFromWKT.Parse((string)dr[0]); } } } } conn.Close(); } return(geom); }
public void Operations() { //Prepare data Geometry gPn = GeometryFromWKT.Parse(Point); gPn.SRID = 0; Geometry gMp = GeometryFromWKT.Parse(Multipoint); gMp.SRID = 0; Geometry gLi = GeometryFromWKT.Parse(Linestring); gLi.SRID = 0; Geometry gML = GeometryFromWKT.Parse(MultiLinestring); gML.SRID = 0; Geometry gPl = GeometryFromWKT.Parse(Polygon); gPl.SRID = 0; Geometry gPnBuffer30 = SpatialOperationsEx.Buffer(gPn, 30); System.Diagnostics.Trace.WriteLine(gPnBuffer30.ToString()); Geometry gPnBuffer30IntersectiongPl = SpatialOperationsEx.Intersection(gPnBuffer30, gPl); System.Diagnostics.Trace.WriteLine(gPnBuffer30IntersectiongPl.ToString()); Geometry gUnion = SpatialOperationsEx.Union(gPn, gMp, gML, gLi, gPl); System.Diagnostics.Trace.WriteLine(gUnion.ToString()); }
/// <summary> /// Boundingbox of dataset /// </summary> /// <returns>boundingbox</returns> public IEnvelope GetExtents() { using (SqlConnection conn = new SqlConnection(this.connectionString)) { string strSQL = String.Format( //"SELECT g.{0}{1}.STEnvelope().STAsText() FROM {2} g ", //NS 2013-04-03 "SELECT g.{0}{1}.STAsText() FROM {2} g ", this.GeometryColumn, this.MakeValidString, this.Table); if (!String.IsNullOrEmpty(this.DefinitionQuery)) { strSQL += " WHERE " + this.DefinitionQuery; } using (SqlCommand command = new SqlCommand(strSQL, conn)) { conn.Open(); IEnvelope bx = null; SqlDataReader dr = command.ExecuteReader(); while (dr.Read()) { string wkt = dr.GetString(0); IGeometry g = GeometryFromWKT.Parse(wkt); IEnvelope bb = g.EnvelopeInternal; bx = bx == null ? bb : bx.Union(bb); } dr.Close(); conn.Close(); return(bx); } } }
public void ConvertAndBack(SqlServerSpatialObjectType spatialType) { int srid = 4326; //Prepare data var gPn = GeometryFromWKT.Parse(Point); var gMp = GeometryFromWKT.Parse(Multipoint); var gLi = GeometryFromWKT.Parse(Linestring); var gML = GeometryFromWKT.Parse(MultiLinestring); var gPl = GeometryFromWKT.Parse(Polygon); var gMPol = GeometryFromWKT.Parse(MultiPolygon); // Geography requires valid SRID gPn.SRID = srid; gMp.SRID = srid; gLi.SRID = srid; gML.SRID = srid; gPl.SRID = srid; gMPol.SRID = srid; var comparison = new Comparison <IGeometry>((u, v) => u.EqualsExact(v) ? 0 : 1); Assert.That(ToSqlServerAndBack(gPn, spatialType), Is.EqualTo(gPn).Using(comparison)); Assert.That(ToSqlServerAndBack(gMp, spatialType), Is.EqualTo(gMp).Using(comparison)); Assert.That(ToSqlServerAndBack(gLi, spatialType), Is.EqualTo(gLi).Using(comparison)); Assert.That(ToSqlServerAndBack(gML, spatialType), Is.EqualTo(gML).Using(comparison)); Assert.That(ToSqlServerAndBack(gPl, spatialType), Is.EqualTo(gPl).Using(comparison)); Assert.That(ToSqlServerAndBack(gMPol, spatialType), Is.EqualTo(gMPol).Using(comparison)); }
public override Geometry GetGeometryByID(uint oid) { Geometry geom = null; using (var conn = new SQLiteConnection(ConnectionID)) { string strSQL = "SELECT " + GeometryColumn + " AS Geom FROM " + Table + " WHERE " + ObjectIdColumn + "='" + oid.ToString(NumberFormatInfo.InvariantInfo) + "'"; conn.Open(); using (var command = new SQLiteCommand(strSQL, conn)) { using (var dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { geom = GeometryFromWKT.Parse((string)dr[0]); } } } } conn.Close(); } return(geom); }
public void UpdateChainagesRegardlessOfOrderingAfterSplitBranch() { var network = new Network(); var branch = new Branch { Source = new Node("n1"), Target = new Node("n2"), IsLengthCustom = false, Length = 1000, Geometry = GeometryFromWKT.Parse("LINESTRING(0 0, 100 0)") }; network.Branches.Add(branch); var f1 = new SimpleBranchFeature(); var f2 = new SimpleBranchFeature(); var f3 = new SimpleBranchFeature(); var f4 = new SimpleBranchFeature(); NetworkHelper.AddBranchFeatureToBranch(f1, branch, 5); NetworkHelper.AddBranchFeatureToBranch(f2, branch, 50); NetworkHelper.AddBranchFeatureToBranch(f3, branch, 15); NetworkHelper.AddBranchFeatureToBranch(f4, branch, 10); NetworkHelper.SplitBranchAtNode(network.Branches.First(), 20); Assert.AreEqual(5, f1.Chainage); Assert.AreEqual(30, f2.Chainage); Assert.AreEqual(15, f3.Chainage); Assert.AreEqual(10, f4.Chainage); }
public void UpdateLengthAfterSplitNonGeometryBasedBranchWithLength0ThrowsException() { // note ExpectedException(typeof(InvalidOperationException)) no longer thrown. // offset and thus SplitBranchAtNode use geometry based value var network = new Network(); network.Branches.Add(new Branch { Source = new Node("n1"), Target = new Node("n2"), Geometry = GeometryFromWKT.Parse("LINESTRING(0 0, 100 0)") }); var branch = network.Branches.First(); Assert.AreEqual(100.0, branch.Length); branch.IsLengthCustom = true; branch.Length = 0; var node = NetworkHelper.SplitBranchAtNode(network.Branches.First(), 50).NewNode; Assert.AreEqual(0, node.IncomingBranches[0].Length); Assert.AreEqual(0, node.OutgoingBranches[0].Length); }
public void SplitChannelAtNode() { var network = new Network(); var branch = new Branch { Source = new Node("n1"), Target = new Node("n2"), Geometry = GeometryFromWKT.Parse("LINESTRING(219478.546875 495899.46875,219434.578125 495917.3125,219202.234375 495979,219074.015625 496013.59375,219046.5 496021.15625,218850.078125 496073.59375,218732.421875 496105.65625,218572.546875 496148.9375,218473.515625 496173.90625,218463.546875 496176.65625,218454.734375 496178.9375,218264.84375 496229.65625,218163.8125 496256.53125,218073.453125 496280.59375,217862.65625 496336.71875,217672.5 496387.3125,217487.9375 496436.4375,217293.546875 496488.1875,217103.90625 496538.65625,216945.078125 496580.9375,216748.34375 496633.3125,216581.8125 496677.65625,216380.8125 496731.15625,216205.03125 496777.9375,215978.53125 496838.21875,215819.328125 496880.59375,215646.3125 496926.65625,215563.609375 496948.6875,215502.453125 496966.28125,215501.234375 496966.625,215448 496981.40625,215216.5 497069.90625,215083.546875 497124.40625,214913.109375 497191.34375,214733.015625 497260.15625,214557.265625 497329.3125,214369.578125 497403.1875,214147.828125 497490.4375,213947.328125 497569.34375,213883.34375 497594.0625,213862.03125 497601.0625,213848.140625 497603.0625,213627.5625 497609.375,213513.796875 497612.53125,213494.71875 497614.9375,213471.40625 497621.9375,213325.015625 497681.5,213317.515625 497684.40625,213049.609375 497788.21875,212896.21875 497844.78125,212675.125 497868.21875,212426.046875 497843.375,212282.171875 497830.03125,212042.1875 497810.25,211798.59375 497791.46875,211515.140625 497766.625,211509.109375 497766.09375,211234.28125 497741.8125,211070.875 497729.75,210538.3125 497760.78125,210445.53125 497768.15625,210408.921875 497763.28125,210372.796875 497752.5625,210325.953125 497745.0625,210279.109375 497742.5625,210237.625 497753.625,210209.734375 497769.71875,210001.203125 497891.03125,209796.765625 498006.6875,209763.90625 498020.5625,209722.265625 498029.3125,209691.59375 498026.40625,209600.1875 498008.53125,209498.828125 497991.75,209441.78125 497987.15625,209390.375 497987.96875,209337.359375 497996.8125,208898.703125 498072.90625,208331.625 498166.03125,208286.40625 498172.8125)") }; /*branch.IsLengthCustom = true; * double originalLength = 11597.6724261341; * branch.Length = originalLength;*/ var originalLength = branch.Length; network.Branches.Add(branch); //twice as long.. NetworkHelper.SplitBranchAtNode(branch, 763); //the first branch is EXACTLY clipped.. Assert.AreEqual(763, network.Branches[0].Length); //and the other branch Assert.AreEqual(originalLength - 763, network.Branches[1].Length); }
public override IGeometry GetGeometryByOid(object oid) { IGeometry geom = null; using (var conn = new SQLiteConnection(ConnectionID)) { string strSQL = "SELECT " + GeometryColumn + " AS Geom FROM " + Table + " WHERE " + ObjectIdColumn + "=@POid"; conn.Open(); using (var command = new SQLiteCommand(strSQL, conn)) { command.Parameters.Add(new SQLiteParameter("POid", oid)); using (var dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { geom = GeometryFromWKT.Parse((string)dr[0]); } } } } conn.Close(); } return(geom); }
public void SetAttributes() { Collection <IGeometry> geometries = new Collection <IGeometry>(); geometries.Add(GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)")); geometries.Add(GeometryFromWKT.Parse("LINESTRING (21 21, 21 31, 31 31, 31 21, 41 21)")); geometries.Add(GeometryFromWKT.Parse("LINESTRING (22 22, 22 32, 32 32, 32 22, 42 22)")); DataTableFeatureProvider dataTableFeatureFeatureProvider = new DataTableFeatureProvider(geometries); VectorLayer vectorLayer = new VectorLayer(); vectorLayer.DataSource = dataTableFeatureFeatureProvider; // add column FeatureDataRow r = (FeatureDataRow)vectorLayer.DataSource.GetFeature(0); r.Table.Columns.Add("Value", typeof(float)); // set value attribute for (int i = 0; i < dataTableFeatureFeatureProvider.GetFeatureCount(); i++) { r = (FeatureDataRow)dataTableFeatureFeatureProvider.GetFeature(i); r[0] = i; } FeatureDataRow row = (FeatureDataRow)dataTableFeatureFeatureProvider.GetFeature(2); Assert.AreEqual(2, row[0], "Attribute 0 in the second feature must be set to 2"); }
public void CreateFromCollection() { EventedList <SampleFeature> features = new EventedList <SampleFeature>(); features.Add(new SampleFeature()); features.Add(new SampleFeature()); features.Add(new SampleFeature()); features[0].Geometry = GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)"); features[1].Geometry = GeometryFromWKT.Parse("LINESTRING (30 30, 30 40, 40 40, 40 30, 50 30)"); features[2].Geometry = GeometryFromWKT.Parse("LINESTRING (40 40, 40 50, 50 50, 50 40, 60 40)"); FeatureCollection featureCollection = new FeatureCollection { Features = features }; Map map = new Map(); VectorLayer vectorLayer = new VectorLayer(); vectorLayer.DataSource = featureCollection; map.Layers.Add(vectorLayer); Assert.AreEqual(3, vectorLayer.DataSource.GetFeatureCount()); Assert.AreEqual("LineString", vectorLayer.DataSource.GetGeometryByID(0).GeometryType); // ShowMap(map); }
public override IEnumerable <IGeometry> GetGeometriesInView(Envelope view, CancellationToken?cancellationToken = null) { using (var conn = new SQLiteConnection(ConnectionID)) { var boxIntersect = GetBoxClause(view); var strSQL = "SELECT " + GeometryColumn + " AS Geom "; strSQL += "FROM " + Table + " WHERE "; strSQL += boxIntersect; if (!String.IsNullOrEmpty(_definitionQuery)) { strSQL += " AND " + DefinitionQuery; } using (var command = new SQLiteCommand(strSQL, conn)) { conn.Open(); using (var dr = command.ExecuteReader()) { while (dr.Read()) { if (dr[0] != DBNull.Value) { var geom = GeometryFromWKT.Parse((string)dr[0]); if (geom != null) { yield return(geom); } } } } conn.Close(); } } }
public void Evaluate() { // create network var network = new Network(); var node1 = new Node("node1"); var node2 = new Node("node2"); network.Nodes.Add(node1); network.Nodes.Add(node2); var branch1 = new Branch("branch1", node1, node2, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)") }; network.Branches.Add(branch1); // create network coverage INetworkCoverage networkCoverage = new NetworkCoverage { Network = network }; networkCoverage.Locations.InterpolationType = ApproximationType.Linear; networkCoverage[new NetworkLocation(network.Branches[0], 0.0)] = 0; networkCoverage[new NetworkLocation(network.Branches[0], 100.0)] = 10; // evaluate var value = networkCoverage.Evaluate <double>(50.0, 0.0); value.Should().Be.EqualTo(5); // linear interpolation }
public void ThrowExceptionWhenBranchIdsAreNotUnique() { var network = new Network(); var node1 = new Node("node1"); var node2 = new Node("node2"); var node3 = new Node("node3"); network.Nodes.Add(node1); network.Nodes.Add(node2); network.Nodes.Add(node3); var branch1 = new Branch("branch1", node1, node2, 100.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)") }; var branch2 = new Branch("branch2", node2, node3, 200.0) { Geometry = GeometryFromWKT.Parse("LINESTRING (100 0, 300 0)") }; network.Branches.Add(branch1); network.Branches.Add(branch2); var location = new NetworkLocation(network.Branches[0], 0); var typeConverter = new NetworkLocationTypeConverter(network); typeConverter.ConvertToStore(location); // throws exception since branch ids are not unique }
public void FailingConversions() { //Prepare data const string invalidMultiPolygon = "MULTIPOLYGON (((20 20, 20 30, 30 30, 30 20, 20 20)), ((21 21, 21 29, 29 29, 29 21, 21 21)))"; Geometry gMP = GeometryFromWKT.Parse(invalidMultiPolygon); Assert.AreEqual(gMP, ToSqlServerAndBack(gMP)); }
public void FailingConversionGeog() { //Prepare data const string invalidMultiPolygon = "MULTIPOLYGON (((20 20, 20 30, 30 30, 30 20, 20 20)), ((21 21, 21 29, 29 29, 29 21, 21 21)))"; var gMP = GeometryFromWKT.Parse(invalidMultiPolygon); gMP.SRID = 4326; Assert.Throws <SqlGeographyConverterException>(() => gMP = ToSqlServerAndBack(gMP, SqlServerSpatialObjectType.Geography)); }
public void ShowRoutes() { Routes.Clear(); List <QuestionList> questionLists = DBContext.Instance.QuestionLists.Where(x => x.Festival.Id == _festival.Id).ToList(); List <Inspection> inspections = new List <Inspection>(); foreach (QuestionList list in questionLists) { List <Inspection> listInspections = DBContext.Instance.Inspections.Where(x => x.QuestionList.Id == list.Id).ToList(); foreach (Inspection add in listInspections) { inspections.Add(add); } } foreach (Inspection inspection in inspections) { Employee employee = inspection.Employee; try { var responseRoute = _geodan.FindRoute($"&from={employee.City}%20{employee.Street}%20{employee.HouseNumber}&to={_festival.City}%20{_festival.Street}%20{_festival.HouseNumber}&srs=epsg:28992&returntype=coords&outputformat=json"); var geometry = responseRoute.features[0].geometry; string code = $"{geometry.type} ("; foreach (var coord in geometry.coordinates) { var i = coord[0]; var sm = SphericalMercator.FromLonLat((float)coord[0], (float)coord[1]); code += $"{sm.X} {sm.Y}".Replace(",", ".") + ", "; } code = code.Remove(code.Length - 2, 2) + ")"; var geoRoute = GeometryFromWKT.Parse(code); var routeLayer = new Layer { DataSource = new MemoryProvider(geoRoute), Style = new VectorStyle { Line = new Pen(Color.Black, 3), } }; MapControl.Map.Layers.Add(routeLayer); Routes.Add(new RouteData(routeLayer, employee, (double)responseRoute.features[0].properties.route_distance, (double)responseRoute.features[0].properties.route_duration)); } catch (NoRouteException) { //No valid route was found MessageBox.Show($"Geen route gevonden voor {employee.Name},\nControleer het adres van het festival en de medewerker.", "Geen route gevonden"); Routes.Add(new RouteData(null, employee, 999.9, 59940)); } } UpdateRouteColors(); }
public void ParseMultiPoint() { string multipoint = "MULTIPOINT(20.564 346.3493254,45 32,23 54)"; IMultiPoint geom = GeometryFromWKT.Parse(multipoint) as IMultiPoint; Assert.IsNotNull(geom); Assert.AreEqual(20.564, (geom.Geometries[0] as IPoint).X); Assert.AreEqual(54, (geom.Geometries[2] as IPoint).Y); Assert.AreEqual(multipoint, geom.AsText()); Assert.IsTrue(GeometryFromWKT.Parse("MULTIPOINT EMPTY").IsEmpty); Assert.AreEqual("MULTIPOINT EMPTY", GeometryFactory.CreateMultiPoint(null).AsText()); }
public void ParsePoint() { string point = "POINT(20.564 346.3493254)"; IPoint geom = GeometryFromWKT.Parse(point) as IPoint; Assert.IsNotNull(geom); Assert.AreEqual(20.564, geom.X); Assert.AreEqual(346.3493254, geom.Y); Assert.AreEqual(point, geom.AsText()); Assert.IsTrue(GeometryFromWKT.Parse("POINT EMPTY").IsEmpty); Assert.AreEqual("POINT EMPTY", GeometryFactory.CreatePoint(null).AsText()); }
public void ParseLineString() { string linestring = "LINESTRING(20 20,20 30,30 30,30 20,40 20)"; ILineString geom = GeometryFromWKT.Parse(linestring) as ILineString; Assert.IsNotNull(geom); Assert.AreEqual(40, geom.Length); Assert.IsFalse(geom.IsRing); Assert.AreEqual(linestring, geom.AsText()); Assert.IsTrue((GeometryFromWKT.Parse("LINESTRING EMPTY") as ILineString).IsEmpty); Assert.AreEqual("LINESTRING EMPTY", GeometryFactory.CreateLineString(null).AsText()); }
public void AllVerticesTransformTest() { // arrange var geomety = GeometryFromWKT.Parse("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))"); var transformation = new MinimalTransformation(); // act var enumeration = transformation.Transform("EPSG:4326", "EPSG:3857", geomety); // assert Assert.AreEqual(14, enumeration.AllVertices().Count()); }
public void MultiLineStringAllVerticesTest() { // arrange var geomety = GeometryFromWKT.Parse("MULTILINESTRING ((10 10, 20 20, 10 40), (40 40, 30 30, 40 20, 30 10))"); const int numberOfVectices = 7; // act var enumeration = geomety.AllVertices(); // assert Assert.AreEqual(numberOfVectices, enumeration.Count()); }
public FeatureDataRow GetFeature(uint RowID) { using (SQLiteConnection conn = new SQLiteConnection(_connectionString)) { string strSQL = "SELECT *, " + GeometryColumn + " AS sharpmap_tempgeometry FROM " + Table + " WHERE " + ObjectIdColumn + "='" + RowID.ToString() + "'"; using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(strSQL, conn)) { DataSet ds = new DataSet(); conn.Open(); adapter.Fill(ds); conn.Close(); if (ds.Tables.Count > 0) { FeatureDataTable fdt = new FeatureDataTable(ds.Tables[0]); foreach (DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" && !col.ColumnName.StartsWith("Envelope_")) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } if (ds.Tables[0].Rows.Count > 0) { DataRow dr = ds.Tables[0].Rows[0]; FeatureDataRow fdr = fdt.NewRow(); foreach (DataColumn col in ds.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" && !col.ColumnName.StartsWith("Envelope_")) { fdr[col.ColumnName] = dr[col]; } } if (dr["sharpmap_tempgeometry"] != DBNull.Value) { fdr.Geometry = GeometryFromWKT.Parse((string)dr["sharpmap_tempgeometry"]); } return(fdr); } else { return(null); } } else { return(null); } } } }
public void MultiPolygonAllVerticesTest() { // arrange var geomety = GeometryFromWKT.Parse("MULTIPOLYGON (((40 40, 20 45, 45 30, 40 40)), ((20 35, 10 30, 10 10, 30 5, 45 20, 20 35), (30 20, 20 15, 20 25, 30 20)))"); const int numberOfVectices = 14; // act var enumeration = geomety.AllVertices(); // assert Assert.AreEqual(numberOfVectices, enumeration.Count()); }
public override void ExecuteIntersectionQuery(BoundingBox box, FeatureDataSet ds) { using (var conn = new SQLiteConnection(ConnectionID)) { string strSQL = "SELECT *, " + GeometryColumn + " AS sharpmap_tempgeometry "; strSQL += "FROM " + Table + " WHERE "; strSQL += GetBoxClause(box); if (!String.IsNullOrEmpty(_definitionQuery)) { strSQL += " AND " + DefinitionQuery; } using (SQLiteDataAdapter adapter = new SQLiteDataAdapter(strSQL, conn)) { conn.Open(); DataSet ds2 = new DataSet(); adapter.Fill(ds2); conn.Close(); if (ds2.Tables.Count > 0) { FeatureDataTable fdt = new FeatureDataTable(ds2.Tables[0]); foreach (DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" && !col.ColumnName.StartsWith("Envelope_")) { fdt.Columns.Add(col.ColumnName, col.DataType, col.Expression); } } foreach (DataRow dr in ds2.Tables[0].Rows) { FeatureDataRow fdr = fdt.NewRow(); foreach (DataColumn col in ds2.Tables[0].Columns) { if (col.ColumnName != GeometryColumn && col.ColumnName != "sharpmap_tempgeometry" && !col.ColumnName.StartsWith("Envelope_")) { fdr[col.ColumnName] = dr[col]; } } if (dr["sharpmap_tempgeometry"] != DBNull.Value) { fdr.Geometry = GeometryFromWKT.Parse((string)dr["sharpmap_tempgeometry"]); } fdt.AddRow(fdr); } ds.Tables.Add(fdt); } } } }
public void SplitBranchFeaturesWithLengthIntoTwoFeaturesWithBranchWithCustomLength() { // n1 f1 n2 n1 f1_1 n3 f1_2 n2 // O--------==================----------O ==> O--------=========O=========----------O // ^ // split var network = new Network(); var node1 = new Node("n1"); var node2 = new Node("n2"); var branch = new Branch("Branch", node1, node2, 100) { Geometry = GeometryFromWKT.Parse("LINESTRING(0 0, 100 0)"), IsLengthCustom = true, Length = 200 }; var f1 = new SimpleBranchFeature { Name = "f1", Length = 100, Chainage = 50, Geometry = GeometryFromWKT.Parse("LINESTRING(25 0, 75 0)") }; network.Nodes.AddRange(new[] { node1, node2 }); network.Branches.Add(branch); NetworkHelper.AddBranchFeatureToBranch(f1, branch, 50); // split is geometry based --> offset 50 (geometry based) == 100 m (custom length format) NetworkHelper.SplitBranchAtNode(branch, 50); Assert.AreEqual(2, network.Branches.Count); Assert.AreEqual(3, network.Nodes.Count); var branch2 = network.Branches[1]; Assert.AreEqual(1, branch.BranchFeatures.Count); Assert.AreEqual(1, branch2.BranchFeatures.Count); var f2 = branch2.BranchFeatures[0]; Assert.AreEqual(50, f1.Length); Assert.AreEqual(50, f2.Length); Assert.AreEqual(25, f1.Geometry.Length); Assert.AreEqual(25, f2.Geometry.Length); Assert.AreEqual(50, f1.Chainage); Assert.AreEqual(0, f2.Chainage); Assert.AreEqual("f1_1", f1.Name); Assert.AreEqual("f1_2", f2.Name); }
public void NetworkLocationsAreNotAddedToBranchFeatures() { //issue pinpoints the problem of issue 2358 var branch = new Branch { Source = new Node("n1"), Target = new Node("n2"), Geometry = GeometryFromWKT.Parse("LINESTRING(219478.546875 495899.46875,219434.578125 495917.3125,219202.234375 495979,219074.015625 496013.59375,219046.5 496021.15625,218850.078125 496073.59375,218732.421875 496105.65625,218572.546875 496148.9375,218473.515625 496173.90625,218463.546875 496176.65625,218454.734375 496178.9375,218264.84375 496229.65625,218163.8125 496256.53125,218073.453125 496280.59375,217862.65625 496336.71875,217672.5 496387.3125,217487.9375 496436.4375,217293.546875 496488.1875,217103.90625 496538.65625,216945.078125 496580.9375,216748.34375 496633.3125,216581.8125 496677.65625,216380.8125 496731.15625,216205.03125 496777.9375,215978.53125 496838.21875,215819.328125 496880.59375,215646.3125 496926.65625,215563.609375 496948.6875,215502.453125 496966.28125,215501.234375 496966.625,215448 496981.40625,215216.5 497069.90625,215083.546875 497124.40625,214913.109375 497191.34375,214733.015625 497260.15625,214557.265625 497329.3125,214369.578125 497403.1875,214147.828125 497490.4375,213947.328125 497569.34375,213883.34375 497594.0625,213862.03125 497601.0625,213848.140625 497603.0625,213627.5625 497609.375,213513.796875 497612.53125,213494.71875 497614.9375,213471.40625 497621.9375,213325.015625 497681.5,213317.515625 497684.40625,213049.609375 497788.21875,212896.21875 497844.78125,212675.125 497868.21875,212426.046875 497843.375,212282.171875 497830.03125,212042.1875 497810.25,211798.59375 497791.46875,211515.140625 497766.625,211509.109375 497766.09375,211234.28125 497741.8125,211070.875 497729.75,210538.3125 497760.78125,210445.53125 497768.15625,210408.921875 497763.28125,210372.796875 497752.5625,210325.953125 497745.0625,210279.109375 497742.5625,210237.625 497753.625,210209.734375 497769.71875,210001.203125 497891.03125,209796.765625 498006.6875,209763.90625 498020.5625,209722.265625 498029.3125,209691.59375 498026.40625,209600.1875 498008.53125,209498.828125 497991.75,209441.78125 497987.15625,209390.375 497987.96875,209337.359375 497996.8125,208898.703125 498072.90625,208331.625 498166.03125,208286.40625 498172.8125)") }; NetworkHelper.AddBranchFeatureToBranch(new NetworkLocation(branch, 1), branch); Assert.AreEqual(0, branch.BranchFeatures.Count); }
public void DefaultExtentForVectorLayer() { var geometry = GeometryFromWKT.Parse("LINESTRING (20 20, 20 30, 30 30, 30 20, 40 20)"); var provider = new DataTableFeatureProvider(geometry); var map = new Map { Layers = { new VectorLayer { DataSource = provider } } }; Assert.IsTrue(map.GetExtents().Contains(geometry.EnvelopeInternal)); }
public void GetDistinctBranchesViaLinq() { IList <Branch> branches = new List <Branch>(); var branch1 = new Branch { Geometry = GeometryFromWKT.Parse("LINESTRING (0 0, 100 0)") }; branches.Add(branch1); branches.Add(branch1); Assert.AreEqual(2, branches.Count); Assert.AreEqual(1, branches.Distinct().Count()); }
public void SplitBranchFeaturesWithLengthIntoTwoFeaturesWhereTheFeatureWithTheLongestLengthShouldBeOrginalFeature() { // n1 f1 n2 n1 f1_1 n3 f1_2 n2 // O--------==================----------O ==> O--------====O==============----------O // ^ (f1_B = original feature) // split var network = new Network(); var node1 = new Node("n1"); var node2 = new Node("n2"); var branch = new Branch("Branch", node1, node2, 100) { Geometry = GeometryFromWKT.Parse("LINESTRING(0 0, 100 0)") }; var f1 = new SimpleBranchFeature { Name = "f1", Length = 50, Geometry = GeometryFromWKT.Parse("LINESTRING(25 0, 75 0)") }; network.Nodes.AddRange(new[] { node1, node2 }); network.Branches.Add(branch); NetworkHelper.AddBranchFeatureToBranch(f1, branch, 25); NetworkHelper.SplitBranchAtNode(branch, 40); Assert.AreEqual(2, network.Branches.Count); Assert.AreEqual(3, network.Nodes.Count); var branch2 = network.Branches[1]; Assert.AreEqual(1, branch.BranchFeatures.Count); Assert.AreEqual(1, branch2.BranchFeatures.Count); var feature1 = branch.BranchFeatures[0]; var feature2 = branch2.BranchFeatures[0]; Assert.AreEqual(15, feature1.Length); Assert.AreEqual(35, feature2.Length); Assert.AreEqual(15, feature1.Geometry.Length); Assert.AreEqual(35, feature2.Geometry.Length); Assert.AreEqual(25, feature1.Chainage); Assert.AreEqual(0, feature2.Chainage); Assert.AreEqual("f1_1", feature1.Name); Assert.AreEqual("f1_2", feature2.Name); Assert.AreEqual(f1, feature2); }