/// <summary> /// Returns all arcs inside the given bounding box. /// </summary> /// <param name="box"></param> /// <returns></returns> public KeyValuePair <uint, KeyValuePair <uint, TEdgeData> >[] GetEdges( GeoCoordinateBox box) { if (_vertexIndex == null) { // rebuild on-the-fly. this.RebuildVertexIndex(); } // get all the vertices in the given box. var vertices = _vertexIndex.GetInside( box); // loop over all vertices and get the arcs. var arcs = new List <KeyValuePair <uint, KeyValuePair <uint, TEdgeData> > >(); foreach (uint vertex in vertices) { var localArcs = this.GetEdges(vertex); foreach (var localArc in localArcs) { arcs.Add(new KeyValuePair <uint, KeyValuePair <uint, TEdgeData> >( vertex, localArc)); } } return(arcs.ToArray()); }
/// <summary> /// Try and find matching lines. /// </summary> /// <param name="lines"></param> /// <param name="points"></param> /// <returns></returns> private MatchPosition FindMatch(ILocatedObjectIndex <PointF2D, Scene2D.ScenePoints> linesIndex, Dictionary <Scene2D.ScenePoints, Scene2DStylesSet> lines, double[] x, double[] y, Scene2DStylesSet style, float epsilon, out Scene2D.ScenePoints found) { // build box. var box = new BoxF2D(x, y); box = box.ResizeWith(epsilon * 1.1); // get all geometries in this box. var potentialMatches = linesIndex.GetInside(box); // find a match in the potential matches list. PointF2D first = new PointF2D(x[0], y[0]); PointF2D last = new PointF2D(x[x.Length - 1], y[y.Length - 1]); MatchPosition position = MatchPosition.None; found = null; foreach (var line in potentialMatches) { // check first. PointF2D potentialFirst = new PointF2D(line.X[0], line.Y[0]); PointF2D potentialLast = new PointF2D(line.X[line.X.Length - 1], line.Y[line.Y.Length - 1]); if (first.Distance(potentialFirst) < epsilon) { found = line; position = MatchPosition.FirstFirst; } else if (last.Distance(potentialFirst) < epsilon) { found = line; position = MatchPosition.LastFirst; } else if (first.Distance(potentialLast) < epsilon) { found = line; position = MatchPosition.FirstLast; } else if (last.Distance(potentialLast) < epsilon) { found = line; position = MatchPosition.LastLast; } Scene2DStylesSet styleValue; if (position != MatchPosition.None && lines.TryGetValue(line, out styleValue) && styleValue.Equals(style)) { break; } else { position = MatchPosition.None; found = null; } } return(position); }
/// <summary> /// Returns all edges inside the given boundingbox. /// </summary> /// <param name="box"></param> /// <returns></returns> public KeyValuePair <uint, KeyValuePair <uint, CHEdgeData> >[] GetArcs( GeoCoordinateBox box) { // load the missing tiles. this.LoadMissingTile(box); // get all the vertices in the given box. IEnumerable <uint> vertices = _vertexIndex.GetInside( box); // loop over all vertices and get the arcs. var arcs = new List <KeyValuePair <uint, KeyValuePair <uint, CHEdgeData> > >(); foreach (uint vertexId in vertices) { var location = _coordinates[(int)vertexId]; if (location != null) { // load tile if needed. this.LoadMissingTile(new GeoCoordinate( location.Latitude, location.Longitude)); // get the arcs and return. if (_vertices.Length > vertexId) { var vertex = _vertices[(int)vertexId]; if (vertex != null && vertex.Arcs != null) { KeyValuePair <uint, CHEdgeData>[] localArcs = vertex.Arcs; foreach (KeyValuePair <uint, CHEdgeData> localArc in localArcs) { arcs.Add(new KeyValuePair <uint, KeyValuePair <uint, CHEdgeData> >( vertexId, localArc)); } } } } } return(arcs.ToArray()); }
/// <summary> /// Returns all arcs inside the given bounding box. /// </summary> /// <param name="box"></param> /// <returns></returns> public KeyValuePair <uint, KeyValuePair <uint, TEdgeData> >[] GetArcs( GeoCoordinateBox box) { // get all the vertices in the given box. IEnumerable <uint> vertices = _vertexIndex.GetInside( box); // loop over all vertices and get the arcs. var arcs = new List <KeyValuePair <uint, KeyValuePair <uint, TEdgeData> > >(); foreach (uint vertex in vertices) { KeyValuePair <uint, TEdgeData>[] localArcs = this.GetArcs(vertex); foreach (KeyValuePair <uint, TEdgeData> localArc in localArcs) { arcs.Add(new KeyValuePair <uint, KeyValuePair <uint, TEdgeData> >( vertex, localArc)); } } return(arcs.ToArray()); }
/// <summary> /// Returns all arcs inside the given bounding box. /// </summary> /// <param name="box"></param> /// <returns></returns> public override INeighbourEnumerator <TEdgeData> GetEdges( GeoCoordinateBox box) { if (_vertexIndex == null) { // rebuild on-the-fly. this.RebuildVertexIndex(); } // get all the vertices in the given box. var vertices = _vertexIndex.GetInside( box); // loop over all vertices and get the arcs. var neighbours = new List <Tuple <uint, uint, uint, TEdgeData> >(); foreach (uint vertexId in vertices) { var localArcs = this.GetEdges(vertexId); uint arcIdx = 0; while (localArcs.MoveNext()) { if (localArcs.EdgeData.RepresentsNeighbourRelations) { //if (localArcs.isInverted) //{ // neighbours.Add(new Tuple<uint, uint, uint, TEdgeData>(vertexId, localArcs.Neighbour, arcIdx, // (TEdgeData)localArcs.EdgeData.Reverse())); //} //else //{ // not inverted. neighbours.Add(new Tuple <uint, uint, uint, TEdgeData>(vertexId, localArcs.Neighbour, arcIdx, localArcs.EdgeData)); //} } arcIdx++; } } return(new NeighbourEnumerator(this, neighbours)); }
/// <summary> /// Returns all edges inside the given boundingbox. /// </summary> /// <param name="box"></param> /// <returns></returns> public INeighbourEnumerator <LiveEdge> GetEdges( GeoCoordinateBox box) { // load the missing tiles. this.LoadMissingTile(box); // get all the vertices in the given box. var vertices = _vertexIndex.GetInside(box); // loop over all vertices and get the arcs. var neighbours = new List <Tuple <uint, uint, uint, LiveEdge> >(); foreach (uint vertexId in vertices) { var location = _coordinates[(int)vertexId]; if (location != null) { //// load tile if needed. //this.LoadMissingTile(new GeoCoordinate( // location.Latitude, location.Longitude)); // get the arcs and return. if (_vertices.Length > vertexId) { var vertex = _vertices[(int)vertexId]; if (vertex != null && vertex.Arcs != null) { var localArcs = vertex.Arcs; for (int arcIdx = 0; arcIdx < vertex.Arcs.Length; arcIdx++) { neighbours.Add(new Tuple <uint, uint, uint, LiveEdge>(vertexId, (uint)arcIdx, localArcs[arcIdx].Item1, localArcs[arcIdx].Item2)); } } } } } return(new NeighbourEnumerator(this, neighbours)); }
/// <summary> /// Tests adding some simple data. /// </summary> protected void DoTestSimple() { // create the index. ILocatedObjectIndex <GeoCoordinate, LocatedObjectData> index = this.CreateIndex(); // add the data. GeoCoordinate point1 = new GeoCoordinate(0, 0); LocatedObjectData point1_data = new LocatedObjectData() { SomeData = point1.ToString() }; GeoCoordinate point2 = new GeoCoordinate(1, 1); LocatedObjectData point2_data = new LocatedObjectData() { SomeData = point2.ToString() }; GeoCoordinateBox location_box = new GeoCoordinateBox( new GeoCoordinate(point1.Latitude - 0.0001, point1.Longitude - 0.0001), new GeoCoordinate(point1.Latitude + 0.0001, point1.Longitude + 0.0001)); // try and get data from empty index. // regression test for issue: https://osmsharp.codeplex.com/workitem/1244 IEnumerable <LocatedObjectData> location_box_data = index.GetInside(location_box); Assert.IsNotNull(location_box_data); Assert.AreEqual(0, location_box_data.Count()); // try point1. index.Add(point1, point1_data); location_box_data = index.GetInside( location_box); Assert.IsNotNull(location_box_data); bool found = false; foreach (LocatedObjectData location_data in location_box_data) { if (location_data.SomeData == point1.ToString()) { found = true; } } Assert.IsTrue(found, string.Format("Data added at location {0} not found in box {1}!", point1, location_box)); // try point2. index.Add(point2, point2_data); location_box = new GeoCoordinateBox( new GeoCoordinate(point2.Latitude - 0.0001, point2.Longitude - 0.0001), new GeoCoordinate(point2.Latitude + 0.0001, point2.Longitude + 0.0001)); location_box_data = index.GetInside( location_box); Assert.IsNotNull(location_box_data); found = false; foreach (LocatedObjectData location_data in location_box_data) { if (location_data.SomeData == point2.ToString()) { found = true; } } Assert.IsTrue(found, string.Format("Data added at location {0} not found in box {1}!", point2, location_box)); }
/// <summary> /// Tests adding a lot of random data. /// </summary> /// <param name="count"></param> public void DoTestAddingRandom(int count) { ILocatedObjectIndex <GeoCoordinate, LocatedObjectData> index = this.CreateIndex(); GeoCoordinateBox box = new GeoCoordinateBox(new GeoCoordinate(50, 3), new GeoCoordinate(40, 2)); HashSet <GeoCoordinate> locations = new HashSet <GeoCoordinate>(); Random random = new Random(); while (count > 0) { GeoCoordinate location = box.GenerateRandomIn(random); LocatedObjectData data = new LocatedObjectData() { SomeData = location.ToString() }; locations.Add(location); index.Add(location, data); // try immidiately after. GeoCoordinateBox location_box = new GeoCoordinateBox( new GeoCoordinate(location.Latitude - 0.0001, location.Longitude - 0.0001), new GeoCoordinate(location.Latitude + 0.0001, location.Longitude + 0.0001)); IEnumerable <LocatedObjectData> location_box_data = index.GetInside( location_box); Assert.IsNotNull(location_box_data); bool found = false; foreach (LocatedObjectData location_data in location_box_data) { if (location_data.SomeData == location.ToString()) { found = true; } } Assert.IsTrue(found, string.Format("Data added at location {0} not found in box {1}!", location, location_box)); count--; } foreach (GeoCoordinate location in locations) { GeoCoordinateBox location_box = new GeoCoordinateBox( new GeoCoordinate(location.Latitude - 0.0001, location.Longitude - 0.0001), new GeoCoordinate(location.Latitude + 0.0001, location.Longitude + 0.0001)); IEnumerable <LocatedObjectData> location_box_data = index.GetInside( location_box); Assert.IsNotNull(location_box_data); bool found = false; foreach (LocatedObjectData location_data in location_box_data) { if (location_data.SomeData == location.ToString()) { found = true; } } Assert.IsTrue(found, string.Format("Data added at location {0} not found in box {1}!", location, location_box)); } }
/// <summary> /// Try and find matching lines. /// </summary> /// <param name="lines"></param> /// <param name="points"></param> /// <returns></returns> private MatchPosition FindMatch(ILocatedObjectIndex<PointF2D, Scene2D.ScenePoints> linesIndex, Dictionary<Scene2D.ScenePoints, Scene2DStylesSet> lines, double[] x, double[] y, Scene2DStylesSet style, float epsilon, out Scene2D.ScenePoints found) { // build box. var box = new BoxF2D(x, y); box = box.ResizeWith(epsilon * 1.1); // get all geometries in this box. var potentialMatches = linesIndex.GetInside(box); // find a match in the potential matches list. PointF2D first = new PointF2D(x[0], y[0]); PointF2D last = new PointF2D(x[x.Length - 1], y[y.Length - 1]); MatchPosition position = MatchPosition.None; found = null; foreach (var line in potentialMatches) { // check first. PointF2D potentialFirst = new PointF2D(line.X[0], line.Y[0]); PointF2D potentialLast = new PointF2D(line.X[line.X.Length - 1], line.Y[line.Y.Length - 1]); if (first.Distance(potentialFirst) < epsilon) { found = line; position = MatchPosition.FirstFirst; } else if (last.Distance(potentialFirst) < epsilon) { found = line; position = MatchPosition.LastFirst; } else if (first.Distance(potentialLast) < epsilon) { found = line; position = MatchPosition.FirstLast; } else if (last.Distance(potentialLast) < epsilon) { found = line; position = MatchPosition.LastLast; } Scene2DStylesSet styleValue; if (position != MatchPosition.None && lines.TryGetValue(line, out styleValue) && styleValue.Equals(style)) { break; } else { position = MatchPosition.None; found = null; } } return position; }