OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
Public Member Functions | Protected Attributes | Friends | List of all members
ossimGeoPolygon Class Reference

#include <ossimGeoPolygon.h>

Public Member Functions

 ossimGeoPolygon ()
 
 ossimGeoPolygon (const std::vector< ossimGpt > &points)
 
 ossimGeoPolygon (const ossimGeoPolygon &rhs)
 
bool addWmsBbox (const ossimString &wmsBbox)
 
void addPoint (const ossimGpt &pt)
 
void addPoint (double lat, double lon, double h=ossim::nan(), const ossimDatum *datum=0)
 
void addAttribute (const ossimString &attribute)
 
void addHole (const ossimGeoPolygon &polygon)
 
ossimGptoperator[] (int index)
 
const ossimGptoperator[] (int index) const
 
const std::vector< ossimGpt > & getVertexList () const
 
std::vector< ossimString > & getAttributeList ()
 
std::vector< ossimGeoPolygon > & getHoleList ()
 
void clear ()
 
ossim_uint32 size () const
 
void resize (ossim_uint32 newSize)
 
const ossimGeoPolygonoperator= (const std::vector< ossimGpt > &rhs)
 
const ossimGeoPolygonoperator= (const ossimGeoPolygon &rhs)
 
void stretchOut (ossimGeoPolygon &newPolygon, double displacement)
 
double area () const
 
ossimGpt computeCentroid () const
 
bool vertex (int index, ossimGpt &v) const
 
bool nextVertex (ossimDpt &v) const
 
bool hasNans () const
 
void reverseOrder ()
 
bool saveState (ossimKeywordlist &kwl, const char *prefix=0) const
 
bool loadState (const ossimKeywordlist &kwl, const char *prefix=0)
 
void checkOrdering () const
 
ossimVertexOrdering getOrdering () const
 
void setOrdering (ossimVertexOrdering ordering)
 

Protected Attributes

std::vector< ossimGpttheVertexList
 
std::vector< ossimStringtheAttributeList
 
std::vector< ossimGeoPolygontheHoleList
 
ossim_int32 theCurrentVertex
 
ossimVertexOrdering theOrderingType
 

Friends

OSSIM_DLL std::ostream & operator<< (std::ostream &out, const ossimGeoPolygon &poly)
 

Detailed Description

Definition at line 19 of file ossimGeoPolygon.h.

Constructor & Destructor Documentation

◆ ossimGeoPolygon() [1/3]

ossimGeoPolygon::ossimGeoPolygon ( )

Definition at line 44 of file ossimGeoPolygon.cpp.

45  :
46  theVertexList(),
48  theHoleList(),
49  theCurrentVertex(-1),
51 {
52 }
std::vector< ossimString > theAttributeList
std::vector< ossimGeoPolygon > theHoleList
std::vector< ossimGpt > theVertexList
ossimVertexOrdering theOrderingType
ossim_int32 theCurrentVertex

◆ ossimGeoPolygon() [2/3]

ossimGeoPolygon::ossimGeoPolygon ( const std::vector< ossimGpt > &  points)

Definition at line 54 of file ossimGeoPolygon.cpp.

55  :
56  theVertexList(points),
58  theHoleList(),
61 {
62 }
std::vector< ossimString > theAttributeList
std::vector< ossimGeoPolygon > theHoleList
std::vector< ossimGpt > theVertexList
ossimVertexOrdering theOrderingType
ossim_int32 theCurrentVertex

◆ ossimGeoPolygon() [3/3]

ossimGeoPolygon::ossimGeoPolygon ( const ossimGeoPolygon rhs)

Definition at line 64 of file ossimGeoPolygon.cpp.

65  :
71 {
72 }
std::vector< ossimString > theAttributeList
std::vector< ossimGeoPolygon > theHoleList
std::vector< ossimGpt > theVertexList
ossimVertexOrdering theOrderingType
ossim_int32 theCurrentVertex

Member Function Documentation

◆ addAttribute()

void ossimGeoPolygon::addAttribute ( const ossimString attribute)
inline

