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