/// <summary> /// Fills the scene with objects from the given datasource that existing inside the given boundingbox with the given projection. /// </summary> /// <param name="dataSource"></param> /// <param name="box"></param> /// <param name="projection"></param> public void FillScene(IDataSourceReadOnly dataSource, GeoCoordinateBox box, IProjection projection) { foreach (var osmGeo in dataSource.Get(box, null)) { // translate each object into scene object. LongIndex index = null; switch (osmGeo.Type) { case Osm.OsmGeoType.Node: index = _interpretedNodes; break; case Osm.OsmGeoType.Way: index = _interpretedWays; break; case Osm.OsmGeoType.Relation: index = _interpretedRelations; break; } if (!index.Contains(osmGeo.Id.Value)) { // object was not yet interpreted. index.Add(osmGeo.Id.Value); _interpreter.Translate(_scene, projection, dataSource, osmGeo); } } }
/// <summary> /// Moves to the next item. /// </summary> /// <returns></returns> public bool MoveNext() { if (_current == null) { _current = this.FindHighest(); _index.Add(_current.Vertex); _currentCount = 1; return(_current != null); } // search for the next arc. KeyValuePair <uint, CHEdgeData>[] edges = _graph.GetEdges(_current.Vertex); int arcIdx = _current.ArcIdx; arcIdx++; while (arcIdx < edges.Length) { // check if it is 'lower'. if (edges[arcIdx].Value.ToLower && !_index.Contains(edges[arcIdx].Key)) { // yes the arc is 'lower' take it! _current.ArcIdx = arcIdx; // move the arcIdx. Position newPosition = new Position(); newPosition.Parent = _current; newPosition.ArcIdx = -1; newPosition.Vertex = edges[arcIdx].Key; newPosition.Depth = _current.Depth + 1; _current = newPosition; _index.Add(_current.Vertex); _currentCount++; return(true); } arcIdx++; // move to the next arc. } // move to parent. if (_current.Parent != null) { // set parent as current and move next. _current = _current.Parent; return(this.MoveNext()); } // also enumerate all the other 'islands' of vertices unconnected to the current vertices. return(this.MoveToNextIsland()); }
/// <summary> /// Moves to the next object. /// </summary> /// <returns></returns> public override bool MoveNext() { if (!_includeExtraMode) { // just go over all nodes and ways. if (this.Source.MoveNext()) { bool finished = false; bool isIn = false; // move to the next object of the current type. while (this.Current().Type != _currentType) { if (!this.Source.MoveNext()) { finished = true; break; } } if (!finished) { while (this.Current().Type == _currentType && !isIn) { OsmGeo current = this.Source.Current(); isIn = this.IsInBB(current); // check and keep the extras. if (isIn) { // add to the actual in-boundingbox indexes. switch (current.Type) { case OsmGeoType.Node: _nodesIn.Add(current.Id.Value); break; case OsmGeoType.Way: _waysIn.Add(current.Id.Value); break; case OsmGeoType.Relation: _relationIn.Add(current.Id.Value); break; } break; } // move to the next object of the current type. if (!this.Source.MoveNext()) { finished = true; break; } while (this.Current().Type != _currentType) { if (!this.Source.MoveNext()) { finished = true; break; } } // stop when finished. if (finished) { break; } } } if (!finished && this.Current().Type == _currentType) { // nothing was finished and the types match. return(true); } } // switch to the next mode. switch (_currentType) { case OsmGeoType.Node: this.Source.Reset(); _currentType = OsmGeoType.Way; return(this.MoveNext()); case OsmGeoType.Way: this.Source.Reset(); _currentType = OsmGeoType.Relation; return(this.MoveNext()); case OsmGeoType.Relation: this.Source.Reset(); _includeExtraMode = true; return(this.MoveNext()); } throw new InvalidOperationException("Unkown SimpleOsmGeoType"); } else { while (this.Source.MoveNext()) { switch (this.Source.Current().Type) { case OsmGeoType.Node: if (_nodesToInclude.Contains(this.Source.Current().Id.Value)) { if (!_nodesIn.Contains(this.Source.Current().Id.Value)) { return(true); } } break; case OsmGeoType.Way: if (_waysToInclude.Contains(this.Source.Current().Id.Value)) { if (!_waysIn.Contains(this.Source.Current().Id.Value)) { return(true); } } break; case OsmGeoType.Relation: if (_relationsToInclude.Contains(this.Source.Current().Id.Value)) { if (!_relationIn.Contains(this.Source.Current().Id.Value)) { return(true); } } break; } } return(false); } }
/// <summary> /// Moves to the next object. /// </summary> /// <returns></returns> private bool DoMoveNext() { while (this.Source.MoveNext()) { // check the type and check if the source is sorted. var current = this.Source.Current(); switch (current.Type) { case OsmGeoType.Node: if (_currentType != OsmGeoType.Node) { // source is not sorted, a node appeared after a way/relation. throw new OsmStreamNotSortedException("OsmStreamFilterPoly - Source stream is not sorted."); } var node = current as Node; if (this.IsInsidePoly(node.Latitude.Value, node.Longitude.Value)) { // keep this node. _nodesIn.Add(node.Id.Value); return(true); } break; case OsmGeoType.Way: if (_currentType == OsmGeoType.Relation) { // source is not sorted, a way appeared after a relation. throw new OsmStreamNotSortedException("OsmStreamFilterPoly - Source stream is not sorted."); } if (_currentType == OsmGeoType.Node) { // switch type to way. _currentType = OsmGeoType.Way; } var way = current as Way; if (way.Nodes != null) { for (var i = 0; i < way.Nodes.Count; i++) { if (_nodesIn.Contains(way.Nodes[i])) { _waysIn.Add(way.Id.Value); return(true); } } } break; case OsmGeoType.Relation: if (_currentType == OsmGeoType.Way || _currentType == OsmGeoType.Node) { // switch type to way. _currentType = OsmGeoType.Relation; } var relation = current as Relation; if (relation.Members != null) { for (var i = 0; i < relation.Members.Count; i++) { var member = relation.Members[i]; switch (member.MemberType.Value) { case OsmGeoType.Node: if (_nodesIn.Contains(member.MemberId.Value)) { return(true); } break; case OsmGeoType.Way: if (_waysIn.Contains(member.MemberId.Value)) { return(true); } break; } } } break; } } return(false); }