Definition at line 39 of file ossimGeoPolygon.h.

Referenced by ossimVpfAnnotationFeatureInfo::readAttributes().

40  {
41  theAttributeList.push_back( attribute );
42  }
std::vector< ossimString > theAttributeList

◆ addHole()

void ossimGeoPolygon::addHole ( const ossimGeoPolygon polygon)
inline

Definition at line 43 of file ossimGeoPolygon.h.

44  {
45  theHoleList.push_back( polygon );
46  }
std::vector< ossimGeoPolygon > theHoleList

◆ addPoint() [1/2]

void ossimGeoPolygon::addPoint ( const ossimGpt pt)
inline

◆ addPoint() [2/2]

void ossimGeoPolygon::addPoint ( double  lat,
double  lon,
double  h = ossim::nan(),
const ossimDatum datum = 0 
)
inline

Definition at line 35 of file ossimGeoPolygon.h.

36  {
37  theVertexList.push_back(ossimGpt(lat, lon, h, datum));
38  }
std::vector< ossimGpt > theVertexList

◆ addWmsBbox()

bool ossimGeoPolygon::addWmsBbox ( const ossimString wmsBbox)

Definition at line 87 of file ossimGeoPolygon.cpp.

References addPoint(), and ossimString::split().

88 {
89  std::vector<ossimString> splitArray = wmsBbox.split(",");
90  bool result = true;
91  if(splitArray.size()>=4)
92  {
93  double minx = splitArray[0].trim().toDouble();
94  double miny = splitArray[1].trim().toDouble();
95  double maxx = splitArray[2].trim().toDouble();
96  double maxy = splitArray[3].trim().toDouble();
97 
98  addPoint(miny, minx);//lower left
99  addPoint(maxy, minx);//upper left
100  addPoint(maxy, maxx);//upper right
101  addPoint(miny, maxx);//lower right
102  }
103  else
104  {
105  // error
106  result = false;
107  }
108 
109  return result;
110 }
void split(std::vector< ossimString > &result, const ossimString &separatorList, bool skipBlankFields=false) const
Splits this string into a vector of strings (fields) using the delimiter list specified.
void addPoint(const ossimGpt &pt)

◆ area()

double ossimGeoPolygon::area ( ) const

Definition at line 265 of file ossimGeoPolygon.cpp.

References size(), and theVertexList.

Referenced by checkOrdering().

266 {
267  double area = 0;
268  ossim_uint32 i=0;
269  ossim_uint32 j=0;
271 
272  for (i=0;i<size;i++)
273  {
274  j = (i + 1) % size;
275  area += theVertexList[i].lon * theVertexList[j].lat;
276  area -= theVertexList[i].lat * theVertexList[j].lon;
277  }
278 
279  area /= 2;
280 
281  return area;
282 }
double area() const
unsigned int ossim_uint32
std::vector< ossimGpt > theVertexList
ossim_uint32 size() const

◆ checkOrdering()

void ossimGeoPolygon::checkOrdering ( ) const

Definition at line 299 of file ossimGeoPolygon.cpp.

References area(), OSSIM_CLOCKWISE_ORDER, OSSIM_COUNTERCLOCKWISE_ORDER, OSSIM_VERTEX_ORDER_UNKNOWN, and theOrderingType.

Referenced by stretchOut().

300 {
302  {
303  double areaValue = area();
304  if(areaValue > 0)
305  {
307  }
308  else if(areaValue <= 0)
309  {
311  }
312  }
313 }
double area() const
ossimVertexOrdering theOrderingType

◆ clear()

void ossimGeoPolygon::clear ( )
inline

◆ computeCentroid()

ossimGpt ossimGeoPolygon::computeCentroid ( ) const

Definition at line 315 of file ossimGeoPolygon.cpp.

References size(), theVertexList, ossimDpt::x, and ossimDpt::y.

