• 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
OsmTagTagHandler.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 
11 #include "OsmTagTagHandler.h"
12 
13 #include "OsmElementDictionary.h"
14 #include "OsmParser.h"
15 
16 #include "GeoDataDocument.h"
17 #include "GeoDataPlacemark.h"
18 #include "GeoDataParser.h"
19 #include "GeoDataLineString.h"
20 #include "GeoDataStyle.h"
21 
22 #include "MarbleDebug.h"
23 
24 namespace Marble
25 {
26 
27 namespace osm
28 {
29 static GeoTagHandlerRegistrar osmTagTagHandler( GeoParser::QualifiedName( osmTag_tag, "" ),
30  new OsmTagTagHandler() );
31 
32 static QStringList tagBlackList = QStringList() << "created_by";
33 
34 GeoNode* OsmTagTagHandler::parse( GeoParser &geoParser ) const
35 {
36  Q_ASSERT( dynamic_cast<OsmParser *>( &geoParser ) != 0 );
37  OsmParser &parser = static_cast<OsmParser &>( geoParser );
38 
39  Q_ASSERT( parser.isStartElement() );
40 
41  GeoStackItem parentItem = parser.parentElement();
42  GeoDataDocument* doc = geoDataDoc( parser );
43  QString key = parser.attribute( "k" );
44  QString value = parser.attribute( "v" );
45 
46  if ( tagBlackList.contains( key ) )
47  return 0;
48 
49  GeoDataGeometry * geometry = parentItem.nodeAs<GeoDataGeometry>();
50  if ( !geometry )
51  return 0;
52 
53  GeoDataGeometry *placemarkGeometry = geometry;
54 
55  //If node geometry is part of multigeometry -> go up to placemark geometry.
56  while( dynamic_cast<GeoDataMultiGeometry*>(placemarkGeometry->parent()) )
57  placemarkGeometry = dynamic_cast<GeoDataMultiGeometry*>(placemarkGeometry->parent());
58 
59  GeoDataPlacemark *placemark = dynamic_cast<GeoDataPlacemark*>(placemarkGeometry->parent());
60 
61  if ( key == "name" )
62  {
63  if ( !placemark )
64  {
65  if ( parentItem.represents( osmTag_node ) )
66  placemark = createPOI( doc, geometry );
67  else
68  return 0;
69  }
70  placemark->setName( value );
71  return 0;
72  }
73 
74  // Ways or relations can represent closed areas such as buildings
75  if ( parentItem.represents( osmTag_way ) || parentItem.represents( osmTag_relation ) )
76  {
77  Q_ASSERT( placemark );
78 
79  if( !dynamic_cast<GeoDataPolygon*>( geometry ) && parser.tagNeedArea( key + '=' + value ) ) {
80  //Convert area ways or relations to polygons
81  GeoDataLineString *polyline = dynamic_cast<GeoDataLineString *>( geometry );
82  Q_ASSERT( polyline );
83  doc->remove( doc->childPosition( placemark ) );
84  parser.addDummyPlacemark( placemark );
85  placemark = new GeoDataPlacemark( *placemark );
86  GeoDataPolygon *polygon = new GeoDataPolygon;
87  polygon->setOuterBoundary( *polyline );
88  //FIXME: Dirty hack to change placemark associated with node, for parsing purposes.
89  polyline->setParent( placemark );
90  placemark->setGeometry( polygon );
91  doc->append( placemark );
92  }
93  if ( key == "building" && value == "yes" && placemark->visualCategory() == GeoDataFeature::Default )
94  {
95  placemark->setVisualCategory( GeoDataFeature::Building );
96  placemark->setVisible( true );
97  }
98  }
99  else if ( parentItem.represents( osmTag_node ) ) //POI
100  {
101  GeoDataFeature::GeoDataVisualCategory poiCategory = GeoDataFeature::OsmVisualCategory( key + '=' + value );
102 
103  //Placemark is an accepted POI
104  if ( poiCategory )
105  {
106  if ( !placemark )
107  placemark = createPOI( doc, geometry );
108 
109  placemark->setVisible( true );
110  }
111  }
112 
113  if ( placemark )
114  {
115  GeoDataFeature::GeoDataVisualCategory category;
116 
117  if ( ( category = GeoDataFeature::OsmVisualCategory( key + '=' + value ) ) )
118  {
119  if( placemark->visualCategory() != GeoDataFeature::Default
120  && placemark->visualCategory() != GeoDataFeature::Building )
121  {
122  GeoDataPlacemark* newPlacemark = new GeoDataPlacemark( *placemark );
123  newPlacemark->setVisualCategory( category );
124  newPlacemark->setStyle( 0 );
125  newPlacemark->setVisible( true );
126  doc->append( newPlacemark );
127  }
128  else
129  {
130  //Remove assigned style (i.e. building style)
131  placemark->setStyle( 0 );
132  placemark->setVisualCategory( category );
133  placemark->setVisible( true );
134  }
135  }
136  else if ( ( category = GeoDataFeature::OsmVisualCategory( key ) ) )
137  {
138  if( placemark->visualCategory() != GeoDataFeature::Default )
139  {
140  GeoDataPlacemark* newPlacemark = new GeoDataPlacemark( *placemark );
141  newPlacemark->setVisualCategory( category );
142  newPlacemark->setStyle( 0 );
143  newPlacemark->setVisible( true );
144  doc->append( newPlacemark );
145  }
146  else
147  {
148  //Remove assigned style (i.e. building style)
149  placemark->setStyle( 0 );
150  placemark->setVisualCategory( category );
151  placemark->setVisible( true );
152  }
153  }
154  }
155 
156  return 0;
157 }
158 
159 GeoDataPlacemark* OsmTagTagHandler::createPOI( GeoDataDocument* doc, GeoDataGeometry* geometry )
160 {
161  GeoDataPoint *point = dynamic_cast<GeoDataPoint *>( geometry );
162  Q_ASSERT( point );
163  GeoDataPlacemark *placemark = new GeoDataPlacemark();
164  placemark->setGeometry( new GeoDataPoint( *point ) );
165  point->setParent( placemark );
166  placemark->setVisible( false );
167  placemark->setZoomLevel( 18 );
168  doc->append( placemark );
169  return placemark;
170 }
171 
172 }
173 
174 }
GeoDataDocument.h
Marble::GeoDataPoint
A Geometry object representing a 3d point.
Definition: GeoDataPoint.h:47
Marble::osm::osmTagTagHandler
static GeoTagHandlerRegistrar osmTagTagHandler(GeoParser::QualifiedName(osmTag_tag,""), new OsmTagTagHandler())
Marble::GeoDataFeature::OsmVisualCategory
static GeoDataVisualCategory OsmVisualCategory(const QString &keyValue)
Convenience categorization of placemarks for Osm key=value pairs.
Definition: GeoDataFeature.cpp:875
Marble::GeoDataDocument
A container for Features, Styles and in the future Schemas.
Definition: GeoDataDocument.h:65
Marble::OsmParser::tagNeedArea
bool tagNeedArea(const QString &keyValue) const
Definition: src/plugins/runner/osm/OsmParser.cpp:96
Marble::GeoDataFeature::setVisualCategory
void setVisualCategory(GeoDataVisualCategory category)
Sets the symbol index of the placemark.
Definition: GeoDataFeature.cpp:770
Marble::GeoNode
A shared base class for all classes that are mapped to a specific tag (ie.
Definition: GeoDocument.h:60
Marble::GeoDataFeature::Default
Definition: GeoDataFeature.h:79
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoParser::parentElement
GeoStackItem parentElement(unsigned int depth=0) const
Definition: GeoParser.cpp:122
Marble::osm::osmTag_node
const char * osmTag_node
Definition: OsmElementDictionary.cpp:23
QStringList::contains
bool contains(const QString &str, Qt::CaseSensitivity cs) const
Marble::GeoDataObject::parent
virtual GeoDataObject * parent() const
Provides the parent of the object in GeoDataContainers.
Definition: GeoDataObject.cpp:65
GeoDataStyle.h
OsmTagTagHandler.h
GeoDataParser.h
MarbleDebug.h
Marble::OsmParser::addDummyPlacemark
void addDummyPlacemark(GeoDataPlacemark *placemark)
Definition: src/plugins/runner/osm/OsmParser.cpp:101
Marble::GeoParser
Definition: GeoParser.h:40
Marble::GeoDataObject::setParent
virtual void setParent(GeoDataObject *parent)
Sets the parent of the object.
Definition: GeoDataObject.cpp:70
OsmElementDictionary.h
Marble::osm::OsmTagTagHandler::parse
virtual GeoNode * parse(GeoParser &) const
Definition: OsmTagTagHandler.cpp:34
Marble::GeoDataFeature::setName
void setName(const QString &value)
Set a new name for this feature.
Definition: GeoDataFeature.cpp:549
Marble::GeoParser::attribute
QString attribute(const char *attributeName) const
Definition: GeoParser.cpp:200
Marble::osm::osmTag_relation
const char * osmTag_relation
Definition: OsmElementDictionary.cpp:25
Marble::GeoDataPolygon
A polygon that can have "holes".
Definition: GeoDataPolygon.h:81
GeoDataLineString.h
Marble::osm::osmTag_way
const char * osmTag_way
Definition: OsmElementDictionary.cpp:24
Marble::GeoStackItem
Definition: GeoParser.h:97
QString
GeoDataPlacemark.h
Marble::GeoDataLineString
A LineString that allows to store a contiguous set of line segments.
Definition: GeoDataLineString.h:75
QStringList
Marble::GeoDataContainer::childPosition
int childPosition(const GeoDataFeature *child) const
returns the position of an item in the list
Definition: GeoDataContainer.cpp:252
Marble::GeoDataContainer::append
void append(GeoDataFeature *other)
add an element
Definition: GeoDataContainer.cpp:272
Marble::osm::osmTag_tag
const char * osmTag_tag
Definition: OsmElementDictionary.cpp:27
Marble::GeoDataFeature::setVisible
void setVisible(bool value)
Set a new value for visibility.
Definition: GeoDataFeature.cpp:661
QXmlStreamReader::isStartElement
bool isStartElement() const
Marble::GeoDataFeature::visualCategory
GeoDataVisualCategory visualCategory() const
Return the symbol index of the placemark.
Definition: GeoDataFeature.cpp:765
Marble::osm::tagBlackList
static QStringList tagBlackList
Definition: OsmTagTagHandler.cpp:32
Marble::GeoDataFeature::Building
Definition: GeoDataFeature.h:159
Marble::GeoDataContainer::remove
void remove(int index)
Definition: GeoDataContainer.cpp:280
Marble::GeoDataMultiGeometry
Definition: GeoDataMultiGeometry.h:33
Marble::OsmParser
Definition: src/plugins/runner/osm/OsmParser.h:29
Marble::GeoDataFeature::setZoomLevel
void setZoomLevel(int index)
Sets the popularity index of the placemark.
Definition: GeoDataFeature.cpp:802
Marble::GeoDataFeature::setStyle
void setStyle(GeoDataStyle *style)
Sets the style of the placemark.
Definition: GeoDataFeature.cpp:735
Marble::GeoDataFeature::GeoDataVisualCategory
GeoDataVisualCategory
A categorization of a placemark as defined by ...FIXME.
Definition: GeoDataFeature.h:77
Marble::GeoDataPlacemark
a class representing a point of interest on the map
Definition: GeoDataPlacemark.h:54
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
Marble::geoDataDoc
GeoDataDocument * geoDataDoc(GeoParser &parser)
Definition: GeoDataParser.cpp:105
Marble::GeoDataPlacemark::setGeometry
void setGeometry(GeoDataGeometry *entry)
Sets the current Geometry of this Placemark.
Definition: GeoDataPlacemark.cpp:230
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