• 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
  • lib
  • marble
  • geodata
  • data
GeoDataPolygon.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 2008-2009 Patrick Spendrin <ps_ml@gmx.de>
9 // Copyright 2008 Inge Wallin <inge@lysator.liu.se>
10 //
11 
12 
13 #include "GeoDataPolygon.h"
14 #include "GeoDataPolygon_p.h"
15 
16 #include "MarbleDebug.h"
17 
18 
19 namespace Marble
20 {
21 
22 GeoDataPolygon::GeoDataPolygon( TessellationFlags f )
23  : GeoDataGeometry( new GeoDataPolygonPrivate( f ) )
24 {
25 }
26 
27 GeoDataPolygon::GeoDataPolygon( const GeoDataGeometry & other )
28  : GeoDataGeometry( other )
29 {
30 }
31 
32 GeoDataPolygon::~GeoDataPolygon()
33 {
34 #ifdef DEBUG_GEODATA
35  mDebug() << "delete polygon";
36 #endif
37 }
38 
39 GeoDataPolygonPrivate* GeoDataPolygon::p() const
40 {
41  return static_cast<GeoDataPolygonPrivate*>(d);
42 }
43 
44 bool GeoDataPolygon::isClosed() const
45 {
46  return true;
47 }
48 
49 bool GeoDataPolygon::tessellate() const
50 {
51  return p()->m_tessellationFlags.testFlag(Tessellate);
52 }
53 
54 void GeoDataPolygon::setTessellate( bool tessellate )
55 {
56  // According to the KML reference the tesselation is done along great circles
57  // for polygons in Google Earth. Our "Tesselate" flag does this.
58  // Only for pure line strings and linear rings the
59  // latitude circles are followed for subsequent points that share the same latitude.
60  GeoDataGeometry::detach();
61 
62  if ( tessellate ) {
63  p()->m_tessellationFlags |= Tessellate;
64  } else {
65  p()->m_tessellationFlags ^= Tessellate;
66  }
67 }
68 
69 TessellationFlags GeoDataPolygon::tessellationFlags() const
70 {
71  return p()->m_tessellationFlags;
72 }
73 
74 void GeoDataPolygon::setTessellationFlags( TessellationFlags f )
75 {
76  GeoDataGeometry::detach();
77  p()->m_tessellationFlags = f;
78 }
79 
80 const GeoDataLatLonAltBox& GeoDataPolygon::latLonAltBox() const
81 {
82  return p()->outer.latLonAltBox();
83 }
84 
85 GeoDataLinearRing &GeoDataPolygon::outerBoundary()
86 {
87  return (p()->outer);
88 }
89 
90 const GeoDataLinearRing &GeoDataPolygon::outerBoundary() const
91 {
92  return (p()->outer);
93 }
94 
95 void GeoDataPolygon::setOuterBoundary( const GeoDataLinearRing& boundary )
96 {
97  GeoDataGeometry::detach();
98  p()->outer = boundary;
99 }
100 
101 QVector<GeoDataLinearRing>& GeoDataPolygon::innerBoundaries()
102 {
103  return p()->inner;
104 }
105 
106 const QVector<GeoDataLinearRing>& GeoDataPolygon::innerBoundaries() const
107 {
108  return p()->inner;
109 }
110 
111 void GeoDataPolygon::appendInnerBoundary( const GeoDataLinearRing& boundary )
112 {
113  GeoDataGeometry::detach();
114  p()->inner.append( boundary );
115 }
116 
117 void GeoDataPolygon::pack( QDataStream& stream ) const
118 {
119  GeoDataObject::pack( stream );
120 
121  p()->outer.pack( stream );
122 
123  stream << p()->inner.size();
124  stream << (qint32)(p()->m_tessellationFlags);
125 
126  for( QVector<GeoDataLinearRing>::const_iterator iterator
127  = p()->inner.constBegin();
128  iterator != p()->inner.constEnd();
129  ++iterator ) {
130  mDebug() << "innerRing: size" << p()->inner.size();
131  GeoDataLinearRing linearRing = ( *iterator );
132  linearRing.pack( stream );
133  }
134 }
135 
136 void GeoDataPolygon::unpack( QDataStream& stream )
137 {
138  GeoDataGeometry::detach();
139  GeoDataObject::unpack( stream );
140 
141  p()->outer.unpack( stream );
142 
143  qint32 size;
144  qint32 tessellationFlags;
145 
146  stream >> size;
147  stream >> tessellationFlags;
148 
149  p()->m_tessellationFlags = (TessellationFlags)(tessellationFlags);
150 
151  for(qint32 i = 0; i < size; i++ ) {
152  GeoDataLinearRing linearRing;
153  linearRing.unpack( stream );
154  p()->inner.append( linearRing );
155  }
156 }
157 
158 bool GeoDataPolygon::contains( const GeoDataCoordinates &coordinates ) const
159 {
160  if ( !outerBoundary().contains( coordinates ) ) {
161  // Not inside the polygon at all
162  return false;
163  }
164 
165  foreach( const GeoDataLinearRing &ring, innerBoundaries() ) {
166  if ( ring.contains( coordinates ) ) {
167  // Inside the polygon, but in one of its holes
168  return false;
169  }
170  }
171 
172  return true;
173 }
174 
175 }
Marble::GeoDataCoordinates
A 3d point representation.
Definition: GeoDataCoordinates.h:52
Marble::GeoDataLinearRing
A LinearRing that allows to store a closed, contiguous set of line segments.
Definition: GeoDataLinearRing.h:68
Marble::GeoDataPolygon::contains
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
Definition: GeoDataPolygon.cpp:158
Marble::GeoDataLinearRing::contains
virtual bool contains(const GeoDataCoordinates &coordinates) const
Returns whether the given coordinates lie within the polygon.
Definition: GeoDataLinearRing.cpp:47
Marble::GeoDataPolygon::GeoDataPolygon
GeoDataPolygon(TessellationFlags f=Tessellate)
Creates a new Polygon.
Definition: GeoDataPolygon.cpp:22
GeoDataPolygon.h
Marble::GeoDataPolygon::pack
virtual void pack(QDataStream &stream) const
Serialize the Polygon to a stream.
Definition: GeoDataPolygon.cpp:117
Marble::GeoDataGeometry
A base class for all geodata features.
Definition: GeoDataGeometry.h:47
Marble::GeoDataPolygon::tessellate
bool tessellate() const
Returns whether the Polygon follows the earth's surface.
Definition: GeoDataPolygon.cpp:49
Marble::GeoDataObject::pack
virtual void pack(QDataStream &stream) const
Reimplemented from Serializable.
Definition: GeoDataObject.cpp:114
Marble::GeoDataGeometry::detach
void detach()
Definition: GeoDataGeometry.cpp:54
GeoDataPolygon_p.h
Marble::GeoDataLineString::unpack
virtual void unpack(QDataStream &stream)
Unserialize the LineString from a stream.
Definition: GeoDataLineString.cpp:627
Marble::GeoDataPolygon::setTessellate
void setTessellate(bool tessellate)
Sets the tessellation property for the Polygon.
Definition: GeoDataPolygon.cpp:54
MarbleDebug.h
Marble::GeoDataPolygonPrivate::m_tessellationFlags
TessellationFlags m_tessellationFlags
Definition: GeoDataPolygon_p.h:57
Marble::GeoDataPolygon::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the Polygon.
Definition: GeoDataPolygon.cpp:80
Marble::GeoDataPolygon::p
GeoDataPolygonPrivate * p() const
Definition: GeoDataPolygon.cpp:39
Marble::GeoDataPolygonPrivate
Definition: GeoDataPolygon_p.h:21
Marble::GeoDataPolygon::outerBoundary
GeoDataLinearRing & outerBoundary()
Returns the outer boundary that is represented as a LinearRing.
Definition: GeoDataPolygon.cpp:85
Marble::GeoDataPolygon::~GeoDataPolygon
virtual ~GeoDataPolygon()
Destroys a Polygon.
Definition: GeoDataPolygon.cpp:32
Marble::GeoDataLineString::pack
virtual void pack(QDataStream &stream) const
Serialize the LineString to a stream.
Definition: GeoDataLineString.cpp:609
Marble::GeoDataPolygon::appendInnerBoundary
void appendInnerBoundary(const GeoDataLinearRing &boundary)
Appends a given LinearRing as an inner boundary of the Polygon.
Definition: GeoDataPolygon.cpp:111
Marble::GeoDataPolygon::unpack
virtual void unpack(QDataStream &stream)
Unserialize the Polygon from a stream.
Definition: GeoDataPolygon.cpp:136
Marble::GeoDataPolygon::innerBoundaries
QVector< GeoDataLinearRing > & innerBoundaries()
Returns a set of inner boundaries which are represented as LinearRings.
Definition: GeoDataPolygon.cpp:101
Marble::GeoDataPolygon::isClosed
virtual bool isClosed() const
Returns whether a Polygon is a closed polygon.
Definition: GeoDataPolygon.cpp:44
Marble::GeoDataObject::unpack
virtual void unpack(QDataStream &steam)
Reimplemented from Serializable.
Definition: GeoDataObject.cpp:120
Marble::GeoDataPolygonPrivate::outer
GeoDataLinearRing outer
Definition: GeoDataPolygon_p.h:52
Marble::GeoDataPolygon::tessellationFlags
TessellationFlags tessellationFlags() const
Returns the tessellation flags for a Polygon.
Definition: GeoDataPolygon.cpp:69
Marble::Tessellate
Definition: MarbleGlobal.h:32
Marble::GeoDataPolygonPrivate::inner
QVector< GeoDataLinearRing > inner
Definition: GeoDataPolygon_p.h:53
Marble::mDebug
QDebug mDebug()
a function to replace qDebug() in Marble library code
Definition: MarbleDebug.cpp:31
Marble::GeoDataPolygon::setOuterBoundary
void setOuterBoundary(const GeoDataLinearRing &boundary)
Sets the given LinearRing as an outer boundary of the Polygon.
Definition: GeoDataPolygon.cpp:95
Marble::GeoDataPolygon::setTessellationFlags
void setTessellationFlags(TessellationFlags f)
Sets the given tessellation flags for a Polygon.
Definition: GeoDataPolygon.cpp:74
Marble::GeoDataLatLonAltBox
A class that defines a 3D bounding box for geographic data.
Definition: GeoDataLatLonAltBox.h:49
Marble::GeoDataLineString::latLonAltBox
virtual const GeoDataLatLonAltBox & latLonAltBox() const
Returns the smallest latLonAltBox that contains the LineString.
Definition: GeoDataLineString.cpp:545
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:38:50 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