316 {
317  if(!size())
318  {
319  return ossimGpt();
320  }
321  ossimDpt average(0.0,0.0);
322  double height=0.0;
323  for(ossim_uint32 i = 0; i < size(); ++i)
324  {
325  average += ossimDpt(theVertexList[i]);
326  height += theVertexList[i].height();
327  }
328 
329 
330  average.x /= size();
331  average.y /= size();
332  height /= size();
333 
334  return ossimGpt(average.y, average.x, height, theVertexList[0].datum());
335 }
unsigned int ossim_uint32
std::vector< ossimGpt > theVertexList
ossim_uint32 size() const

◆ getAttributeList()

std::vector<ossimString>& ossimGeoPolygon::getAttributeList ( )
inline

Definition at line 60 of file ossimGeoPolygon.h.

61  {
62  return theAttributeList;
63  }
std::vector< ossimString > theAttributeList

◆ getHoleList()

std::vector<ossimGeoPolygon>& ossimGeoPolygon::getHoleList ( )
inline

Definition at line 64 of file ossimGeoPolygon.h.

Referenced by ossimTilingPoly::nextFeature().

65  {
66  return theHoleList;
67  }
std::vector< ossimGeoPolygon > theHoleList

◆ getOrdering()

ossimVertexOrdering ossimGeoPolygon::getOrdering ( ) const
inline

Definition at line 112 of file ossimGeoPolygon.h.

References OSSIM_VERTEX_ORDER_UNKNOWN.

Referenced by ossimIgenGenerator::addPadding().

113  {
115  {
116  checkOrdering();
117  }
118  return theOrderingType;
119  }
void checkOrdering() const
ossimVertexOrdering theOrderingType

◆ getVertexList()

const std::vector<ossimGpt>& ossimGeoPolygon::getVertexList ( ) const
inline

◆ hasNans()

bool ossimGeoPolygon::hasNans ( ) const

Definition at line 112 of file ossimGeoPolygon.cpp.

References theVertexList.

113 {
114  int upper = (int)theVertexList.size();
115  int i = 0;
116 
117  for(i = 0; i < upper; ++i)
118  {
119  if(theVertexList[i].hasNans())
120  {
121  return true;
122  }
123  }
124 
125  return false;
126 }
bool hasNans() const
std::vector< ossimGpt > theVertexList

◆ loadState()

bool ossimGeoPolygon::loadState ( const ossimKeywordlist kwl,
const char *  prefix = 0 
)

Definition at line 380 of file ossimGeoPolygon.cpp.

References ossimKeywordlist::find().

