• 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
  • src
  • plugins
  • runner
  • osm
  • handlers
OsmMemberTagHandler.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 Konstantin Oblaukhov <oblaukhov.konstantin@gmail.com>
9 
10  Copyright 2012 Ander Pijoan <ander.pijoan@deusto.es>
11 */
12 
13 #include "OsmMemberTagHandler.h"
14 
15 #include "OsmParser.h"
16 #include "OsmElementDictionary.h"
17 
18 #include "GeoDataParser.h"
19 #include "GeoDataPolygon.h"
20 
21 #include "MarbleDebug.h"
22 
23 namespace Marble
24 {
25 
26 namespace osm
27 {
28 
29 static GeoTagHandlerRegistrar osmMemberTagHandler( GeoParser::QualifiedName( osmTag_member, "" ),
30  new OsmMemberTagHandler() );
31 
32 GeoNode* OsmMemberTagHandler::parse( GeoParser &geoParser ) const
33 {
34  // Relations members examples
35  // http://wiki.openstreetmap.org/wiki/Relation:multipolygon#Examples
36 
37  Q_ASSERT( dynamic_cast<OsmParser *>( &geoParser ) );
38  OsmParser &parser = static_cast<OsmParser &>( geoParser );
39 
40  Q_ASSERT( parser.isStartElement() );
41 
42  GeoStackItem parentItem = parser.parentElement();
43 
44  if ( parentItem.represents( osmTag_relation ) )
45  {
46  // Never heard of a type different from "way" but
47  // maybe it should be checked
48 
49  if (parser.attribute( "type" ) == "way")
50  {
51  // Outer poligons (sometimes the role is empty)
52  if (parser.attribute( "role" ) == "outer" || parser.attribute( "role" ) == "")
53  {
54 
55  GeoDataPolygon *polygon = parentItem.nodeAs<GeoDataPolygon>();
56  Q_ASSERT( polygon );
57  quint64 id = parser.attribute( "ref" ).toULongLong();
58 
59  // With the id we get the way geometry
60  if ( GeoDataLineString *line = parser.way( id ) )
61  {
62  // Some of the ways that build the relation
63  // might be in opposite directions
64  // so the final linearRing would be wrong.
65  // It is needed to seek in the linearRing
66  // to know if the new way should be added
67  // at the beginning or end and in which order.
68  // Also the shared node (which will be in both
69  // geometries) has to be removed to avoid having
70  // it repeated.
71 
72  GeoDataLinearRing envelope = polygon->outerBoundary();
73 
74  // Case 0: envelope is empty
75  if ( envelope.isEmpty() )
76  {
77  envelope = *line;
78  }
79 
80  // Case 1: line.first = envelope.first
81  else if ( line->first() == envelope.first() )
82  {
83  GeoDataLinearRing temp = GeoDataLinearRing( envelope.tessellationFlags() );
84 
85  // Invert envelopes direction
86  for (int x = envelope.size()-1; x > -1; x--)
87  {
88  temp.append( GeoDataCoordinates ( envelope.at(x) ) );
89  }
90  envelope = temp;
91 
92  // Now its the same as case 2
93  // envelope-last not to repeat the shared node
94  envelope.remove( envelope.size() - 1 );
95  envelope << *line;
96  }
97 
98  // Case 2: line.first = envelope.last
99  else if (line->first() == envelope.last() )
100  {
101  // envelope-last not to repeat the shared node
102  envelope.remove( envelope.size() - 1 );
103  envelope << *line;
104  }
105 
106  // Case 3: line.last = envelope.first
107  else if (line->last() == envelope.first() )
108  {
109  GeoDataLinearRing temp = GeoDataLinearRing( envelope.tessellationFlags() );
110 
111  // Invert envelopes direction
112  for (int x = envelope.size()-1; x > -1; x--)
113  {
114  temp.append( GeoDataCoordinates ( envelope.at(x) ) );
115  }
116  envelope = temp;
117 
118  // Now its the same as case 4
119  // size-2 not to repeat the shared node
120  for (int x = line->size()-2; x > -1; x--)
121  {
122  envelope.append( GeoDataCoordinates ( line->at(x) ) );
123  }
124  }
125 
126  // Case 4: line.last = envelope.last
127  else if (line->last() == envelope.last() )
128  {
129  // size-2 not to repeat the shared node
130  for (int x = line->size()-2; x > -1; x--)
131  {
132  envelope.append( GeoDataCoordinates ( line->at(x) ) );
133  }
134  }
135 
136  // Update the outer boundary
137  polygon->setOuterBoundary( envelope );
138  }
139  }
140 
141  // Inner poligons
142  if (parser.attribute( "role" ) == "inner")
143  {
144  GeoDataPolygon *polygon = parentItem.nodeAs<GeoDataPolygon>();
145  Q_ASSERT( polygon );
146  quint64 id = parser.attribute( "ref" ).toULongLong();
147 
148  // With the id we get the way geometry
149  if ( GeoDataLineString *line = parser.way( id ) )
150  {
151  polygon->appendInnerBoundary( GeoDataLinearRing( *line ) );
152  }
153  }
154  }
155 
156  else if (parser.attribute( "type" ) == "relation")
157  {
158  // Never seen this case
159  if ( parser.attribute( "role" ) == "outer" )
160  {
161  mDebug() << "Parsed relation with a relation outer member";
162  }
163 
164  // It only can be an inner relation or subarea
165  // Subarea is mainly used for administrative boundaries
166  else if (parser.attribute( "role" ) == "inner"
167  || parser.attribute( "role" ) == "subarea"
168  || parser.attribute( "role" ) == "")
169  {
170  GeoDataPolygon *polygon = parentItem.nodeAs<GeoDataPolygon>();
171  Q_ASSERT( polygon );
172  quint64 id = parser.attribute( "ref" ).toULongLong();
173 
174  // With the id we get the relation geometry
175  if ( GeoDataPolygon *p = parser.polygon( id ) )
176  {
177  polygon->appendInnerBoundary( p->outerBoundary() );
178  }
179  }
180  }
181 
182  return 0;
183  }
184 
185  return 0;
186 }
187 
188 }
189 
190 }
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataLineString::last
GeoDataCoordinates & last()
Returns a reference to the last node in the LineString. This method detaches the returned coordinate ...
Definition: GeoDataLineString.cpp:169
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
GeoDataPolygon.h
Marble::osm::osmMemberTagHandler
static GeoTagHandlerRegistrar osmMemberTagHandler(GeoParser::QualifiedName(osmTag_member,""), new OsmMemberTagHandler())
Marble::GeoNode
A shared base class for all classes that are mapped to a specific tag (ie.
Definition: GeoDocument.h:60
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:138
Marble::GeoParser::parentElement
GeoStackItem parentElement(unsigned int depth=0) const
Definition: GeoParser.cpp:122
GeoDataParser.h
Marble::OsmParser::polygon
GeoDataPolygon * polygon(quint64 id)
Definition: src/plugins/runner/osm/OsmParser.cpp:91
MarbleDebug.h
Marble::GeoDataLineString::tessellationFlags
TessellationFlags tessellationFlags() const
Returns the tessellation flags for a LineString.
Definition: GeoDataLineString.cpp:337
Marble::GeoParser
Definition: GeoParser.h:40
OsmElementDictionary.h
Marble::GeoParser::attribute
QString attribute(const char *attributeName) const
Definition: GeoParser.cpp:200
OsmMemberTagHandler.h
Marble::osm::osmTag_relation
const char * osmTag_relation
Definition: OsmElementDictionary.cpp:25
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
Marble::GeoDataLineString::first
GeoDataCoordinates & first()
Returns a reference to the first node in the LineString. This method detaches the returned coordinate...
Definition: GeoDataLineString.cpp:177
Marble::GeoStackItem
Definition: GeoParser.h:97
QString::toULongLong
qulonglong toULongLong(bool *ok, int base) const
Marble::GeoDataLineString::append
void append(const GeoDataCoordinates &position)
Appends a given geodesic position as a new node to the LineString.
Definition: GeoDataLineString.cpp:225
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
Marble::GeoDataPolygon::outerBoundary
GeoDataLinearRing & outerBoundary()
Returns the outer boundary that is represented as a LinearRing.
Definition: GeoDataPolygon.cpp:123
Marble::GeoDataLineString::at
GeoDataCoordinates & at(int pos)
Returns a reference to the coordinates of a node at a given position. This method detaches the return...
Definition: GeoDataLineString.cpp:143
Marble::GeoDataPolygon::appendInnerBoundary
void appendInnerBoundary(const GeoDataLinearRing &boundary)
Appends a given LinearRing as an inner boundary of the Polygon.
Definition: GeoDataPolygon.cpp:149
Marble::GeoDataLineString::remove
void remove(int i)
Removes the node at the given position and destroys it.
Definition: GeoDataLineString.cpp:635
QXmlStreamReader::isStartElement
bool isStartElement() const
Marble::OsmParser::way
GeoDataLineString * way(quint64 id)
Definition: src/plugins/runner/osm/OsmParser.cpp:81
Marble::GeoDataLineString::isEmpty
bool isEmpty() const
Returns whether the LineString has no nodes at all.
Definition: GeoDataLineString.cpp:133
Marble::osm::OsmMemberTagHandler::parse
virtual GeoNode * parse(GeoParser &) const
Definition: OsmMemberTagHandler.cpp:32
Marble::osm::osmTag_member
const char * osmTag_member
Definition: OsmElementDictionary.cpp:26
Marble::OsmParser
Definition: src/plugins/runner/osm/OsmParser.h:29
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:36
Marble::GeoParser::QualifiedName
QPair< QString, QString > QualifiedName
Definition: GeoParser.h:43
Marble::GeoDataPolygon::setOuterBoundary
void setOuterBoundary(const GeoDataLinearRing &boundary)
Sets the given LinearRing as an outer boundary of the Polygon.
Definition: GeoDataPolygon.cpp:133
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