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

marble

  • sources
  • kde-4.12
  • 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 "GeoParser.h"
16 #include "OsmWayFactory.h"
17 #include "OsmRelationFactory.h"
18 #include "GeoDataParser.h"
19 #include "GeoDataPolygon.h"
20 #include "OsmElementDictionary.h"
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& parser ) const
33 {
34  // Relations members examples
35  // http://wiki.openstreetmap.org/wiki/Relation:multipolygon#Examples
36 
37  Q_ASSERT( parser.isStartElement() );
38 
39  GeoStackItem parentItem = parser.parentElement();
40 
41  if ( parentItem.represents( osmTag_relation ) )
42  {
43  // Never heard of a type different from "way" but
44  // maybe it should be checked
45 
46  if (parser.attribute( "type" ) == "way")
47  {
48  // Outer poligons (sometimes the role is empty)
49  if (parser.attribute( "role" ) == "outer" || parser.attribute( "role" ) == "")
50  {
51 
52  GeoDataPolygon *polygon = parentItem.nodeAs<GeoDataPolygon>();
53  Q_ASSERT( polygon );
54  quint64 id = parser.attribute( "ref" ).toULongLong();
55 
56  // With the id we get the way geometry
57  if ( GeoDataLineString *line = osm::OsmWayFactory::line( id ) )
58  {
59  // Some of the ways that build the relation
60  // might be in opposite directions
61  // so the final linearRing would be wrong.
62  // It is needed to seek in the linearRing
63  // to know if the new way should be added
64  // at the beginning or end and in which order.
65  // Also the shared node (which will be in both
66  // geometries) has to be removed to avoid having
67  // it repeated.
68 
69  GeoDataLinearRing envelope = polygon->outerBoundary();
70 
71  // Case 0: envelope is empty
72  if ( envelope.isEmpty() )
73  {
74  envelope = *line;
75  }
76 
77  // Case 1: line.first = envelope.first
78  else if ( line->first() == envelope.first() )
79  {
80  GeoDataLinearRing temp = GeoDataLinearRing( envelope.tessellationFlags() );
81 
82  // Invert envelopes direction
83  for (int x = envelope.size()-1; x > -1; x--)
84  {
85  temp.append( GeoDataCoordinates ( envelope.at(x) ) );
86  }
87  envelope = temp;
88 
89  // Now its the same as case 2
90  // envelope-last not to repeat the shared node
91  envelope.remove( envelope.size() - 1 );
92  envelope << *line;
93  }
94 
95  // Case 2: line.first = envelope.last
96  else if (line->first() == envelope.last() )
97  {
98  // envelope-last not to repeat the shared node
99  envelope.remove( envelope.size() - 1 );
100  envelope << *line;
101  }
102 
103  // Case 3: line.last = envelope.first
104  else if (line->last() == envelope.first() )
105  {
106  GeoDataLinearRing temp = GeoDataLinearRing( envelope.tessellationFlags() );
107 
108  // Invert envelopes direction
109  for (int x = envelope.size()-1; x > -1; x--)
110  {
111  temp.append( GeoDataCoordinates ( envelope.at(x) ) );
112  }
113  envelope = temp;
114 
115  // Now its the same as case 4
116  // size-2 not to repeat the shared node
117  for (int x = line->size()-2; x > -1; x--)
118  {
119  envelope.append( GeoDataCoordinates ( line->at(x) ) );
120  }
121  }
122 
123  // Case 4: line.last = envelope.last
124  else if (line->last() == envelope.last() )
125  {
126  // size-2 not to repeat the shared node
127  for (int x = line->size()-2; x > -1; x--)
128  {
129  envelope.append( GeoDataCoordinates ( line->at(x) ) );
130  }
131  }
132 
133  // Update the outer boundary
134  polygon->setOuterBoundary( envelope );
135  }
136  }
137 
138  // Inner poligons
139  if (parser.attribute( "role" ) == "inner")
140  {
141  GeoDataPolygon *polygon = parentItem.nodeAs<GeoDataPolygon>();
142  Q_ASSERT( polygon );
143  quint64 id = parser.attribute( "ref" ).toULongLong();
144 
145  // With the id we get the way geometry
146  if ( GeoDataLineString *line = osm::OsmWayFactory::line( id ) )
147  {
148  polygon->appendInnerBoundary( GeoDataLinearRing( *line ) );
149  }
150  }
151  }
152 
153  else if (parser.attribute( "type" ) == "relation")
154  {
155  // Never seen this case
156  if ( parser.attribute( "role" ) == "outer" )
157  {
158  mDebug() << "Parsed relation with a relation outer member";
159  }
160 
161  // It only can be an inner relation or subarea
162  // Subarea is mainly used for administrative boundaries
163  else if (parser.attribute( "role" ) == "inner"
164  || parser.attribute( "role" ) == "subarea"
165  || parser.attribute( "role" ) == "")
166  {
167  GeoDataPolygon *polygon = parentItem.nodeAs<GeoDataPolygon>();
168  Q_ASSERT( polygon );
169  quint64 id = parser.attribute( "ref" ).toULongLong();
170 
171  // With the id we get the relation geometry
172  if ( GeoDataPolygon *p = osm::OsmRelationFactory::polygon( id ) )
173  {
174  polygon->appendInnerBoundary( p->outerBoundary() );
175  }
176  }
177  }
178 
179  return 0;
180  }
181 
182  return 0;
183 }
184 
185 }
186 
187 }
OsmRelationFactory.h
Marble::osm::OsmWayFactory::line
static GeoDataLineString * line(quint64 id)
Definition: OsmWayFactory.cpp:31
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:165
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
GeoParser.h
Marble::GeoDataLineString::size
int size() const
Returns the number of nodes in a LineString.
Definition: GeoDataLineString.cpp:134
Marble::GeoParser::parentElement
GeoStackItem parentElement(unsigned int depth=0) const
Definition: GeoParser.cpp:122
OsmWayFactory.h
GeoDataParser.h
MarbleDebug.h
Marble::GeoDataLineString::tessellationFlags
TessellationFlags tessellationFlags() const
Returns the tessellation flags for a LineString.
Definition: GeoDataLineString.cpp:302
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:173
Marble::GeoStackItem
Definition: GeoParser.h:97
Marble::GeoDataLineString::append
void append(const GeoDataCoordinates &position)
Appends a given geodesic position as a new node to the LineString.
Definition: GeoDataLineString.cpp:221
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:85
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:139
Marble::GeoDataPolygon::appendInnerBoundary
void appendInnerBoundary(const GeoDataLinearRing &boundary)
Appends a given LinearRing as an inner boundary of the Polygon.
Definition: GeoDataPolygon.cpp:111
Marble::GeoDataLineString::remove
void remove(int i)
Removes the node at the given position and destroys it.
Definition: GeoDataLineString.cpp:600
Marble::GeoDataLineString::isEmpty
bool isEmpty() const
Returns whether the LineString has no nodes at all.
Definition: GeoDataLineString.cpp:129
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::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
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:95
Marble::osm::OsmRelationFactory::polygon
static GeoDataPolygon * polygon(quint64 id)
Definition: OsmRelationFactory.cpp:32
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:52 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
  • kstars
  • libkdeedu
  •   keduvocdocument
  • 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