⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qgswmsprovider.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
            // though this was deprecated in WMS 1.1.1            QStringList srsList = e1.text().split(QRegExp("\\s+"));            QStringList::const_iterator i;            for (i = srsList.constBegin(); i != srsList.constEnd(); ++i)            {              layerProperty.crs.push_back(*i);            }          }          else if (e1.tagName() == "LatLonBoundingBox")        // legacy from earlier versions of WMS          {//            QgsDebugMsg("      LLBB is: '"  + e1.attribute("minx")  + "'.");//            QgsDebugMsg("      LLBB is: '"  + e1.attribute("miny")  + "'.");//            QgsDebugMsg("      LLBB is: '"  + e1.attribute("maxx")  + "'.");//            QgsDebugMsg("      LLBB is: '"  + e1.attribute("maxy")  + "'.");            layerProperty.ex_GeographicBoundingBox = QgsRect(                                                 e1.attribute("minx").toDouble(),                                                e1.attribute("miny").toDouble(),                                                e1.attribute("maxx").toDouble(),                                                e1.attribute("maxy").toDouble()                                              );          }	  else if(e1.tagName() == "EX_GeographicBoundingBox") //for WMS 1.3	    {	      QDomElement wBoundLongitudeElem = n1.namedItem("westBoundLongitude").toElement();	      QDomElement eBoundLongitudeElem = n1.namedItem("eastBoundLongitude").toElement();	      QDomElement sBoundLatitudeElem = n1.namedItem("southBoundLatitude").toElement();	      QDomElement nBoundLatitudeElem = n1.namedItem("northBoundLatitude").toElement();	      double wBLong, eBLong, sBLat, nBLat;	      bool wBOk, eBOk, sBOk, nBOk;	      wBLong = wBoundLongitudeElem.text().toDouble(&wBOk);	      eBLong = eBoundLongitudeElem.text().toDouble(&eBOk);	      sBLat = sBoundLatitudeElem.text().toDouble(&sBOk);	      nBLat = nBoundLatitudeElem.text().toDouble(&nBOk);	      if(wBOk && eBOk && sBOk && nBOk)		{		  layerProperty.ex_GeographicBoundingBox = QgsRect(wBLong, sBLat, eBLong, nBLat);		}	    }          else if (e1.tagName() == "BoundingBox")          {              // TODO: overwrite inherited              QgsWmsBoundingBoxProperty bbox;              bbox.box = QgsRect ( e1.attribute("minx").toDouble(),                                   e1.attribute("miny").toDouble(),                                   e1.attribute("maxx").toDouble(),                                   e1.attribute("maxy").toDouble()                                 );              bbox.crs = e1.attribute("SRS");              layerProperty.boundingBox.push_back ( bbox );          }          else if (e1.tagName() == "Dimension")          {            // TODO          }          else if (e1.tagName() == "Attribution")          {            // TODO          }          else if (e1.tagName() == "AuthorityURL")          {            // TODO          }          else if (e1.tagName() == "Identifier")          {            // TODO          }          else if (e1.tagName() == "MetadataURL")          {            // TODO          }          else if (e1.tagName() == "DataURL")          {            // TODO          }          else if (e1.tagName() == "FeatureListURL")          {            // TODO          }          else if (e1.tagName() == "Style")          {            QgsWmsStyleProperty styleProperty;            parseStyle(e1, styleProperty);            layerProperty.style.push_back(styleProperty);          }          else if (e1.tagName() == "MinScaleDenominator")          {            // TODO          }          else if (e1.tagName() == "MaxScaleDenominator")          {            // TODO          }          // If we got here then it's not in the WMS 1.3 standard      }      n1 = n1.nextSibling();  }  if (atleaf)  {    // We have all the information we need to properly evaluate a layer definition    // TODO: Save this somewhere    // Store if the layer is queryable    mQueryableForLayer[ layerProperty.name ] = layerProperty.queryable;    // Store the available Coordinate Reference Systems for the layer so that it    // can be combined with others later in supportedCrsForLayers()    crsForLayer[ layerProperty.name ] = layerProperty.crs;    // Store the WGS84 (CRS:84) extent so that it can be combined with others later    // in calculateExtent()    // Apply the coarse bounding box first    extentForLayer[ layerProperty.name ] = layerProperty.ex_GeographicBoundingBox;    // see if we can refine the bounding box with the CRS-specific bounding boxes    for ( uint i = 0; i < layerProperty.boundingBox.size(); i++ )     {      QgsDebugMsg("testing bounding box CRS which is "              + layerProperty.boundingBox[i].crs + "." );      if ( layerProperty.boundingBox[i].crs == DEFAULT_LATLON_CRS )      {        extentForLayer[ layerProperty.name ] =                 layerProperty.boundingBox[i].box;      }    }    QgsDebugMsg("extent for "              + layerProperty.name  + " is "             + extentForLayer[ layerProperty.name ].stringRep(3)  + "." );    // Insert into the local class' registry    layersSupported.push_back(layerProperty);    //if there are several <Layer> elements without a parent layer, the style list needs to be cleared    if(atleaf)      {	layerProperty.style.clear();      }  }//  QgsDebugMsg("exiting.");}bool QgsWmsProvider::parseServiceExceptionReportDOM(QByteArray const & xml){  QgsDebugMsg("entering.");#ifdef QGISDEBUG  //test the content of the QByteArray  QString responsestring(xml);  QgsDebugMsg("received the following data: "+responsestring);#endif  // Convert completed document into a DOM  QString errorMsg;  int errorLine;  int errorColumn;  bool contentSuccess = serviceExceptionReportDOM.setContent(xml, false, &errorMsg, &errorLine, &errorColumn);  if (!contentSuccess)  {    mErrorCaption = tr("DOM Exception");    mError = QString(tr("Could not get WMS Service Exception at %1: %2 at line %3 column %4")                .arg(baseUrl)                .arg(errorMsg)                .arg(errorLine)                .arg(errorColumn) );  QgsLogger::debug("DOM Exception: "+mError);    return FALSE;  }  QDomElement docElem = serviceExceptionReportDOM.documentElement();  // TODO: Assert the docElem.tagName() is "ServiceExceptionReport"  // serviceExceptionProperty.version = docElem.attribute("version");  // Start walking through XML.  QDomNode n = docElem.firstChild();  while( !n.isNull() ) {      QDomElement e = n.toElement(); // try to convert the node to an element.      if( !e.isNull() ) {          //QgsDebugMsg(e.tagName() ); // the node really is an element.          if (e.tagName() == "ServiceException")          {            QgsDebugMsg("  ServiceException.");            parseServiceException(e);          }      }      n = n.nextSibling();  }  QgsDebugMsg("exiting.");  return TRUE;}void QgsWmsProvider::parseServiceException(QDomElement const & e){  QgsDebugMsg("entering.");  QString seCode = e.attribute("code");  QString seText = e.text();  // set up friendly descriptions for the service exception  if      (seCode == "InvalidFormat")  {    mError = tr("Request contains a Format not offered by the server.");  }  else if (seCode == "InvalidCRS")  {    mError = tr("Request contains a CRS not offered by the server for one or more of the Layers in the request.");  }  else if (seCode == "InvalidSRS")  // legacy WMS < 1.3.0  {    mError = tr("Request contains a SRS not offered by the server for one or more of the Layers in the request.");  }  else if (seCode == "LayerNotDefined")  {    mError = tr("GetMap request is for a Layer not offered by the server, "                "or GetFeatureInfo request is for a Layer not shown on the map.");  }  else if (seCode == "StyleNotDefined")  {    mError = tr("Request is for a Layer in a Style not offered by the server.");  }  else if (seCode == "LayerNotQueryable")  {    mError = tr("GetFeatureInfo request is applied to a Layer which is not declared queryable.");  }  else if (seCode == "InvalidPoint")  {    mError = tr("GetFeatureInfo request contains invalid X or Y value.");  }  else if (seCode == "CurrentUpdateSequence")  {    mError = tr("Value of (optional) UpdateSequence parameter in GetCapabilities request is equal to "                "current value of service metadata update sequence number.");  }  else if (seCode == "InvalidUpdateSequence")  {    mError = tr("Value of (optional) UpdateSequence parameter in GetCapabilities request is greater "                "than current value of service metadata update sequence number.");  }  else if (seCode == "MissingDimensionValue")  {    mError = tr("Request does not include a sample dimension value, and the server did not declare a "                "default value for that dimension.");  }  else if (seCode == "InvalidDimensionValue")  {    mError = tr("Request contains an invalid sample dimension value.");  }  else if (seCode == "OperationNotSupported")  {    mError = tr("Request is for an optional operation that is not supported by the server.");  }  else  {    mError = tr("(Unknown error code from a post-1.3 WMS server)");  }  mError += "\n" + tr("The WMS vendor also reported: ");  mError += seText;  mError += "\n" + tr("This is probably due to a bug in the QGIS program.  Please report this error.");  // TODO = e.attribute("locator");  QgsDebugMsg("composed error message '"  + mError  + "'.");  QgsDebugMsg("exiting.");}QgsRect QgsWmsProvider::extent(){  if (extentDirty)  {    if (calculateExtent())    {      extentDirty = FALSE;    }  }  return layerExtent;}void QgsWmsProvider::reset(){  // TODO} bool QgsWmsProvider::isValid(){  return valid;} QString QgsWmsProvider::wmsVersion(){  // TODO  return NULL;} QStringList QgsWmsProvider::supportedImageEncodings(){  return mCapabilities.capability.request.getMap.format;} QStringList QgsWmsProvider::subLayers() const{  return activeSubLayers;}QStringList QgsWmsProvider::subLayerStyles() const{  return activeSubStyles;}void QgsWmsProvider::showStatusMessage(QString const & theMessage){    // Pass-through    // TODO: See if we can connect signal-to-signal.  This is a kludge according to the Qt doc.    emit setStatus(theMessage);}bool QgsWmsProvider::calculateExtent(){  //! \todo Make this handle non-geographic CRSs (e.g. floor plans) as per WMS spec  QgsDebugMsg("entered.");  // Make sure we know what extents are available  if (!retrieveServerCapabilities())  {    return FALSE;  }  // Set up the coordinate transform from the WMS standard CRS:84 bounding  // box to the user's selected CRS  if (!mCoordinateTransform)  {    QgsSpatialRefSys qgisSrsSource;    QgsSpatialRefSys qgisSrsDest;    qgisSrsSource.createFromOgcWmsCrs(DEFAULT_LATLON_CRS);    qgisSrsDest  .createFromOgcWmsCrs(imageCrs);    mCoordinateTransform = new QgsCoordinateTransform(qgisSrsSource, qgisSrsDest);  }  bool firstLayer = true; //flag to know if a layer is the first to be successfully transformed  for ( QStringList::Iterator it  = activeSubLayers.begin();                               it != activeSubLayers.end();                             ++it )   {    QgsDebugMsg("Sublayer Iterator: "+*it);    // This is the extent for the layer name in *it    QgsRect extent = extentForLayer.find( *it )->second;    // Convert to the user's CRS as required    try      {	extent = mCoordinateTransform->transformBoundingBox(extent, QgsCoordinateTransform::FORWARD);      }    catch(QgsCsException &cse)      {	UNUSED(cse);	continue; //ignore extents of layers which cannot be transformed info the required CRS      }    //make sure extent does not contain 'inf' or 'nan'    if (!extent.isFinite())    {      continue;    }    // add to the combined extent of all the active sublayers    if (firstLayer)    {      layerExtent = extent;    }    else    {      layerExtent.combineExtentWith( &extent );    }    firstLayer = false;    QgsDebugMsg("combined extent is '"  + layerExtent.stringRep()	      + "' after '"  + (*it) + "'." );  }  QgsDebugMsg("exiting with '"  + layerExtent.stringRep() + "'.");  return TRUE;}int QgsWmsProvider::capabilities() const{  int capability = 0;  bool canIdentify = FALSE;  QgsDebugMsg("entering.");  // Test for the ability to use the Identify map tool  for ( QStringList::const_iterator it  = activeSubLayers.begin();                                     it != activeSubLayers.end();                                   ++it )  {    // Is sublayer visible?    if (TRUE == activeSubLayerVisibility.find( *it )->second)    {      // Is sublayer queryable?      if (TRUE == mQueryableForLayer.find( *it )->second)      {        QgsDebugMsg("'"  + (*it)  + "' is queryable.");        canIdentify = TRUE;      }    }  }  // Collect all the test results into one bitmask  if (canIdentify)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -