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

📄 qgsmysqlprovider.cpp

📁 一个非常好的GIS开源新版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
            }            // at this point, one way or another, the current feature values            // are valid           feature.setValid( true );           ++mFid;             // increment to next feature ID           feature.setFeatureId( mFid );           unsigned char * geometry = new unsigned char[sizeof(wkbPoint)];           QByteArray  buffer;           buffer.setRawData( (const char*)geometry, sizeof(wkbPoint) ); // buffer                                                                         // points                                                                         // to                                                                         // geometry           QDataStream s( &buffer, QIODevice::WriteOnly ); // open on buffers's data           switch ( endian() )           {               case QgsDataProvider::NDR :                   // we're on a little-endian platform, so tell the data                   // stream to use that                   s.setByteOrder( QDataStream::LittleEndian );                   s << (Q_UINT8)1; // 1 is for little-endian                   break;               case QgsDataProvider::XDR :                   // don't change byte order since QDataStream is big endian by default                   s << (Q_UINT8)0; // 0 is for big-endian                   break;               default :                   qDebug( "%s:%d unknown endian", __FILE__, __LINE__ );                   delete [] geometry;                   return false;           }           s << (Q_UINT32)1; // 1 is for WKBPoint           s << x;           s << y;           feature.setGeometryAndOwnership( geometry, sizeof(wkbPoint) );           // ensure that the buffer doesn't delete the data on us           buffer.resetRawData( (const char*)geometry, sizeof(wkbPoint) );           if ( getAttributes && ! desiredAttributes )           {               for (int fi = 0; fi < attributeFields.size(); fi++)               {                   feature.addAttribute(attributeFields[fi].name(), tokens[fi]);               }           }           // regardless of whether getAttributes is true or not, if the           // programmer went through the trouble of passing in such a list of           // attribute fields, then obviously they want them           else if ( desiredAttributes )           {               for ( std::list<int>::const_iterator i = desiredAttributes->begin();                     i != desiredAttributes->end();                     ++i )               {                   feature.addAttribute(attributeFields[*i].name(), tokens[*i]);               }           }           return true;        } // if able to get x and y coordinates    } // ! textStream EOF    return false;} // getNextFeature_( QgsFeature & feature )/**  Get the next feature resulting from a select operation  Return 0 if there are no features in the selection set * @return false if unable to get the next feature */bool QgsMySQLProvider::getNextFeature(QgsFeature & feature,                                              bool fetchAttributes){    return getNextFeature_( feature, fetchAttributes );} // QgsMySQLProvider::getNextFeatureQgsFeature * QgsMySQLProvider::getNextFeature(bool fetchAttributes){    QgsFeature * f = new QgsFeature;    if ( getNextFeature( *f, fetchAttributes ) )    {        return f;    }        delete f;    return 0x0;} // QgsMySQLProvider::getNextFeature(bool fetchAttributes)QgsFeature * QgsMySQLProvider::getNextFeature(std::list<int> const & desiredAttributes, int featureQueueSize){    QgsFeature * f = new QgsFeature;    if ( getNextFeature_( *f, true, &desiredAttributes ) )    {        return f;    }        delete f;    return 0x0;} // QgsMySQLProvider::getNextFeature(std::list < int >&attlist)/** * Select features based on a bounding rectangle. Features can be retrieved * with calls to getFirstFeature and getNextFeature. * @param mbr QgsRect containing the extent to use in selecting features */void QgsMySQLProvider::select(QgsRect * rect, bool useIntersect){  // Setting a spatial filter doesn't make much sense since we have to  // compare each point against the rectangle.  // We store the rect and use it in getNextFeature to determine if the  // feature falls in the selection area  mSelectionRectangle = new QgsRect((*rect));  // Select implies an upcoming feature read so we reset the data source  reset();  // Reset the feature id to 0  mFid = 0;}/** * Identify features within the search radius specified by rect * @param rect Bounding rectangle of search radius * @return std::vector containing QgsFeature objects that intersect rect */std::vector < QgsFeature > &QgsMySQLProvider::identify(QgsRect * rect){  // reset the data source since we need to be able to read through  // all features  reset();  std::cerr << "Attempting to identify features falling within " << (const char *)rect->    stringRep().toLocal8Bit().data() << std::endl;  // select the features  select(rect);#ifdef WIN32  //TODO fix this later for win32  std::vector < QgsFeature > feat;  return feat;#endif}/*   unsigned char * QgsMySQLProvider::getGeometryPointer(OGRFeature *fet){   unsigned char *gPtr=0;// get the wkb representation//geom->exportToWkb((OGRwkbByteOrder) endian(), gPtr);return gPtr;}*/// Return the extent of the layerQgsRect *QgsMySQLProvider::extent(){  return new QgsRect(mExtent->xMin(), mExtent->yMin(), mExtent->xMax(),                     mExtent->yMax());}/**  * Return the feature type */int QgsMySQLProvider::geometryType() const{  return 1;                     // WKBPoint}/**  * Return the feature type */long QgsMySQLProvider::featureCount() const{  return mNumberFeatures;}/** * Return the number of fields */int QgsMySQLProvider::fieldCount() const{  return attributeFields.size();}/** * Fetch attributes for a selected feature */void QgsMySQLProvider::getFeatureAttributes(int key, QgsFeature * f){  //for (int i = 0; i < ogrFet->GetFieldCount(); i++) {  //  // add the feature attributes to the tree  //  OGRFieldDefn *fldDef = ogrFet->GetFieldDefnRef(i);  //  QString fld = fldDef->GetNameRef();  //  //    OGRFieldType fldType = fldDef->GetType();  //  QString val;  //  val = ogrFet->GetFieldAsString(i);  //  f->addAttribute(fld, val);  //}}std::vector<QgsField> const & QgsMySQLProvider::fields() const{  return attributeFields;}void QgsMySQLProvider::reset(){  // Reset the file pointer to BOF  mFile->reset();  // Reset feature id to 0  mFid = 0;  // Skip ahead one line since first record is always assumed to be  // the header record  QTextStream stream(mFile);  stream.readLine();}QString QgsMySQLProvider::minValue(int position){  if (position >= fieldCount())  {    std::      cerr << "Warning: access requested to invalid position " <<      "in QgsMySQLProvider::minValue(..)" << std::endl;  }  if (mMinMaxCacheDirty)  {    fillMinMaxCash();  }  return QString::number(mMinMaxCache[position][0], 'f', 2);}QString QgsMySQLProvider::maxValue(int position){  if (position >= fieldCount())  {    std::      cerr << "Warning: access requested to invalid position " <<      "in QgsMySQLProvider::maxValue(..)" << std::endl;  }  if (mMinMaxCacheDirty)  {    fillMinMaxCash();  }  return QString::number(mMinMaxCache[position][1], 'f', 2);}void QgsMySQLProvider::fillMinMaxCash(){  for (int i = 0; i < fieldCount(); i++)  {    mMinMaxCache[i][0] = DBL_MAX;    mMinMaxCache[i][1] = -DBL_MAX;  }  QgsFeature f;  reset();  getNextFeature(f, true);  do  {    for (int i = 0; i < fieldCount(); i++)    {      double value = (f.attributeMap())[i].fieldValue().toDouble();      if (value < mMinMaxCache[i][0])      {        mMinMaxCache[i][0] = value;      }      if (value > mMinMaxCache[i][1])      {        mMinMaxCache[i][1] = value;      }    }  }  while (getNextFeature(f, true));  mMinMaxCacheDirty = false;}//TODO - add sanity check for shape file layers, to include cheking to//       see if the .shp, .dbf, .shx files are all present and the layer//       actually has featuresbool QgsMySQLProvider::isValid(){  return mValid;}/**  * Check to see if the point is within the selection rectangle */bool QgsMySQLProvider::boundsCheck(double x, double y){  bool inBounds = (((x < mSelectionRectangle->xMax()) &&                    (x > mSelectionRectangle->xMin())) &&                   ((y < mSelectionRectangle->yMax()) &&                    (y > mSelectionRectangle->yMin())));  // QString hit = inBounds?"true":"false";  // std::cerr << "Checking if " << x << ", " << y << " is in " <<   //mSelectionRectangle->stringRep().ascii() << ": " << hit.ascii() << std::endl;   return inBounds;}int QgsMySQLProvider::capabilities() const{    return QgsVectorDataProvider::SaveAsShapefile;}bool QgsMySQLProvider::saveAsShapefile(){  // OGR based save to shapefile method removed, unused?  return false;}size_t QgsMySQLProvider::layerCount() const{    return 1;                   // XXX How to calculate the layers?} // QgsOgrProvider::layerCount()int *QgsMySQLProvider::getFieldLengths(){  // this function parses the entire data file and calculates the  // max for each  // Only do this if we haven't done it already (ie. the vector is  // empty)  int *lengths = new int[attributeFields.size()];  // init the lengths to zero  for (int il = 0; il < attributeFields.size(); il++)  {    lengths[il] = 0;  }  if (mValid)  {    reset();    // read the line    QTextStream stream(mFile);    QString line;    while (!stream.atEnd())    {      line = stream.readLine(); // line of text excluding '\n'      // split the line      QStringList parts = QStringList::split(QRegExp(mDelimiter), line, true);      // iterate over the parts and update the max value      for (int i = 0; i < parts.size(); i++)      {        if (parts[i] != QString::null)        {          // std::cerr << "comparing length for " << parts[i] << " against max len of " << lengths[i] << std::endl;           if (parts[i].length() > lengths[i])          {            lengths[i] = parts[i].length();          }        }      }    }  }  return lengths;}QString  QgsMySQLProvider::name() const{    return TEXT_PROVIDER_KEY;} // ::name()QString  QgsMySQLProvider::description() const{    return TEXT_PROVIDER_DESCRIPTION;} //  QgsMySQLProvider::name()/** * Class factory to return a pointer to a newly created  * QgsMySQLProvider object */QGISEXTERN QgsMySQLProvider *classFactory(const QString *uri){  return new QgsMySQLProvider(*uri);}/** Required key function (used to map the plugin to a data store type)*/QGISEXTERN QString providerKey(){    return TEXT_PROVIDER_KEY;}/** * Required description function  */QGISEXTERN QString description(){    return TEXT_PROVIDER_DESCRIPTION;}/** * Required isProvider function. Used to determine if this shared library * is a data provider plugin */QGISEXTERN bool isProvider(){  return true;}

⌨️ 快捷键说明

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