Example #1
0
int QgsWFSData::pointsFromCoordinateString( std::list<QgsPoint>& points, const QString& coordString ) const
{
  //tuples are separated by space, x/y by ','
  QStringList tuples = coordString.split( mTupleSeparator, QString::SkipEmptyParts );
  QStringList tuples_coordinates;
  double x, y;
  bool conversionSuccess;

  QStringList::const_iterator tupleIterator;
  for ( tupleIterator = tuples.constBegin(); tupleIterator != tuples.constEnd(); ++tupleIterator )
  {
    tuples_coordinates = tupleIterator->split( mCoordinateSeparator, QString::SkipEmptyParts );
    if ( tuples_coordinates.size() < 2 )
    {
      continue;
    }
    x = tuples_coordinates.at( 0 ).toDouble( &conversionSuccess );
    if ( !conversionSuccess )
    {
      continue;
    }
    y = tuples_coordinates.at( 1 ).toDouble( &conversionSuccess );
    if ( !conversionSuccess )
    {
      continue;
    }
    points.push_back( QgsPoint( x, y ) );
  }
  return 0;
}
Example #2
0
QStringList CMDLineRegistryUtils::getParameterValuesByWords( const QString & paramName, int startWith ) {
    QStringList words;
    QStringList res = getParameterValues( paramName, startWith );
    QStringList::const_iterator it = res.constBegin();
    while( it != res.constEnd() ) {
        words << it->split( QRegExp("\\s"), QString::SkipEmptyParts );
        ++it;
    }
    return words;
}
DataSetPtr readSelectedFeatures(char *filename, FeatureMappingPtr featureMapping)
{
	SelectedFeatures selectedFeatures;
	OverlappingFeatures overlappingFeatures;

	QFile featureFile(filename);
	if (!featureFile.open(QFile::ReadOnly))
	{
		qCritical() << "Could not open" << filename << "for reading!";
		return QSharedPointer<DataSet>(new DataSet(selectedFeatures, overlappingFeatures));
	}

	QTextStream featureStream(&featureFile);

	while(!featureStream.atEnd())
	{
		QString featureLine(featureStream.readLine());		
		QStringList lineParts = featureLine.split("\t");
		size_t featureNr = lineParts[0].toULong();
		QString featureName = (*featureMapping)[featureNr];

		SelectedFeature feature(featureName, lineParts[1].toDouble(),
			lineParts[2].toDouble());
		selectedFeatures.push_back(feature);

		QString overlapLine(featureStream.readLine());
		QStringList overlapParts = overlapLine.split("\t", QString::SkipEmptyParts);

		QVector<OverlappingFeature> overlaps;
		double normOverlapSum = 0.0;
		double normActivationSum = 0.0;
		for (QStringList::const_iterator iter = overlapParts.begin();
			iter != overlapParts.end(); ++iter)
		{
			QStringList overlap = iter->split('#');

			double normOverlap = overlap[0].toDouble();
			if (normOverlap > 0.0)
				normOverlapSum += normOverlap;
			else if (normOverlap < 0.0)
				normActivationSum += fabs(normOverlap);

			OverlappingFeature overlappingFeature(
				(*featureMapping)[overlap[1].toUInt()],
				normOverlap);
			overlaps.push_back(overlappingFeature);
		}


		overlappingFeatures[featureName] = Overlap(normOverlapSum, normActivationSum,
			overlaps);
	}

	return QSharedPointer<DataSet>(new DataSet(selectedFeatures, overlappingFeatures));
}
void QgsCoordinateTransformContext::readSettings()
{
  d.detach();
  d->mLock.lockForWrite();

  d->mSourceDestDatumTransforms.clear();
#if 0
  d->mSourceDatumTransforms.clear();
  d->mDestDatumTransforms.clear();
#endif

  QgsSettings settings;
  settings.beginGroup( QStringLiteral( "/Projections" ) );
  QStringList projectionKeys = settings.allKeys();

  //collect src and dest entries that belong together
  QMap< QPair< QString, QString >, QPair< int, int > > transforms;
  QStringList::const_iterator pkeyIt = projectionKeys.constBegin();
  for ( ; pkeyIt != projectionKeys.constEnd(); ++pkeyIt )
  {
    if ( pkeyIt->contains( QLatin1String( "srcTransform" ) ) || pkeyIt->contains( QLatin1String( "destTransform" ) ) )
    {
      QStringList split = pkeyIt->split( '/' );
      QString srcAuthId, destAuthId;
      if ( ! split.isEmpty() )
      {
        srcAuthId = split.at( 0 );
      }
      if ( split.size() > 1 )
      {
        destAuthId = split.at( 1 ).split( '_' ).at( 0 );
      }

      QString proj = settings.value( *pkeyIt ).toString();
      Q_NOWARN_DEPRECATED_PUSH
      int datumId = QgsDatumTransform::projStringToDatumTransformId( proj );
      Q_NOWARN_DEPRECATED_POP
      if ( pkeyIt->contains( QLatin1String( "srcTransform" ) ) )
      {
        transforms[ qMakePair( srcAuthId, destAuthId )].first = datumId;
      }
      else if ( pkeyIt->contains( QLatin1String( "destTransform" ) ) )
      {
        transforms[ qMakePair( srcAuthId, destAuthId )].second = datumId;
      }
    }
  }
	Qualities Visualizer::parseQualities(QString raw_qualities)
	{
		Qualities ret;
		QStringList qualities = raw_qualities.split('&');
		for(QStringList::const_iterator cqi = qualities.constBegin()
				, cqiend = qualities.constEnd(); cqi != cqiend; ++cqi)
			if(cqi->size())
			{
				QStringList key_and_value = cqi->split("=");
				QString key = key_and_value.takeFirst();
				filter_model_.checkKey(key);
				QVariant &value = ret[key];
				QString str = key_and_value.join("=");
				bool is_double = false;
				double d = str.toDouble(&is_double);
				value = is_double ? QVariant(d) : QVariant(str);
			}
		return ret;
	}
Example #6
0
void QgsSvgCache::containsElemParams( const QDomElement& elem, bool& hasFillParam, QColor& defaultFill, bool& hasOutlineParam, QColor& defaultOutline,
                                      bool& hasOutlineWidthParam, double& defaultOutlineWidth ) const
{
  if ( elem.isNull() )
  {
    return;
  }

  //we already have all the information, no need to go deeper
  if ( hasFillParam && hasOutlineParam && hasOutlineWidthParam )
  {
    return;
  }

  //check this elements attribute
  QDomNamedNodeMap attributes = elem.attributes();
  int nAttributes = attributes.count();

  QStringList valueSplit;
  for ( int i = 0; i < nAttributes; ++i )
  {
    QDomAttr attribute = attributes.item( i ).toAttr();
    if ( attribute.name().compare( "style", Qt::CaseInsensitive ) == 0 )
    {
      //entries separated by ';'
      QStringList entryList = attribute.value().split( ';' );
      QStringList::const_iterator entryIt = entryList.constBegin();
      for ( ; entryIt != entryList.constEnd(); ++entryIt )
      {
        QStringList keyValueSplit = entryIt->split( ':' );
        if ( keyValueSplit.size() < 2 )
        {
          continue;
        }
        QString key = keyValueSplit.at( 0 );
        QString value = keyValueSplit.at( 1 );
        valueSplit = value.split( " " );
        if ( !hasFillParam && value.startsWith( "param(fill)" ) )
        {
          hasFillParam = true;
          if ( valueSplit.size() > 1 )
          {
            defaultFill = QColor( valueSplit.at( 1 ) );
          }
        }
        else if ( !hasOutlineParam && value.startsWith( "param(outline)" ) )
        {
          hasOutlineParam = true;
          if ( valueSplit.size() > 1 )
          {
            defaultOutline = QColor( valueSplit.at( 1 ) );
          }
        }
        else if ( !hasOutlineWidthParam && value.startsWith( "param(outline-width)" ) )
        {
          hasOutlineWidthParam = true;
          if ( valueSplit.size() > 1 )
          {
            defaultOutlineWidth = valueSplit.at( 1 ).toDouble();
          }
        }
      }
    }
    else
    {
      QString value = attribute.value();
      valueSplit = value.split( " " );
      if ( !hasFillParam && value.startsWith( "param(fill)" ) )
      {
        hasFillParam = true;
        if ( valueSplit.size() > 1 )
        {
          defaultFill = QColor( valueSplit.at( 1 ) );
        }
      }
      else if ( !hasOutlineParam && value.startsWith( "param(outline)" ) )
      {
        hasOutlineParam = true;
        if ( valueSplit.size() > 1 )
        {
          defaultOutline = QColor( valueSplit.at( 1 ) );
        }
      }
      else if ( !hasOutlineWidthParam && value.startsWith( "param(outline-width)" ) )
      {
        hasOutlineWidthParam = true;
        if ( valueSplit.size() > 1 )
        {
          defaultOutlineWidth = valueSplit.at( 1 ).toDouble();
        }
      }
    }
  }

  //pass it further to child items
  QDomNodeList childList = elem.childNodes();
  int nChildren = childList.count();
  for ( int i = 0; i < nChildren; ++i )
  {
    QDomElement childElem = childList.at( i ).toElement();
    containsElemParams( childElem, hasFillParam, defaultFill, hasOutlineParam, defaultOutline, hasOutlineWidthParam, defaultOutlineWidth );
  }
}
Example #7
0
void QgsSvgCache::replaceElemParams( QDomElement& elem, const QColor& fill, const QColor& outline, double outlineWidth )
{
  if ( elem.isNull() )
  {
    return;
  }

  //go through attributes
  QDomNamedNodeMap attributes = elem.attributes();
  int nAttributes = attributes.count();
  for ( int i = 0; i < nAttributes; ++i )
  {
    QDomAttr attribute = attributes.item( i ).toAttr();
    //e.g. style="fill:param(fill);param(stroke)"
    if ( attribute.name().compare( "style", Qt::CaseInsensitive ) == 0 )
    {
      //entries separated by ';'
      QString newAttributeString;

      QStringList entryList = attribute.value().split( ';' );
      QStringList::const_iterator entryIt = entryList.constBegin();
      for ( ; entryIt != entryList.constEnd(); ++entryIt )
      {
        QStringList keyValueSplit = entryIt->split( ':' );
        if ( keyValueSplit.size() < 2 )
        {
          continue;
        }
        QString key = keyValueSplit.at( 0 );
        QString value = keyValueSplit.at( 1 );
        if ( value.startsWith( "param(fill" ) )
        {
          value = fill.name();
        }
        else if ( value.startsWith( "param(outline)" ) )
        {
          value = outline.name();
        }
        else if ( value.startsWith( "param(outline-width)" ) )
        {
          value = QString::number( outlineWidth );
        }

        if ( entryIt != entryList.constBegin() )
        {
          newAttributeString.append( ";" );
        }
        newAttributeString.append( key + ":" + value );
      }
      elem.setAttribute( attribute.name(), newAttributeString );
    }
    else
    {
      QString value = attribute.value();
      if ( value.startsWith( "param(fill)" ) )
      {
        elem.setAttribute( attribute.name(), fill.name() );
      }
      else if ( value.startsWith( "param(outline)" ) )
      {
        elem.setAttribute( attribute.name(), outline.name() );
      }
      else if ( value.startsWith( "param(outline-width)" ) )
      {
        elem.setAttribute( attribute.name(), QString::number( outlineWidth ) );
      }
    }
  }

  QDomNodeList childList = elem.childNodes();
  int nChildren = childList.count();
  for ( int i = 0; i < nChildren; ++i )
  {
    QDomElement childElem = childList.at( i ).toElement();
    replaceElemParams( childElem, fill, outline, outlineWidth );
  }
}
Example #8
0
QgsRasterLayer* QgsRemoteOWSBuilder::wmsLayerFromUrl( const QString& url, const QString& layerName, QList<QgsMapLayer*>& layersToRemove, bool allowCaching ) const
{
  QgsDebugMsg( "Entering" );
  QgsRasterLayer* result = nullptr;
  QString baseUrl, format, crs;
  QStringList layerList, styleList;

  if ( allowCaching )
  {
    result = qobject_cast<QgsRasterLayer*>( QgsMSLayerCache::instance()->searchLayer( url, layerName ) );
  }

  if ( result )
  {
    return result;
  }

  QStringList urlList = url.split( QStringLiteral( "?" ) );
  if ( urlList.size() < 2 )
  {
    return nullptr;
  }
  baseUrl = urlList.at( 0 );
  QStringList paramList = urlList.at( 1 ).split( QStringLiteral( "&" ) );

  QStringList::const_iterator paramIt;
  for ( paramIt = paramList.constBegin(); paramIt != paramList.constEnd(); ++paramIt )
  {
    if ( paramIt->startsWith( QLatin1String( "http" ), Qt::CaseInsensitive ) )
    {
      baseUrl = paramIt->split( QStringLiteral( "=" ) ).at( 1 );
    }
    else if ( paramIt->startsWith( QLatin1String( "FORMAT" ), Qt::CaseInsensitive ) )
    {
      format = paramIt->split( QStringLiteral( "=" ) ).at( 1 );
    }
    else if ( paramIt->startsWith( QLatin1String( "CRS" ), Qt::CaseInsensitive ) )
    {
      crs = paramIt->split( QStringLiteral( "=" ) ).at( 1 );
    }
    else if ( paramIt->startsWith( QLatin1String( "LAYERS" ), Qt::CaseInsensitive ) )
    {
      layerList = paramIt->split( QStringLiteral( "=" ) ).at( 1 ).split( QStringLiteral( "," ) );
    }
    else if ( paramIt->startsWith( QLatin1String( "STYLES" ), Qt::CaseInsensitive ) )
    {
      styleList = paramIt->split( QStringLiteral( "=" ) ).at( 1 ).split( QStringLiteral( "," ) );
    }
  }

  QgsDebugMsg( "baseUrl: " + baseUrl );
  QgsDebugMsg( "format: " + format );
  QgsDebugMsg( "crs: " + crs );
  QgsDebugMsg( "layerList first item: " + layerList.at( 0 ) );
  QgsDebugMsg( "styleList first item: " + styleList.at( 0 ) );

  QgsDataSourceUri uri;
  uri.setParam( QStringLiteral( "url" ), baseUrl );
  uri.setParam( QStringLiteral( "format" ), format );
  uri.setParam( QStringLiteral( "crs" ), crs );
  uri.setParam( QStringLiteral( "layers" ), layerList );
  uri.setParam( QStringLiteral( "styles" ), styleList );
  result = new QgsRasterLayer( uri.encodedUri(), QLatin1String( "" ), QStringLiteral( "wms" ) );
  if ( !result->isValid() )
  {
    return nullptr;
  }

  //insert into cache
  if ( allowCaching )
  {
    QgsMSLayerCache::instance()->insertLayer( url, layerName, result );
  }
  else
  {
    layersToRemove.push_back( result );
  }
  return result;
}