bool rspfOgrVectorTileSource::open()
{
   const char* MODULE = "rspfOgrVectorTileSource::open";
  
   if (isOgrVectorDataSource() == false)
   {
      close();
      return false;
   }
   if(isOpen())
   {
      close();
   }
   theDataSource = OGRSFDriverRegistrar::Open(theImageFile,
                                              false);
   if (theDataSource)
   {
      int layerCount = theDataSource->GetLayerCount();
      theLayerVector.resize(layerCount);
      if(layerCount)
      {
         for(int i = 0; i < layerCount; ++i)
         {
            OGRLayer* layer = theDataSource->GetLayer(i);
            if(layer)
            {
               OGRSpatialReference* spatialReference = layer->GetSpatialRef();
               if(!spatialReference)
               {
                  if(traceDebug())
                  {
                     rspfNotify(rspfNotifyLevel_NOTICE)
                        << MODULE
                        << " No spatial reference given, assuming geographic"
                        << endl;
                  }
               }
            }
            else
            {
               if(traceDebug())
               {
                  rspfNotify(rspfNotifyLevel_NOTICE)
                     << MODULE
                     << " layer " << i << " is null." << endl;
               }
            }
            if (layer)
            {
               layer->GetExtent(&theBoundingExtent, true);
               rspfRefPtr<rspfProjection> proj = createProjFromReference(layer->GetSpatialRef());
               rspfRefPtr<rspfImageGeometry> imageGeometry = 0;
               bool isDefaultProjection = false;
               if(proj.valid())
               {
                  imageGeometry = new rspfImageGeometry(0, proj.get());
               }
               rspfMapProjection* mapProj = 0;
               if(imageGeometry.valid())
               {
                  mapProj = PTR_CAST(rspfMapProjection, imageGeometry->getProjection());
               }
               else
               {
                  mapProj = createDefaultProj();
                  imageGeometry = new rspfImageGeometry(0, mapProj);
                  isDefaultProjection = true;
               }
               if(mapProj)
               {
                  rspfDrect rect(theBoundingExtent.MinX,
                                  theBoundingExtent.MaxY,
                                  theBoundingExtent.MaxX,
                                  theBoundingExtent.MinY,
                                  RSPF_RIGHT_HANDED);
            
                  std::vector<rspfGpt> points;
                  if (isDefaultProjection || mapProj->isGeographic())
                  {
                     rspfGpt g1(rect.ul().y, rect.ul().x);
                     rspfGpt g2(rect.ur().y, rect.ur().x);
                     rspfGpt g3(rect.lr().y, rect.lr().x);
                     rspfGpt g4(rect.ll().y, rect.ll().x);
                     points.push_back(g1);
                     points.push_back(g2);
                     points.push_back(g3);
                     points.push_back(g4);
                  }
                  else
                  {
                     rspfGpt g1 = mapProj->inverse(rect.ul());
                     rspfGpt g2 = mapProj->inverse(rect.ur());
                     rspfGpt g3 = mapProj->inverse(rect.lr());
                     rspfGpt g4 = mapProj->inverse(rect.ll());
                     points.push_back(g1);
                     points.push_back(g2);
                     points.push_back(g3);
                     points.push_back(g4);
                  }
            
                  std::vector<rspfDpt> rectTmp;
                  rectTmp.resize(4);
                  for(std::vector<rspfGpt>::size_type index=0; index < 4; ++index)
                  {
                     imageGeometry->worldToLocal(points[(int)index], rectTmp[(int)index]);
                  }
                  rspfDrect rect2 = rspfDrect(rectTmp[0],
                                                rectTmp[1],
                                                rectTmp[2],
                                                rectTmp[3]);
                  theLayerVector[i] = new rspfOgrVectorLayerNode(rect2);
                  theLayerVector[i]->setGeoImage(imageGeometry);
                  if (i == 0)
                     theImageGeometry = imageGeometry;
               }
            }
         }
      }
   }
   else
   {
      delete theDataSource;
      theDataSource = 0;
      return false;
   }
   return (theDataSource!=0);
}
//*******************************************************************
// Public Method:
//*******************************************************************
bool ossimKmlSuperOverlayReader::open()
{
    // const char* MODULE = "ossimKmlSuperOverlayReader::open";
    bool result = false;

    if(isOpen())
    {
        close();
    }

    if (theImageFile.ext().downcase() == "kmz")
    {
        result = getTopLevelKmlFileInfo();
        if (result == false)
        {
            return result;
        }
    }
    else
    {
        m_xmlDocument = new ossimXmlDocument(theImageFile);
    }

    if ( m_xmlDocument.valid() )
    {
        ossimRefPtr<ossimXmlNode> rootNode = m_xmlDocument->getRoot();
        if (rootNode.valid())
        {
            std::vector<ossimRefPtr<ossimXmlNode> > nodes = rootNode->getChildNodes();
            result = isKmlSuperOverlayFile(nodes);

            if (result == false) //let gdal kml handle vector kml file
            {
                return result;
            }

            ossim_float64 north = 0.0;
            ossim_float64 south = 0.0;
            ossim_float64 east = 0.0;
            ossim_float64 west = 0.0;
            result = getCoordinate(nodes, north, south, east, west);

            if (result == false)
            {
                return result;
            }

            if (!theImageGeometry.valid())
            {
                theImageGeometry = new ossimImageGeometry(0, createDefaultProj(north, south, east, west));
                if (theImageGeometry.valid())
                {
                    result = true;

                    theImageBound.makeNan();

                    //if the projection is default or geographic, uses the bounding of the OGR Layer
                    vector<ossimGpt> points;
                    points.push_back(ossimGpt(north, west));
                    points.push_back(ossimGpt(north, east));
                    points.push_back(ossimGpt(south, east));
                    points.push_back(ossimGpt(south, west));


                    std::vector<ossimDpt> rectTmp;
                    rectTmp.resize(points.size());
                    for(std::vector<ossimGpt>::size_type index=0; index < points.size(); ++index)
                    {
                        theImageGeometry->worldToLocal(points[(int)index], rectTmp[(int)index]);
                    }

                    ossimDrect rect = ossimDrect(rectTmp[0],
                                                 rectTmp[1],
                                                 rectTmp[2],
                                                 rectTmp[3]);

                    theImageBound = rect;
                }
                else
                {
                    result = false;
                }
            }
        }
        else
        {
            result = false;
        }
    }
    else
    {
        result = false;
    }

    return result;
}