382 {
383  const char* number_vertices = kwl.find(prefix, NUMBER_VERTICES_KW);
384  ossimString datumStr = kwl.find(prefix, ossimKeywordNames::DATUM_KW);
385  const ossimDatum* datum = ossimDatumFactoryRegistry::instance()->create(datumStr);
386 
387  theVertexList.clear();
388  int i = 0;
389  int vertexCount = ossimString(number_vertices).toLong();
390  ossimString lat, lon, height;
391  for(i = 0; i < vertexCount; ++i)
392  {
393  ossimString v = kwl.find(prefix, (ossimString("v")+ossimString::toString(i)).c_str());
394  ossimString latString, lonString, heightString;
395  v = v.trim();
396  std::istringstream in(v);
397  in>>lat>>lon>>height;
398  theVertexList.push_back(ossimGpt(lat.toDouble(), lon.toDouble(), height.toDouble(), datum));
399  }
400 
401  return true;
402 }
static const char * DATUM_KW
static ossimDatumFactoryRegistry * instance()
instance method
const char * find(const char *key) const
static ossimString toString(bool aValue)
Numeric to string methods.
virtual const ossimDatum * create(const ossimString &code) const
create method
ossimString trim(const ossimString &valueToTrim=ossimString(" \\)) const
this will strip lead and trailing character passed in.
double toDouble() const
std::vector< ossimGpt > theVertexList
long toLong() const
toLong&#39;s deprecated, please use the toInts...
std::basic_istringstream< char > istringstream
Class for char input memory streams.
Definition: ossimIosFwd.h:32

◆ nextVertex()

bool ossimGeoPolygon::nextVertex ( ossimDpt v) const

Definition at line 142 of file ossimGeoPolygon.cpp.

References theCurrentVertex, and theVertexList.

143 {
146  {
147  return false;
148  }
150 
151  return true;
152 }
std::vector< ossimGpt > theVertexList
ossim_int32 theCurrentVertex
int ossim_int32

◆ operator=() [1/2]

const ossimGeoPolygon& ossimGeoPolygon::operator= ( const std::vector< ossimGpt > &  rhs)
inline

Definition at line 83 of file ossimGeoPolygon.h.

References OSSIM_VERTEX_ORDER_UNKNOWN.

84  {
85  theVertexList = rhs;
86  theCurrentVertex = 0;
88 
89  return *this;
90  }
std::vector< ossimGpt > theVertexList
ossimVertexOrdering theOrderingType
ossim_int32 theCurrentVertex

◆ operator=() [2/2]

const ossimGeoPolygon & ossimGeoPolygon::operator= ( const ossimGeoPolygon rhs)

Definition at line 74 of file ossimGeoPolygon.cpp.

References theAttributeList, theCurrentVertex, theHoleList, theOrderingType, and theVertexList.

75 {
76  if ( this != &rhs )
77  {
83  }
84  return *this;
85 }
std::vector< ossimString > theAttributeList
std::vector< ossimGeoPolygon > theHoleList
std::vector< ossimGpt > theVertexList
ossimVertexOrdering theOrderingType
ossim_int32 theCurrentVertex

◆ operator[]() [1/2]

ossimGpt& ossimGeoPolygon::operator[] ( int  index)
inline

Definition at line 47 of file ossimGeoPolygon.h.

48  {
49  return theVertexList[index];
50  }
std::vector< ossimGpt > theVertexList

◆ operator[]() [2/2]

const ossimGpt& ossimGeoPolygon::operator[] ( int  index) const
inline

Definition at line 51 of file ossimGeoPolygon.h.

52  {
53  return theVertexList[index];
54  }
std::vector< ossimGpt > theVertexList

◆ resize()

void ossimGeoPolygon::resize ( ossim_uint32  newSize)
inline

Definition at line 77 of file ossimGeoPolygon.h.

References OSSIM_VERTEX_ORDER_UNKNOWN.

Referenced by ossimGeoPolyCutter::invertPolygon(), and stretchOut().

78  {
79  theVertexList.resize(newSize);
80  theCurrentVertex = 0;
82  }
std::vector< ossimGpt > theVertexList
ossimVertexOrdering theOrderingType
ossim_int32 theCurrentVertex

◆ reverseOrder()

void ossimGeoPolygon::reverseOrder ( )

Definition at line 284 of file ossimGeoPolygon.cpp.

References OSSIM_CLOCKWISE_ORDER, OSSIM_COUNTERCLOCKWISE_ORDER, theOrderingType, and theVertexList.

285 {
286  std::reverse(theVertexList.begin(), theVertexList.end());
287 
289  {
291  }
293  {
295  }
296 
297 }
std::vector< ossimGpt > theVertexList
ossimVertexOrdering theOrderingType

◆ saveState()

bool ossimGeoPolygon::saveState ( ossimKeywordlist kwl,
const char *  prefix = 0 
) const

Definition at line 337 of file ossimGeoPolygon.cpp.

References ossimKeywordlist::add(), and ossimKeywordNames::TYPE_KW.

339 {
340  int i = 0;
341 
342  kwl.add(prefix,
344  "ossimGeoPolygon",
345  true);
346  kwl.add(prefix,
347  NUMBER_VERTICES_KW,
348  static_cast<ossim_uint32>(theVertexList.size()),
349  true);
350  if(theVertexList.size())
351  {
352  kwl.add(prefix,
354  theVertexList[0].datum()->code(),
355  true);
356  }
357  else
358  {
359  kwl.add(prefix,
361  "WGE",
362  true);
363  }
364 
365  for(i = 0; i < (int)theVertexList.size();++i)
366  {
367  ossimString vert = "v"+ossimString::toString(i);
368  ossimString value = (ossimString::toString(theVertexList[i].latd()) + " " +
369  ossimString::toString(theVertexList[i].lond()) + " " +
370  ( theVertexList[i].isHgtNan()?ossimString("nan"):ossimString::toString(theVertexList[i].height())));
371  kwl.add(prefix,
372  vert.c_str(),
373  value.c_str(),
374  true);
375  }
376 
377  return true;
378 }
static const char * DATUM_KW
static ossimString toString(bool aValue)
Numeric to string methods.
static const char * TYPE_KW
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
std::vector< ossimGpt > theVertexList
const char * c_str() const
Returns a pointer to a null-terminated array of characters representing the string&#39;s contents...
Definition: ossimString.h:396

◆ setOrdering()

void ossimGeoPolygon::setOrdering ( ossimVertexOrdering  ordering)
inline

Definition at line 120 of file ossimGeoPolygon.h.

Referenced by ossimIgenGenerator::addPadding().

121  {
122  theOrderingType = ordering;
123  }
ossimVertexOrdering theOrderingType

◆ size()

ossim_uint32 ossimGeoPolygon::size ( ) const
inline

◆ stretchOut()

void ossimGeoPolygon::stretchOut ( ossimGeoPolygon newPolygon,
double  displacement 
)

Definition at line 154 of file ossimGeoPolygon.cpp.

References checkOrdering(), ossimDpt::lat, ossimDpt::length(), ossimDpt::lon, OSSIM_COUNTERCLOCKWISE_ORDER, resize(), size(), theOrderingType, theVertexList, ossimDpt::x, and ossimDpt::y.

Referenced by ossimEsriShapeFileFilter::loadPolygon().

156 {
157  newPolygon.resize(size());
158  if(size() >= 3)
159  {
160  const ossimDatum* datum = theVertexList[0].datum();
161  checkOrdering();
162  double signMult = 1.0;
164  {
165  signMult = -1.0;
166  }
167 
168  ossimDpt prev, current, next;
169 
170  ossim_uint32 prevI;
171  ossim_uint32 currentI;
172  ossim_uint32 nextI;
173  ossim_uint32 i = 0;
174  ossim_uint32 upper = size();
175 
176  bool equalEndsFlag = false;
177  if(theVertexList[0] == theVertexList[theVertexList.size()-1])
178  {
179  equalEndsFlag = true;
180  prevI = 0;
181  currentI = 1;
182  nextI = 2;
183  i = 1;
184  --upper;
185  }
186  else
187  {
188  equalEndsFlag = false;
189  prevI = size()-1;
190  currentI = 0;
191  nextI = 1;
192  }
193  for(; i < upper;++i)
194  {
195  prev = theVertexList[prevI];
196  current = theVertexList[currentI];
197  next = theVertexList[nextI];
198 
199  ossimDpt averageNormal;
200 
201  ossimDpt diffPrev = current - prev;
202  ossimDpt diffNext = next - current;
203 
204  diffPrev = diffPrev*(1.0/diffPrev.length());
205  diffNext = diffNext*(1.0/diffNext.length());
206 
207  ossimDpt diffPrevNormal(-diffPrev.y,
208  diffPrev.x);
209  ossimDpt diffNextNormal(-diffNext.y,
210  diffNext.x);
211 
212  averageNormal = (diffPrevNormal + diffNextNormal);
213  averageNormal = averageNormal*(signMult*(1.0/averageNormal.length()));
214  ossimDpt newPoint = ossimDpt( theVertexList[i].lond(),
215  theVertexList[i].latd()) +
216  averageNormal*displacement;
217  newPolygon[i].latd(newPoint.lat);
218  newPolygon[i].lond(newPoint.lon);
219  newPolygon[i].height(theVertexList[i].height());
220  newPolygon[i].datum(datum);
221 
222  ++prevI;
223  ++currentI;
224  ++nextI;
225 
226  prevI%=size();
227  nextI%=size();
228  }
229  if(equalEndsFlag)
230  {
231 
232  prev = theVertexList[theVertexList.size()-2];
233  current = theVertexList[0];
234  next = theVertexList[1];
235 
236  ossimDpt averageNormal;
237 
238  ossimDpt diffPrev = current - prev;
239  ossimDpt diffNext = next - current;
240 
241  diffPrev = diffPrev*(1.0/diffPrev.length());
242  diffNext = diffNext*(1.0/diffNext.length());
243 
244  ossimDpt diffPrevNormal(-diffPrev.y,
245  diffPrev.x);
246  ossimDpt diffNextNormal(-diffNext.y,
247  diffNext.x);
248 
249  averageNormal = (diffPrevNormal + diffNextNormal);
250  averageNormal = averageNormal*(signMult*(1.0/averageNormal.length()));
251  ossimDpt newPoint = ossimDpt( theVertexList[i].lond(),
252  theVertexList[i].latd()) +
253  averageNormal*displacement;
254  newPolygon[0].latd(newPoint.lat);
255  newPolygon[0].lond(newPoint.lon);
256  newPolygon[0].height(theVertexList[i].height());
257  newPolygon[0].datum(datum);
258 
259  newPolygon[(int)theVertexList.size()-1] = newPolygon[0];
260  }
261  }
262 }
double y
Definition: ossimDpt.h:165
double length() const
Definition: ossimDpt.h:81
void resize(ossim_uint32 newSize)
double lat
Definition: ossimDpt.h:165
unsigned int ossim_uint32
std::vector< ossimGpt > theVertexList
void checkOrdering() const
double lon
Definition: ossimDpt.h:164
ossim_uint32 size() const
ossimVertexOrdering theOrderingType
double x
Definition: ossimDpt.h:164

◆ vertex()

bool ossimGeoPolygon::vertex ( int  index,
ossimGpt v 
) const

Definition at line 128 of file ossimGeoPolygon.cpp.

References theCurrentVertex, and theVertexList.

129 {
130  if((index >= (int)theVertexList.size()) ||
131  (index < 0))
132  {
133  return false;
134  }
135 
136  v = theVertexList[index];
137  theCurrentVertex = index;
138 
139  return true;
140 }
std::vector< ossimGpt > theVertexList
ossim_int32 theCurrentVertex

Friends And Related Function Documentation

◆ operator<<

OSSIM_DLL std::ostream& operator<< ( std::ostream &  out,
const ossimGeoPolygon poly 
)
friend

Definition at line 22 of file ossimGeoPolygon.cpp.

23 {
24  if(poly.size())
25  {
26  if(poly.size() >1)
27  {
28  for(ossim_uint32 i = 0; i < poly.size()-1; ++i)
29  {
30  out << "P" << i << ": " << poly[i] << std::endl;
31  }
32  out << "P" << (poly.size()-1)
33  << ": " << poly[poly.size()-1] << std::endl;
34  }
35  else
36  {
37  out << "P0: " << poly[0] << std::endl;
38  }
39  }
40 
41  return out;
42 }
unsigned int ossim_uint32
ossim_uint32 size() const

Member Data Documentation

◆ theAttributeList

std::vector<ossimString> ossimGeoPolygon::theAttributeList
protected

Definition at line 126 of file ossimGeoPolygon.h.

Referenced by operator=().

◆ theCurrentVertex

ossim_int32 ossimGeoPolygon::theCurrentVertex
mutableprotected

Definition at line 128 of file ossimGeoPolygon.h.

Referenced by nextVertex(), operator=(), and vertex().

◆ theHoleList

std::vector<ossimGeoPolygon> ossimGeoPolygon::theHoleList
protected

Definition at line 127 of file ossimGeoPolygon.h.

Referenced by operator=().

◆ theOrderingType

ossimVertexOrdering ossimGeoPolygon::theOrderingType
mutableprotected

This enumeration is found in ossimConstants.h

Definition at line 133 of file ossimGeoPolygon.h.

Referenced by checkOrdering(), operator=(), reverseOrder(), and stretchOut().

◆ theVertexList

std::vector<ossimGpt> ossimGeoPolygon::theVertexList
protected

The documentation for this class was generated from the following files: