OSSIM - Open Source Software Image Map  Version 1.9.0 (20180803)
ossimKmlSuperOverlayWriter.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, Harsh Govind
8 //
9 // Description: OSSIM KmlSuperOverlayWriter writer class definition.
10 //
11 //----------------------------------------------------------------------------
12 // $Id: ossimKmlSuperOverlayWriter.cpp 2178 2011-02-17 18:38:30Z ming.su $
13 
15 
16 //OSSIM Includes
17 #include <ossim/base/ossimDpt.h>
21 #include <ossim/base/ossimTrace.h>
22 #include <ossim/base/ossimVisitor.h> /* for ossimViewInterfaceVisitor */
27 
28 //STD Includes
29 #include <cmath>
30 #include <cstring> /* strdup */
31 #include <iostream>
32 #include <sstream>
33 
34 
35 RTTI_DEF1(ossimKmlSuperOverlayWriter, "ossimKmlSuperOverlayWriter", ossimImageFileWriter)
36 
37  //---
38  // For trace debugging (to enable at runtime do:
39  // your_app -T "ossimKmlSuperOverlayWriter:debug" your_app_args
40  //---
41  static ossimTrace traceDebug("ossimKmlSuperOverlayWriter:debug");
42 
45  m_imageWriter(0),
46  m_mapProjection(0),
47  m_isKmz(false),
48  m_isPngFormat(false)
49 {
50  // Set the output image type in the base class.
52 }
53 
55 {
56  close();
57 }
58 
60 {
61  return ossimString("ossim_kmlsuperoverlay");
62 }
63 
65 {
66  return ossimString("ossim kmlsuperoverlay writer");
67 }
68 
70 {
71  return ossimString("ossimKmlSuperOverlayWriter");
72 }
73 
75 {
76  // This method is called from ossimImageFileWriter::execute().
77  bool result = false;
78 
79  if( theInputConnection.valid() &&
81  {
84 
85  //---
86  // Note only the master process used for writing...
87  //---
89  {
90  if (!isOpen())
91  {
92  open();
93  }
94  if ( isOpen() )
95  {
96  result = writeStream();
97  }
98  }
99  else // Slave process.
100  {
101  // This will return after all tiles for this node have been processed.
103  result = true;
104  }
105  }
106 
107  return result;
108 }
109 
111 {
112  static const char MODULE[] = "ossimKmlSuperOverlayWriter::writeStream";
113 
114  if (traceDebug())
115  {
117  << MODULE << " entered..." << endl;
118  }
119 
121  if (bands != 1 && bands != 3)
122  {
124  << MODULE << " Range Error:"
125  << "\nInvalid number of input bands! Must be one or three."
126  << "\nInput bands = " << bands
127  << "\nReturning from method." << endl;
128 
129  return false;
130  }
131 
132  if (theFilename.ext().downcase() == "kmz")
133  {
134  m_isKmz = true;
135  }
136 
137  ossimString fileExt = ".jpg";
138  ossimString ext = "jpg";
139  if (m_isPngFormat)
140  {
141  fileExt = ".png";
142  ext = "png";
143  }
145  if (!m_imageWriter.valid())
146  {
147  return false;
148  }
149  if (m_isPngFormat)//add alpha channel for png
150  {
151  ossimKeywordlist kwl;
152  kwl.add("add_alpha_channel", "true", true);
153  m_imageWriter->loadState(kwl);
154  }
156 
157  ossimString outDir = theFilename.path();
158  if (outDir.empty())
159  outDir = ".";
160 
162  {
163  return false;
164  }
165 
168 
169  ossimGpt ulg;
170  ossimGpt llg;
171  ossimGpt lrg;
172  ossimGpt urg;
173  ossimDpt scale;
175  ossimRefPtr<ossimMapProjection> projDup = 0;
176  if (geom.valid())
177  {
178  geom->localToWorld(theAreaOfInterest.ul(), ulg);
179  geom->localToWorld(theAreaOfInterest.ll(), llg);
180  geom->localToWorld(theAreaOfInterest.lr(), lrg);
181  geom->localToWorld(theAreaOfInterest.ur(), urg);
182 
185  if (m_mapProjection.valid())
186  {
187  //make a copy of map projection for lat, lon conversion of the previous zoom in child kml since m_mapProjection set the scale
188  //for the current zoom
190 
192  {
193  // Get the scale.
196  }
197  else
198  {
199  // Get the scale.
202  }
203  }
204  else
205  {
206  return false;
207  }
208  }
209  else
210  {
211  return false;
212  }
213 
214  //Zoom levels of the pyramid.
215  ossim_int32 maxzoom;
216  ossim_int32 tilexsize;
217  ossim_int32 tileysize;
218  // Let the longer side determine the max zoom level and x/y tilesizes.
219  if ( xsize >= ysize )
220  {
221  ossim_float64 dtilexsize = xsize;
222  while (dtilexsize > 400) //calculate x tile size
223  {
224  dtilexsize = dtilexsize/2;
225  }
226 
227  maxzoom = static_cast<ossim_int32>(log( (ossim_float64)xsize / dtilexsize ) / log(2.0));
228  tilexsize = (ossim_int32)dtilexsize;
229  tileysize = (ossim_int32)( (ossim_float64)(dtilexsize * ysize) / xsize );
230  }
231  else
232  {
233  ossim_float64 dtileysize = ysize;
234  while (dtileysize > 400) //calculate y tile size
235  {
236  dtileysize = dtileysize/2;
237  }
238 
239  maxzoom = static_cast<ossim_int32>(log( (ossim_float64)ysize / dtileysize ) / log(2.0));
240  tileysize = (ossim_int32)dtileysize;
241  tilexsize = (ossim_int32)( (ossim_float64)(dtileysize * xsize) / ysize );
242  }
243 
244  std::vector<ossim_float64> zoomScaleX;
245  std::vector<ossim_float64> zoomScaleY;
246  for (int zoom = 0; zoom < maxzoom + 1; zoom++)
247  {
248  zoomScaleX.push_back(scale.x * pow(2.0, (maxzoom - zoom)));
249  zoomScaleY.push_back(scale.y * pow(2.0, (maxzoom - zoom)));
250  }
251 
252  ossimString tmpFileName;
253  std::vector<ossimString> dirVector;
254  std::vector<ossimString> fileVector;
255  bool isKmlGenerated = false;
256  if (m_isKmz)
257  {
258  tmpFileName = ossimString(outDir + "/" + "tmp.kml");
259  isKmlGenerated = generateRootKml(tmpFileName.c_str(), ulg.lat, lrg.lat, lrg.lon, ulg.lon, (ossim_int32)tilexsize);
260  fileVector.push_back(tmpFileName);
261  }
262  else
263  {
264  isKmlGenerated = generateRootKml(theFilename, ulg.lat, lrg.lat, lrg.lon, ulg.lon, (ossim_int32)tilexsize);
265  }
266  if (!isKmlGenerated)
267  {
268  return false;
269  }
270 
271  for (ossim_int32 zoom = maxzoom; zoom >= 0; --zoom)
272  {
273  ossim_int32 rmaxxsize = static_cast<ossim_int32>(pow(2.0, (maxzoom-zoom)) * tilexsize);
274  ossim_int32 rmaxysize = static_cast<ossim_int32>(pow(2.0, (maxzoom-zoom)) * tileysize);
275 
276  ossim_int32 xloop = (ossim_int32)xsize/rmaxxsize;
277  ossim_int32 yloop = (ossim_int32)ysize/rmaxysize;
278 
279  xloop = xloop>0 ? xloop : 1;
280  yloop = yloop>0 ? yloop : 1;
281 
282  //set scale for the current zoom
283  if (m_mapProjection.valid())
284  {
286  {
287  m_mapProjection->setDecimalDegreesPerPixel(ossimDpt(zoomScaleX[zoom],zoomScaleY[zoom]));
288  }
289  else
290  {
291  m_mapProjection->setMetersPerPixel(ossimDpt(zoomScaleX[zoom],zoomScaleY[zoom]));
292  }
293  }
294 
295  // Set all views and send property event out for combiner if needed.
297 
298  //set the scale for the previous zoom in child kml for lat, lon conversion
299  if (zoom < maxzoom)
300  {
301  if (projDup.valid())
302  {
303  if (projDup->isGeographic())
304  {
305  projDup->setDecimalDegreesPerPixel(ossimDpt(zoomScaleX[zoom+1],zoomScaleY[zoom+1]));
306  }
307  else
308  {
309  projDup->setMetersPerPixel(ossimDpt(zoomScaleX[zoom+1],zoomScaleY[zoom+1]));
310  }
311  }
312  }
313 
314  for (ossim_int32 ix = 0; ix < xloop; ix++)
315  {
316  ossim_int32 rxsize = (ossim_int32)(rmaxxsize);
317  // ossim_int32 rx = (ossim_int32)(ix * rmaxxsize);
318 
319  for (ossim_int32 iy = 0; iy < yloop; iy++)
320  {
321  ossim_int32 rysize = (ossim_int32)(rmaxysize);
322  // ossim_int32 ry = (ossim_int32)(ysize - (iy * rmaxysize)) - rysize;
323 
324  ossim_int32 dxsize = (ossim_int32)(rxsize/rmaxxsize * tilexsize);
325  ossim_int32 dysize = (ossim_int32)(rysize/rmaxysize * tileysize);
326 
327  std::stringstream zoomStr;
328  std::stringstream ixStr;
329  std::stringstream iyStr;
330 
331  zoomStr << zoom;
332  ixStr << ix;
333  iyStr << iy;
334 
335  ossimFilename zoomDir = ossimString(outDir + "/" + ossimString(zoomStr.str()));
336  zoomDir.createDirectory();
337 
338  zoomDir = ossimString(zoomDir + "/") + ossimString::toString(ix);
339  zoomDir.createDirectory();
340 
341  if (m_isKmz)
342  {
343  dirVector.push_back(zoomDir);
344  }
345 
346  ossimString filename = ossimString(zoomDir + "/" + ossimString::toString(yloop-iy-1) + fileExt);
347  if (m_isKmz)
348  {
349  fileVector.push_back(filename);
350  }
351 
352  generateTile(filename, ix, iy, dxsize, dysize);
353 
354  ossimString childKmlfile = ossimString(zoomDir + "/" + ossimString::toString(yloop-iy-1) + ".kml");
355  if (m_isKmz)
356  {
357  fileVector.push_back(childKmlfile);
358  }
359 
360  isKmlGenerated = generateChildKml(childKmlfile, zoom, yloop, ix, iy, dxsize, dysize, xsize, ysize, maxzoom, projDup, fileExt);
361  if (!isKmlGenerated)
362  {
363  return false;
364  }
365  }
366  }
367  }
368 
369 
370  if (m_isKmz)
371  {
372  if (zipWithMinizip(fileVector, outDir, theFilename) == false)
373  {
374  return false;
375  }
376 
377  //remove sub-directories and the files under those directories
378  for (ossim_uint32 i = 0; i < dirVector.size(); ++i)
379  {
380  ossimFilename zoomDir = dirVector[i];
381 
382  ossimDirectory dir;
383  std::vector<ossimFilename> filesInDir;
384  if(dir.open(zoomDir))
385  {
386  ossimFilename file;
387  //if (dir.getFirst(file, ossimDirectory::OSSIM_DIR_DEFAULT))
389  {
390  filesInDir.push_back(file);
391  }
392  do
393  {
394  filesInDir.push_back(file);
395  }while(dir.getNext(file));
396  }
397 
398  for(ossim_uint32 j = 0; j < filesInDir.size(); ++j)
399  {
400  ossimFilename fi = filesInDir[j];
401  if (!fi.empty())
402  {
403  fi.remove();
404  }
405  }
406  if (zoomDir.exists())
407  {
408  ossimString cmd = "rmdir \"";
409  cmd += zoomDir + "\"";
410  std::system(cmd.c_str());
411  }
412  }
413 
414  //remove the top directories
415  for (int zoom = maxzoom; zoom >= 0; --zoom)
416  {
417  std::stringstream zoomStr;
418  zoomStr << zoom;
419  ossimFilename zoomZipDir = ossimString(outDir + "/" + ossimString(zoomStr.str()));
420  if (zoomZipDir.exists())
421  {
422  ossimString cmd = "rmdir \"";
423  cmd += zoomZipDir + "\"";
424  std::system(cmd.c_str());
425  }
426  }
427  if (ossimFilename(tmpFileName).exists())
428  {
429  ossimFilename(tmpFileName).remove();
430  }
431  }
432 
433  return true;
434 }
435 
437  const char* prefix)const
438 {
439  return ossimImageFileWriter::saveState(kwl, prefix);
440 }
441 
443  const char* prefix)
444 {
445  return ossimImageFileWriter::loadState(kwl, prefix);
446 }
447 
449 {
450  if (theFilename.size() > 0)
451  {
452  return true;
453  }
454  return false;
455 }
456 
458 {
459  bool result = false;
460 
461  // Check for empty filenames.
462  if (theFilename.size())
463  {
464  result = true;
465  }
466 
467  if (traceDebug())
468  {
470  << "ossimKmlSuperOverlayWriter::open()\n"
471  << "File " << theFilename << (result ? " opened" : " not opened")
472  << std::endl;
473  }
474 
475  return result;
476 }
477 
479 {
480  if (m_imageWriter.valid())
481  {
482  m_imageWriter = 0;
483  }
484  if (m_mapProjection.valid())
485  {
486  m_mapProjection = 0;
487  }
488 }
489 
490 void ossimKmlSuperOverlayWriter::getImageTypeList(std::vector<ossimString>& imageTypeList)const
491 {
492  imageTypeList.push_back(getShortName());
493 }
494 
496 {
497  if (!theFilename.empty())
498  {
499  return theFilename.ext();
500  }
501  return ossimString("kml");
502 }
503 
505 {
506  bool result = false;
507  if ( (imageType == getShortName()) ||
508  (imageType == "image/kmlsuperoverlay") )
509  {
510  result = true;
511  }
512  return result;
513 }
514 
516 {
517  if (property.get())
518  {
519  if(property->getName().downcase() == "format")
520  {
521  ossimString format = property->valueToString();
522  if (format.downcase() == "png")
523  {
524  m_isPngFormat = true;
525  }
526  }
528  }
529 }
530 
532  const ossimString& name)const
533 {
535 }
536 
538  std::vector<ossimString>& propertyNames)const
539 {
541 }
542 
544  ossim_int32 ix,
545  ossim_int32 iy,
546  ossim_int32 dxsize,
547  ossim_int32 dysize)
548 {
549  ossimFilename file = filename;
550  ossimIpt ul(dxsize*ix, dysize*(iy+1));
551  ossimIpt ur(dxsize*(ix+1), dysize*(iy+1));
552  ossimIpt lr(dxsize*(ix+1), dysize*iy);
553  ossimIpt ll(dxsize*ix, dysize*iy);
554  ossimIrect rect(ul, ur, lr, ll);
555 
556  m_imageWriter->setFilename(file);
559 }
560 
562  ossim_float64 north,
563  ossim_float64 south,
564  ossim_float64 east,
565  ossim_float64 west,
566  ossim_int32 tilesize)
567 {
568  FILE* fp = fopen(filename.c_str(), "wb");
569  if (fp == NULL)
570  {
571  return false;
572  }
573  ossim_int32 minlodpixels = tilesize/2;
574 
575  ossimString tmpfilename = theFilename.fileNoExtension();
576  // If we haven't writen any features yet, output the layer's schema
577  fprintf(fp, "<kml xmlns=\"http://earth.google.com/kml/2.1\">\n");
578  fprintf(fp, "\t<Document>\n");
579  fprintf(fp, "\t\t<name>%s</name>\n", tmpfilename.c_str());
580  fprintf(fp, "\t\t<description></description>\n");
581  fprintf(fp, "\t\t<Style>\n");
582  fprintf(fp, "\t\t\t<ListStyle id=\"hideChildren\">\n");
583  fprintf(fp, "\t\t\t\t<listItemType>checkHideChildren</listItemType>\n");
584  fprintf(fp, "\t\t\t</ListStyle>\n");
585  fprintf(fp, "\t\t</Style>\n");
586  fprintf(fp, "\t\t<Region>\n \t\t<LatLonAltBox>\n");
587  fprintf(fp, "\t\t\t\t<north>%f</north>\n", north);
588  fprintf(fp, "\t\t\t\t<south>%f</south>\n", south);
589  fprintf(fp, "\t\t\t\t<east>%f</east>\n", east);
590  fprintf(fp, "\t\t\t\t<west>%f</west>\n", west);
591  fprintf(fp, "\t\t\t</LatLonAltBox>\n");
592  fprintf(fp, "\t\t</Region>\n");
593  fprintf(fp, "\t\t<NetworkLink>\n");
594  fprintf(fp, "\t\t\t<open>1</open>\n");
595  fprintf(fp, "\t\t\t<Region>\n");
596  fprintf(fp, "\t\t\t\t<Lod>\n");
597  fprintf(fp, "\t\t\t\t\t<minLodPixels>%d</minLodPixels>\n", minlodpixels);
598  fprintf(fp, "\t\t\t\t\t<maxLodPixels>-1</maxLodPixels>\n");
599  fprintf(fp, "\t\t\t\t</Lod>\n");
600  fprintf(fp, "\t\t\t\t<LatLonAltBox>\n");
601  fprintf(fp, "\t\t\t\t\t<north>%f</north>\n", north);
602  fprintf(fp, "\t\t\t\t\t<south>%f</south>\n", south);
603  fprintf(fp, "\t\t\t\t\t<east>%f</east>\n", east);
604  fprintf(fp, "\t\t\t\t\t<west>%f</west>\n", west);
605  fprintf(fp, "\t\t\t\t</LatLonAltBox>\n");
606  fprintf(fp, "\t\t\t</Region>\n");
607  fprintf(fp, "\t\t\t<Link>\n");
608  fprintf(fp, "\t\t\t\t<href>0/0/0.kml</href>\n");
609  fprintf(fp, "\t\t\t\t<viewRefreshMode>onRegion</viewRefreshMode>\n");
610  fprintf(fp, "\t\t\t</Link>\n");
611  fprintf(fp, "\t\t</NetworkLink>\n");
612  fprintf(fp, "\t</Document>\n");
613  fprintf(fp, "</kml>\n");
614 
615  fclose(fp);
616  return true;
617 }
618 
620  ossim_int32 zoom,
621  ossim_int32 yloop,
622  ossim_int32 ix,
623  ossim_int32 iy,
624  ossim_int32 dxsize,
625  ossim_int32 dysize,
626  ossim_int32 xsize,
627  ossim_int32 ysize,
628  ossim_int32 maxzoom,
630  ossimString fileExt)
631 {
632  ossim_int32 yIndex = yloop-iy-1;
633  ossimIpt ul(dxsize*ix, dysize*(iy+1));
634  ossimIpt ur(dxsize*(ix+1), dysize*(iy+1));
635  ossimIpt lr(dxsize*(ix+1), dysize*iy);
636  ossimIpt ll(dxsize*ix, dysize*iy);
637  ossimIrect rect(ul, ur, lr, ll);
638 
639  ossim_float64 tnorth = 0.0;
640  ossim_float64 tsouth = 0.0;
641  ossim_float64 teast = 0.0;
642  ossim_float64 twest = 0.0;
643 
644  ossim_float64 upperleftT = 0.0;
645  ossim_float64 lowerleftT = 0.0;
646 
647  ossim_float64 rightbottomT = 0.0;
648  ossim_float64 leftbottomT = 0.0;
649 
650  ossim_float64 lefttopT = 0.0;
651  ossim_float64 righttopT = 0.0;
652 
653  ossim_float64 lowerrightT = 0.0;
654  ossim_float64 upperrightT = 0.0;
655 
656  ossimGpt ulg;
657  ossimGpt llg;
658  ossimGpt lrg;
659  ossimGpt urg;
660 
661  if (m_mapProjection.valid())
662  {
663  m_mapProjection->lineSampleToWorld(rect.ul(), ulg);
664  m_mapProjection->lineSampleToWorld(rect.ll(), llg);
665  m_mapProjection->lineSampleToWorld(rect.lr(), lrg);
666  m_mapProjection->lineSampleToWorld(rect.ur(), urg);
667 
668  twest = llg.lon;
669  tsouth = llg.lat;
670  teast = urg.lon;
671  tnorth = urg.lat;
672 
673  upperleftT = ulg.lon;
674  lefttopT = ulg.lat;
675 
676  lowerleftT = llg.lon;
677  leftbottomT = llg.lat;
678 
679  lowerrightT = lrg.lon;
680  rightbottomT = lrg.lat;
681 
682  upperrightT = urg.lon;
683  righttopT = urg.lat;
684  }
685 
686  std::vector<ossim_int32> xchildren;
687  std::vector<ossim_int32> ychildern;
688  std::vector<ossim_int32> ychildernIndex;
689 
690  ossim_int32 maxLodPix = -1;
691  if ( zoom < maxzoom )
692  {
693  ossim_float64 zareasize = pow(2.0, (maxzoom - zoom - 1))*dxsize;
694  ossim_float64 zareasize1 = pow(2.0, (maxzoom - zoom - 1))*dysize;
695  xchildren.push_back(ix*2);
696  ossim_int32 tmp = ix*2 + 1;
697  ossim_int32 tmp1 = (ossim_int32)ceil(xsize/zareasize);
698  if (tmp < tmp1)
699  {
700  xchildren.push_back(ix*2+1);
701  }
702 
703  ychildern.push_back(iy*2);
704  tmp = iy*2 + 1;
705  tmp1 = (ossim_int32)ceil(ysize/zareasize1);
706  if (tmp < tmp1)
707  {
708  ychildern.push_back(iy*2+1);
709  }
710 
711  ychildernIndex.push_back(yIndex*2);
712  tmp = yIndex*2 + 1;
713  tmp1 = (ossim_int32)ceil(ysize/zareasize1);
714  if (tmp < tmp1)
715  {
716  ychildernIndex.push_back(yIndex*2+1);
717  }
718  maxLodPix = 2048;
719  }
720 
721  FILE* fp = fopen(filename.c_str(), "wb");
722  if (fp == NULL)
723  {
724  return false;
725  }
726 
727  fprintf(fp, "<kml xmlns=\"http://earth.google.com/kml/2.1\" xmlns:gx=\"http://www.google.com/kml/ext/2.2\">\n");
728  fprintf(fp, "\t<Document>\n");
729  fprintf(fp, "\t\t<name>%d/%d/%d.kml</name>\n", zoom, ix, yIndex);
730  fprintf(fp, "\t\t<Style>\n");
731  fprintf(fp, "\t\t\t<ListStyle id=\"hideChildren\">\n");
732  fprintf(fp, "\t\t\t\t<listItemType>checkHideChildren</listItemType>\n");
733  fprintf(fp, "\t\t\t</ListStyle>\n");
734  fprintf(fp, "\t\t</Style>\n");
735  fprintf(fp, "\t\t<Region>\n");
736  fprintf(fp, "\t\t\t<Lod>\n");
737  fprintf(fp, "\t\t\t\t<minLodPixels>%d</minLodPixels>\n", 128);
738  fprintf(fp, "\t\t\t\t<maxLodPixels>%d</maxLodPixels>\n", maxLodPix);
739  fprintf(fp, "\t\t\t</Lod>\n");
740  fprintf(fp, "\t\t\t<LatLonAltBox>\n");
741  fprintf(fp, "\t\t\t\t<north>%f</north>\n", tnorth);
742  fprintf(fp, "\t\t\t\t<south>%f</south>\n", tsouth);
743  fprintf(fp, "\t\t\t\t<east>%f</east>\n", teast);
744  fprintf(fp, "\t\t\t\t<west>%f</west>\n", twest);
745  fprintf(fp, "\t\t\t</LatLonAltBox>\n");
746  fprintf(fp, "\t\t</Region>\n");
747  fprintf(fp, "\t\t<GroundOverlay>\n");
748  fprintf(fp, "\t\t\t<drawOrder>%d</drawOrder>\n", zoom);
749  fprintf(fp, "\t\t\t<Icon>\n");
750  fprintf(fp, "\t\t\t\t<href>%d%s</href>\n", yIndex, fileExt.c_str());
751  fprintf(fp, "\t\t\t</Icon>\n");
752  fprintf(fp, "\t\t\t<gx:LatLonQuad>\n");
753  fprintf(fp, "\t\t\t\t<coordinates>\n");
754  fprintf(fp, "\t\t\t\t\t%f, %f, 0\n", lowerleftT, leftbottomT);
755  fprintf(fp, "\t\t\t\t\t%f, %f, 0\n", lowerrightT, rightbottomT);
756  fprintf(fp, "\t\t\t\t\t%f, %f, 0\n", upperrightT, righttopT);
757  fprintf(fp, "\t\t\t\t\t%f, %f, 0\n", upperleftT, lefttopT);
758  fprintf(fp, "\t\t\t\t</coordinates>\n");
759  fprintf(fp, "\t\t\t</gx:LatLonQuad>\n");
760  fprintf(fp, "\t\t</GroundOverlay>\n");
761 
762  //generate lat, lon info and links for the previous zoom of kml
763  for (ossim_uint32 i = 0; i < xchildren.size(); i++)
764  {
765  int cx = xchildren[i];
766  for (ossim_uint32 j = 0; j < ychildern.size(); j++)
767  {
768  ossim_int32 cy = ychildern[j];
769  ossim_int32 cyIndex = ychildernIndex[ychildernIndex.size()-j-1];
770 
771  ossimIpt ulc(dxsize*cx, dysize*(cy+1));
772  ossimIpt urc(dxsize*(cx+1), dysize*(cy+1));
773  ossimIpt lrc(dxsize*(cx+1), dysize*cy);
774  ossimIpt llc(dxsize*cx, dysize*cy);
775  ossimIrect rectc(ulc, urc, lrc, llc);
776 
777  ossim_float64 cnorth = 0.0;
778  ossim_float64 csouth = 0.0;
779  ossim_float64 ceast = 0.0;
780  ossim_float64 cwest = 0.0;
781 
782  if (proj.valid())
783  {
784  ulg.makeNan();
785  lrg.makeNan();
786  proj->lineSampleToWorld(rectc.ll(), llg);
787  proj->lineSampleToWorld(rectc.ur(), urg);
788 
789  cwest = llg.lon;
790  csouth = llg.lat;
791 
792  ceast = urg.lon;
793  cnorth = urg.lat;
794  }
795 
796  fprintf(fp, "\t\t<NetworkLink>\n");
797  fprintf(fp, "\t\t\t<name>%d/%d/%d%s</name>\n", zoom+1, cx, cyIndex, fileExt.c_str());
798  fprintf(fp, "\t\t\t<Region>\n");
799  fprintf(fp, "\t\t\t\t<Lod>\n");
800  fprintf(fp, "\t\t\t\t\t<minLodPixels>128</minLodPixels>\n");
801  fprintf(fp, "\t\t\t\t\t<maxLodPixels>-1</maxLodPixels>\n");
802  fprintf(fp, "\t\t\t\t</Lod>\n");
803  fprintf(fp, "\t\t\t\t<LatLonAltBox>\n");
804  fprintf(fp, "\t\t\t\t\t<north>%f</north>\n", cnorth);
805  fprintf(fp, "\t\t\t\t\t<south>%f</south>\n", csouth);
806  fprintf(fp, "\t\t\t\t\t<east>%f</east>\n", ceast);
807  fprintf(fp, "\t\t\t\t\t<west>%f</west>\n", cwest);
808  fprintf(fp, "\t\t\t\t</LatLonAltBox>\n");
809  fprintf(fp, "\t\t\t</Region>\n");
810  fprintf(fp, "\t\t\t<Link>\n");
811  fprintf(fp, "\t\t\t\t<href>../../%d/%d/%d.kml</href>\n", zoom+1, cx, cyIndex);
812  fprintf(fp, "\t\t\t\t<viewRefreshMode>onRegion</viewRefreshMode>\n");
813  fprintf(fp, "\t\t\t\t<viewFormat/>\n");
814  fprintf(fp, "\t\t\t</Link>\n");
815  fprintf(fp, "\t\t</NetworkLink>\n");
816  }
817  }
818 
819  fprintf(fp, "\t</Document>\n");
820  fprintf(fp, "</kml>\n");
821  fclose(fp);
822  return true;
823 }
824 
825 bool ossimKmlSuperOverlayWriter::zipWithMinizip(std::vector<ossimString> srcFiles, ossimString srcDirectory, ossimString targetFile)
826 {
827  zipFile zipfile = zipOpen(targetFile.c_str(), 0);
828  if (!zipfile)
829  {
832  "Unable to open target zip file..");
833  return false;
834  }
835 
836  std::vector<ossimString>::iterator v1_Iter;
837  for(v1_Iter = srcFiles.begin(); v1_Iter != srcFiles.end(); v1_Iter++)
838  {
839  ossimString fileRead = *v1_Iter;
840 
841  // Find relative path and open new file with zip file
842  std::string relativeFileReadPath = fileRead;
843  ossim_int32 remNumChars = srcDirectory.size();
844  if(remNumChars > 0)
845  {
846  ossim_int32 f = fileRead.find(srcDirectory.string());
847  if( f >= 0 )
848  {
849  relativeFileReadPath.erase(f, remNumChars + 1); // 1 added for backslash at the end
850  }
851  }
852 
853  std::basic_string<char>::iterator iter1;
854  for (iter1 = relativeFileReadPath.begin(); iter1 != relativeFileReadPath.end(); iter1++)
855  {
856  int f = relativeFileReadPath.find("\\");
857  if (f >= 0)
858  {
859  relativeFileReadPath.replace(f, 1, "/");
860  }
861  else
862  {
863  break;
864  }
865  }
866  if (zipOpenNewFileInZip(zipfile, relativeFileReadPath.c_str(), 0, 0, 0, 0, 0, 0, Z_DEFLATED, Z_DEFAULT_COMPRESSION) != ZIP_OK)
867  {
870  "Unable to create file within the zip file..");
871  return false;
872  }
873 
874  // Read source file and write to zip file
875  std::fstream inFile (fileRead.c_str(), std::ios::binary | std::ios::in);
876  if (!inFile.is_open())
877  {
880  "Could not open source file..");
881  return false;
882  }
883  if (!inFile.good())
884  {
887  "Error reading source file..");
888  return false;
889  }
890 
891  // Read file in buffer
892  std::string fileData;
893  const unsigned int bufSize = 1024;
894  char buf[bufSize];
895  do
896  {
897  inFile.read(buf, bufSize);
898  fileData.append(buf, inFile.gcount());
899  } while (!inFile.eof() && inFile.good());
900 
901  if (zipWriteInFileInZip(zipfile, static_cast<const void*>(fileData.data()), static_cast<unsigned int>(fileData.size())) != ZIP_OK )
902  {
905  "Could not write to file within zip file..");
906  return false;
907  }
908 
909  // Close one src file zipped completely
910  if ( zipCloseFileInZip(zipfile) != ZIP_OK )
911  {
914  "Could not close file written within zip file..");
915  return false;
916  }
917  }
918 
919  zipClose(zipfile, 0);
920  return true;
921 }
922 
924 {
926  {
927  //---
928  // Send a view interface visitor to the input connection. This will find all view
929  // interfaces, set the view, and send a property event to output so that the combiner,
930  // if present, can reinitialize.
931  //---
936  }
937 }
OSSIMDLLEXPORT void ossimSetError(const char *className, ossim_int32 error, const char *fmtString=0,...)
virtual const ossimDpt & getDecimalDegreesPerPixel() const
Returns decimal degrees per pixel as an ossimDpt with "x" representing longitude and "y" representing...
ossimImageFileWriter * createWriterFromExtension(const ossimString &fileExtension) const
virtual void setOutputImageType(ossim_int32 type)
virtual ossimObject * dup() const =0
std::basic_fstream< char > fstream
Class for char mixed input and output file streams.
Definition: ossimIosFwd.h:50
static bool remove(const ossimFilename &pathname)
Removes pathname from filesystem if supported by platform.
ossimKmlSuperOverlayWriter()
default constructor
std::basic_stringstream< char > stringstream
Class for char mixed input and output memory streams.
Definition: ossimIosFwd.h:38
void generateTile(ossimString filename, ossim_int32 ix, ossim_int32 iy, ossim_int32 dxsize, ossim_int32 dysize)
Represents serializable keyword/value map.
static const ossimErrorCode OSSIM_OK
virtual ossim_uint32 getNumberOfOutputBands() const
Returns the number of bands in a tile returned from this TileSource.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
bool valid() const
Definition: ossimRefPtr.h:75
bool getFirst(ossimFilename &filename, int flags=OSSIM_DIR_DEFAULT)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
double y
Definition: ossimDpt.h:165
ossim_uint32 height() const
Definition: ossimIrect.h:487
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
ossimIrect theAreaOfInterest
static ossimImageWriterFactoryRegistry * instance()
Visitor to update view and then propagate property event to outputs.
Definition: ossimVisitor.h:179
void makeNan()
Definition: ossimGpt.h:130
static ossimString toString(bool aValue)
Numeric to string methods.
virtual bool isGeographic() const
const ossimIpt & ul() const
Definition: ossimIrect.h:274
static const ossimErrorCode OSSIM_ERROR
virtual void setDecimalDegreesPerPixel(const ossimDpt &gsd)
Pure virtual base class for image file writers.
const ossimIpt & ll() const
Definition: ossimIrect.h:277
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
virtual bool writeStream()
Method to write the image to a stream.
bool hasImageType(const ossimString &imageType) const
bool hasImageType(const ossimString& imageType) const
bool getNext(ossimFilename &filename) const
virtual void setMetersPerPixel(const ossimDpt &gsd)
void push_back(char c)
Equivalent to insert(end(), c).
Definition: ossimString.h:905
double ossim_float64
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
bool zipWithMinizip(std::vector< ossimString > srcFiles, ossimString srcDirectory, ossimString targetFile)
virtual void setProperty(ossimRefPtr< ossimProperty > property)
Will set the property whose name matches the argument "property->getName()".
virtual ossimGpt lineSampleToWorld(const ossimDpt &projectedPoint) const
virtual void setAreaOfInterest(const ossimIrect &areaOfInterest)
bool exists() const
ossim_float64 lon
Definition: ossimGpt.h:266
bool localToWorld(const ossimDpt &local_pt, ossimGpt &world_pt) const
Exposes the 3D projection from image to world coordinates.
std::string::size_type size() const
Definition: ossimString.h:405
ossimRefPtr< ossimImageSourceSequencer > theInputConnection
unsigned int ossim_uint32
#define PTR_CAST(T, p)
Definition: ossimRtti.h:321
virtual bool writeFile()
Writes the file to disk or a stream.
const ossimIpt & lr() const
Definition: ossimIrect.h:276
virtual ossimString getClassName() const
static ossimString downcase(const ossimString &aString)
Definition: ossimString.cpp:48
virtual ossim_int32 connectMyInputTo(ossimConnectableObject *inputObject, bool makeOutputConnection=true, bool createEventFlag=true)
Will try to connect this objects input to the passed in object.
virtual ossimRefPtr< ossimProperty > getProperty(const ossimString &name) const
ossim_uint32 width() const
Definition: ossimIrect.h:500
bool generateChildKml(ossimString filename, ossim_int32 zoom, ossim_int32 yloop, ossim_int32 ix, ossim_int32 iy, ossim_int32 dxsize, ossim_int32 dysize, ossim_int32 xsize, ossim_int32 ysize, ossim_int32 maxzoom, ossimRefPtr< ossimMapProjection > proj, ossimString fileExt)
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
const ossimIpt & ur() const
Definition: ossimIrect.h:275
bool open(const ossimFilename &dir)
virtual void setFilename(const ossimFilename &file)
const ossimProjection * getProjection() const
Access methods for projection (may be NULL pointer).
virtual bool saveState(ossimKeywordlist &kwl, const char *prefix=0) const
saves the state of the object.
virtual void setProperty(ossimRefPtr< ossimProperty > property)
virtual ossimErrorCode getErrorStatus() const
ossimRefPtr< ossimMapProjection > m_mapProjection
ossimFilename fileNoExtension() const
virtual void setAreaOfInterest(const ossimIrect &inputRect)
double x
Definition: ossimDpt.h:164
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 empty() const
Definition: ossimString.h:411
virtual void getImageTypeList(std::vector< ossimString > &imageTypeList) const
void getImageTypeList(std::vector<ossimString>& imageTypeList)const
virtual ossimString getShortName() const
bool hasNans() const
Definition: ossimIrect.h:337
ossimString ext() const
virtual void accept(ossimVisitor &visitor)
We will add a visitor interface for all connectable objects.
ossim_float64 lat
Definition: ossimGpt.h:265
virtual ossimString getExtension() const
Returns a 3-letter extension from the image type descriptor (theOutputImageType) that can be used for...
ossimRefPtr< ossimImageFileWriter > m_imageWriter
#define RTTI_DEF1(cls, name, b1)
Definition: ossimRtti.h:485
virtual ossimDpt getMetersPerPixel() const
bool generateRootKml(ossimString filename, ossim_float64 north, ossim_float64 south, ossim_float64 east, ossim_float64 west, ossim_int32 tilesize)
bool createDirectory(bool recurseFlag=true, int perm=0775) const
virtual void getPropertyNames(std::vector< ossimString > &propertyNames) const
Pushes this&#39;s names onto the list of property names.
virtual ossimString getLongName() const
ossimFilename path() const
std::string::size_type find(const std::string &s, std::string::size_type pos=0) const
Searches for s as a substring of *this, beginning at character pos of *this.
Definition: ossimString.h:753
OSSIMDLLEXPORT std::ostream & ossimNotify(ossimNotifyLevel level=ossimNotifyLevel_WARN)
virtual bool loadState(const ossimKeywordlist &kwl, const char *prefix=0)
Method to the load (recreate) the state of an object from a keyword list.
virtual bool execute()
Calls: writeFile() writeMetaDataFiles()
const ossimString & getName() const
void propagateViewChange()
Sends a view interface visitor to the input connetion.
int ossim_int32
const std::string & string() const
Definition: ossimString.h:414