OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimTilingPoly.cpp
Go to the documentation of this file.
1 //*******************************************************************
2 //
3 // License: LGPL
4 //
5 // See LICENSE.txt file in the top level directory for more details.
6 //
7 // Author: Mingjie Su
8 //
9 // Description: implementation for image generator
10 //
11 //*************************************************************************
12 // $Id: ossimTilingPoly.cpp 2725 2011-06-15 18:13:07Z david.burken $
13 
14 #include <sstream>
15 #include <iomanip>
20 #include <ossim/base/ossimTrace.h>
24 
25 static ossimTrace traceDebug("ossimTilingPoly:debug");
26 
27 RTTI_DEF1(ossimTilingPoly, "ossimTilingPoly", ossimTilingRect);
28 
30  : ossimTilingRect(),
31  m_shpFilename(""),
32  m_useMbr(true),
33  m_bufferDistance(0.0),
34  m_exteriorCut(0),
35  m_interiorCut(0),
36  m_featureBoundingIntersect(true)
37 {
38 }
39 
41 {
42  m_exteriorCut = 0; // Ref ptr, not a leak.
43  m_interiorCut = 0; // ditto...
44  m_features.clear();
45 }
46 
48  const ossimIrect& boundingRect)
49 {
50  bool result = false;
51  if(traceDebug())
52  {
54  << "ossimTilingPoly::initialize DEBUG: Entered..."
55  << "\nBounding rect === " << boundingRect
56  << std::endl;
57  }
58 
59  ossimDpt convertedTilingDistance = theTilingDistance;
60  result = initializeBase(proj, boundingRect, convertedTilingDistance);
61  if (result)
62  {
63  return parseShpFile();
64  }
65  return result;
66 }
67 
69  ossimIrect& resultingBounds,
70  ossimString& resultingName)
71 {
72  bool result = true;
73 
75  {
76  ostringstream idString;
77  ossim_int64 tileId = theTileId + 1;
78  if (tileId < static_cast<ossim_int64>(m_features.size()))
79  {
80  idString << m_features[tileId].m_fid;
81  resultingName = theTileNameMask;
82  resultingName = resultingName.substitute("%f%", idString.str().c_str());
83  }
84  result = nextFeature();
85  resultingBounds = m_exteriorCut->getRectangle();
86 
87  resultProjection = theMapProjection;
88 
89  ++theTileId;
90  }
91  else
92  {
93  result = false;
94  }
95 
96  return result;
97 }
98 
100  const char* prefix)const
101 {
102  kwl.add(prefix,
103  "tile_source",
105  true);
106 
107  kwl.add(prefix,
108  "paddding_use_mbr",
109  m_useMbr,
110  true);
111 
112  return ossimTilingRect::saveState(kwl, prefix);;
113 }
114 
116  const char* prefix)
117 {
118  bool result = ossimTilingRect::loadState(kwl, prefix);
119 
120  //Get the shp file if any
121  m_shpFilename = kwl.find(prefix, "tile_source");
122 
123  // Get the mask if any.
124  if (!m_shpFilename.empty())
125  {
126  if (theTileNameMask.contains("%r%_%c%"))
127  {
128  theTileNameMask = theTileNameMask.substitute("%r%_%c%", "%f%", true);
129  }
130  result = true;
131  }
132 
133  const char* useMbr = kwl.find(prefix, "padding_use_mbr");
134  if (useMbr)
135  {
136  if (!ossimString(useMbr).toBool())
137  {
138  m_useMbr = false;
140  }
141  }
142 
143  return result;
144 }
145 
147 {
148  if (!m_exteriorCut)
149  {
152  }
153 
154  bool result = false;
155  ossim_int64 tileId = theTileId + 1;//use (theTileId+1) because theTileId is intialized as -1
156  if (tileId < static_cast<ossim_int64>(m_features.size()))
157  {
158  if (m_features[tileId].m_polygon.size() > 0)
159  {
161  {
162  if (!m_interiorCut)
163  {
167  }
168  m_interiorCut->setPolygon(m_features[tileId].m_polygon);
169  }
170  else
171  {
172  // std::vector<ossimGpt> points = m_features[tileId].m_polygon;
173  // for (ossim_uint32 i = 0; i < points.size(); i++)
174  // {
175  // ossimGpt point = points[i];
176  // }
177  m_exteriorCut->setPolygon(m_features[tileId].m_polygon);
178  setRect();
179  }
180  result = true;
181  }
182  else if (m_features[tileId].m_multiPolys.size() > 0)
183  {
184  for (ossim_uint32 i = 0; i < m_features[tileId].m_multiPolys.size(); i++)
185  {
186  ossimGeoPolygon geoPoly = m_features[tileId].m_multiPolys[i];
187  std::vector<ossimGeoPolygon> holePolys = geoPoly.getHoleList();
188  if (holePolys.size() > 0)
189  {
190  if (!m_interiorCut)
191  {
195  }
196  m_interiorCut->clear();
197  for (ossim_uint32 j = 0; j < holePolys.size(); j++)
198  {
199  m_interiorCut->addPolygon(holePolys[j]);
200  }
201  }
202  m_exteriorCut->setPolygon(m_features[tileId].m_multiPolys[i]);
203  setRect();
204  }
205  result = true;
206  }
207  }
208  else
209  {
210  result = false;
211  }
212  return result;
213 }
214 
216  {
218  if (rect.intersects(theImageRect))
219  {
221  if (!rect.completely_within(theImageRect))
222  {
223  ossimIrect clipRect = rect.clipToRect(theImageRect);
224  m_exteriorCut->setRectangle(clipRect);
225  rect = clipRect;
226  }
227  }
228  else
229  {
231  }
232  if (m_useMbr)
233  {
235  {
240  ossimIrect clipRect = newRect.clipToRect(theImageRect);//in case the bounding is larger than input image after adding buffer
241  m_exteriorCut->setRectangle(clipRect);
242  }
243  }
244  }
245 
247 {
248  m_features.clear();
249 
250  ossimString query = "";
251  bool result = false;
252  if (m_shpFilename.contains("|"))
253  {
254  ossimString fileName = m_shpFilename;
255  std::vector<ossimString> fileList = fileName.split("|");
256  if (fileList.size() > 1)
257  {
258  m_shpFilename = fileList[0];
259  query = fileList[1];
260  }
261  }
262 
265  if (shpInterface != 0)
266  {
267  if (!query.empty())
268  {
269  shpInterface->setQuery(query);
270  }
271  if (m_useMbr == false)
272  {
273  ossimProjection* proj = shpHandler->getImageGeometry()->getProjection();
275  if (mapProj)
276  {
277  if (mapProj->isGeographic())
278  {
281  }
282  else
283  {
286  }
287  }
288  }
289  std::multimap<long, ossimAnnotationObject*> features = shpInterface->getFeatureTable();
290  if (features.size() > 0)
291  {
292  std::multimap<long, ossimAnnotationObject*>::iterator it = features.begin();
293  while (it != features.end())
294  {
295  ossimAnnotationObject* anno = it->second;
296  if (anno != 0)
297  {
299  ossimGeoAnnotationMultiPolyObject* annoMultiPoly = 0;
300  if (annoPoly == 0)
301  {
302  annoMultiPoly = PTR_CAST(ossimGeoAnnotationMultiPolyObject, anno);
303  }
304  if (annoPoly != 0)
305  {
306  result = true;
307  std::vector<ossimGpt> polygon;
308 
309  //get the points of a polygon
310  std::vector<ossimGpt> points = annoPoly->getPoints();
311  for (ossim_uint32 i = 0; i < points.size(); i++)
312  {
313  polygon.push_back(points[i]);
314  }
315 
316  //get polygon type, if it is an internal polygon, initialize the internal cutter
318  ossimShpFeature feature(it->first, polyType, polygon, std::vector<ossimGeoPolygon>());
319  m_features.push_back(feature);
320  }
321  else if (annoMultiPoly != 0)
322  {
323  std::vector<ossimGeoPolygon> multiPolys = annoMultiPoly->getMultiPolygon();
324  ossimShpFeature feature(it->first, 0, std::vector<ossimGpt>(), multiPolys);
325  }
326  }
327  it++;
328  }
329  }
330  }
331  if (m_features.size() > 0)
332  {
333  theTotalTiles = m_features.size();
334  result = true;
335  }
336  return result;
337 }
338 
340 {
341  //if the use_mbr is set to true, no matter if the padding is set to 0 or greater than 0,
342  //always clip the MBR of each feature
343  return m_useMbr;
344 }
345 
347 {
348  return m_exteriorCut.valid();
349 }
350 
352 {
353  return m_interiorCut.valid();
354 }
355 
357 {
358  return m_exteriorCut;
359 }
360 
362 {
363  return m_interiorCut;
364 }
365 
367 {
369 }
virtual const ossimDpt & getDecimalDegreesPerPixel() const
Returns decimal degrees per pixel as an ossimDpt with "x" representing longitude and "y" representing...
virtual std::vector< ossimGpt > getPoints()
ossimString substitute(const ossimString &searchKey, const ossimString &replacementValue, bool replaceAll=false) const
Substitutes searchKey string with replacementValue and returns a string.
virtual void setQuery(const ossimString &query)=0
Pure virtual setQuery method.
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
Definition: ossimIosFwd.h:35
virtual void setPolygon(const vector< ossimDpt > &polygon, ossim_uint32 i=0)
virtual ossimImageHandler * open(const ossimFilename &fileName, bool trySuffixFirst=true, bool openOverview=true) const
open that takes a filename.
Represents serializable keyword/value map.
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
ossimRefPtr< ossimGeoPolyCutter > & getExteriorCut()
ossim_int64 theTileId
Definition: ossimTiling.h:176
bool valid() const
Definition: ossimRefPtr.h:75
ossimRefPtr< ossimGeoPolyCutter > & getInteriorCut()
const char * find(const char *key) const
bool useMbr() const
double y
Definition: ossimDpt.h:165
bool contains(char aChar) const
Definition: ossimString.h:58
ossimRefPtr< ossimMapProjection > theMapProjection
Definition: ossimTiling.h:173
bool hasExteriorCut() const
return true if exterior cut is initialized.
std::vector< ossimShpFeature > m_features
virtual bool isGeographic() const
const ossimIpt & ul() const
Definition: ossimIrect.h:274
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.
ossimIrect theImageRect
Definition: ossimTiling.h:174
ossimRefPtr< ossimGeoPolyCutter > m_exteriorCut
virtual ~ossimTilingPoly()
bool intersects(const ossimIrect &rect) const
Definition: ossimIrect.cpp:183
std::vector< ossimGeoPolygon > & getHoleList()
virtual bool next(ossimRefPtr< ossimMapProjection > &resultProjection, ossimIrect &resultingBounds, ossimString &resultingName)
bool completely_within(const ossimIrect &rect) const
Definition: ossimIrect.cpp:425
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
virtual bool setView(ossimObject *baseObject)
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if non defined...
unsigned int ossim_uint32
ossimFilename m_shpFilename
ossim_int64 theTotalTiles
Definition: ossimTiling.h:179
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
const std::vector< ossimGeoPolygon > & getMultiPolygon() const
bool m_featureBoundingIntersect
const ossimIpt & lr() const
Definition: ossimIrect.h:276
const ossimIrect & getRectangle() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual void addPolygon(const vector< ossimIpt > &polygon)
ossimIrect clipToRect(const ossimIrect &rect) const
Definition: ossimIrect.cpp:501
ossim_float64 m_bufferDistance
ossimRefPtr< ossimGeoPolyCutter > m_interiorCut
ossimString theTileNameMask
Definition: ossimTiling.h:180
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
ossimDpt theTilingDistance
The size of a tile in theTilingDistanceUnitType.
Definition: ossimTiling.h:122
ossim_int32 y
Definition: ossimIpt.h:142
ossimDpt thePaddingSizeInPixels
Definition: ossimTiling.h:172
double x
Definition: ossimDpt.h:164
long long ossim_int64
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
bool initializeBase(const ossimMapProjection &proj, const ossimIrect &boundingRect, ossimDpt &convertedTilingDistance)
bool empty() const
Definition: ossimString.h:411
virtual std::multimap< long, ossimAnnotationObject * > getFeatureTable()=0
Pure virtual getFeatureTable method.
bool isFeatureBoundingIntersect() const
RTTI_DEF1(ossimTilingPoly, "ossimTilingPoly", ossimTilingRect)
static ossimImageHandlerRegistry * instance()
ossim_int32 x
Definition: ossimIpt.h:141
void setRectangle(const ossimIrect &rect)
virtual bool initialize(const ossimMapProjection &proj, const ossimIrect &boundingRect)
virtual ossimDpt getMetersPerPixel() const
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
virtual void setGeometryBuffer(ossim_float64 distance, ossimUnitType type)=0
Pure virtual setGeometryBuffer method.
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
void setCutType(ossimPolyCutterCutType cutType)
bool hasInteriorCut() const
return true if interior cut is initialized.
int ossim_int32