• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdeedu API Reference
  • KDE Home
  • Contact Us
 

marble

  • sources
  • kde-4.14
  • kdeedu
  • marble
  • tools
  • osm-addresses
OsmRegionTree.cpp
Go to the documentation of this file.
1 //
2 // This file is part of the Marble Virtual Globe.
3 //
4 // This program is free software licensed under the GNU LGPL. You can
5 // find a copy of this license in LICENSE.txt in the top directory of
6 // the source code.
7 //
8 // Copyright 2011 Dennis Nienhüser <earthwings@gentoo.org>
9 //
10 
11 #include "OsmRegionTree.h"
12 
13 namespace Marble
14 {
15 
16 OsmRegionTree::OsmRegionTree( const OsmRegion & node ) :
17  m_node( node )
18 {
19  // nothing to do
20 }
21 
22 const OsmRegion &OsmRegionTree::node() const
23 {
24  return m_node;
25 }
26 
27 void OsmRegionTree::setChildren( const QVector<OsmRegionTree> children )
28 {
29  m_children = children;
30 }
31 
32 const QVector<OsmRegionTree> & OsmRegionTree::children() const
33 {
34  return m_children;
35 }
36 
37 void OsmRegionTree::append( QList<OsmRegion> &regions )
38 {
39  foreach( const OsmRegion &candidate, regions ) {
40  if ( candidate.parentIdentifier() == m_node.identifier() ) {
41  m_children << OsmRegionTree( candidate );
42  }
43  }
44 
45  foreach( const OsmRegionTree & child, m_children ) {
46  regions.removeAll( child.node() );
47  }
48 
49  for ( int i = 0; i < m_children.size(); ++i ) {
50  m_children[i].append( regions );
51  }
52 }
53 
54 void OsmRegionTree::traverse( int &counter )
55 {
56  ++counter;
57  m_node.setLeft( counter );
58 
59  for( int i = 0; i < m_children.size(); ++i ) {
60  m_children[i].traverse( counter );
61  }
62 
63  ++counter;
64  m_node.setRight( counter );
65 }
66 
67 OsmRegionTree::operator QList<OsmRegion>() const
68 {
69  QList<OsmRegion> result;
70  enumerate( result );
71  return result;
72 }
73 
74 void OsmRegionTree::enumerate( QList<OsmRegion> &list ) const
75 {
76  list << m_node;
77  foreach( const OsmRegionTree & child, m_children ) {
78  child.enumerate( list );
79  }
80 }
81 
82 int OsmRegionTree::smallestRegionId( const GeoDataCoordinates &coordinates ) const
83 {
84  int rootLevel = m_node.adminLevel();
85  return smallestRegionId( coordinates, rootLevel );
86 }
87 
88 int OsmRegionTree::smallestRegionId( const GeoDataCoordinates &coordinates, int &level ) const
89 {
90  int maxLevel = m_node.adminLevel();
91  int minId = m_node.identifier();
92  foreach( const OsmRegionTree & child, m_children ) {
93  if ( child.node().geometry().contains( coordinates ) ) {
94  int childLevel = level;
95  int id = child.smallestRegionId( coordinates, childLevel );
96  if ( childLevel >= maxLevel ) {
97  maxLevel = childLevel;
98  minId = id;
99  }
100  }
101  }
102 
103  level = maxLevel;
104  return minId;
105 }
106 
107 }
Marble::OsmRegionTree::OsmRegionTree
OsmRegionTree(const OsmRegion &node=OsmRegion())
Definition: OsmRegionTree.cpp:16
Marble::OsmRegionTree::setChildren
void setChildren(const QVector< OsmRegionTree > children)
Definition: OsmRegionTree.cpp:27
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::OsmRegion
A lightweight data structure to represent administrative regions like villages, cities, states, ...
Definition: OsmRegion.h:26
Marble::GeoDataPolygon::contains
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
Definition: GeoDataPolygon.cpp:196
Marble::OsmRegionTree::smallestRegionId
int smallestRegionId(const GeoDataCoordinates &coordinates) const
Definition: OsmRegionTree.cpp:82
Marble::OsmRegion::geometry
const GeoDataPolygon & geometry() const
Definition: OsmRegion.cpp:102
Marble::OsmRegionTree
Definition: OsmRegionTree.h:21
Marble::OsmRegionTree::append
void append(QList< OsmRegion > &regions)
Definition: OsmRegionTree.cpp:37
Marble::OsmRegion::setLeft
void setLeft(int left)
Definition: OsmRegion.cpp:82
Marble::OsmRegion::setRight
void setRight(int right)
Definition: OsmRegion.cpp:92
OsmRegionTree.h
QList::removeAll
int removeAll(const T &value)
Marble::OsmRegionTree::children
const QVector< OsmRegionTree > & children() const
Definition: OsmRegionTree.cpp:32
QList
Marble::OsmRegion::parentIdentifier
int parentIdentifier() const
Definition: OsmRegion.cpp:37
Marble::OsmRegionTree::traverse
void traverse(int &counter)
Definition: OsmRegionTree.cpp:54
QVector
Marble::OsmRegion::identifier
int identifier() const
Unique (per process) region identifier.
Definition: OsmRegion.cpp:27
Marble::OsmRegionTree::node
const OsmRegion & node() const
Definition: OsmRegionTree.cpp:22
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:13:41 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

marble

Skip menu "marble"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdeedu API Reference

Skip menu "kdeedu API Reference"
  • Analitza
  •     lib
  • kalgebra
  • kalzium
  •   libscience
  • kanagram
  • kig
  •   lib
  • klettres
  • marble
  • parley
  • rocs
  •   App
  •   RocsCore
  •   VisualEditor
  •   stepcore

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal