本文整理汇总了C++中QgsPointXY函数的典型用法代码示例。如果您正苦于以下问题:C++ QgsPointXY函数的具体用法?C++ QgsPointXY怎么用?C++ QgsPointXY使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了QgsPointXY函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: QgsPointXY
double QgsLayoutItemScaleBar::mapWidth() const
{
if ( !mMap )
{
return 0.0;
}
QgsRectangle mapExtent = mMap->extent();
if ( mSettings.units() == QgsUnitTypes::DistanceUnknownUnit )
{
return mapExtent.width();
}
else
{
QgsDistanceArea da;
da.setSourceCrs( mMap->crs(), mLayout->project()->transformContext() );
da.setEllipsoid( mLayout->project()->ellipsoid() );
QgsUnitTypes::DistanceUnit units = da.lengthUnits();
double measure = da.measureLine( QgsPointXY( mapExtent.xMinimum(), mapExtent.yMinimum() ),
QgsPointXY( mapExtent.xMaximum(), mapExtent.yMinimum() ) );
measure /= QgsUnitTypes::fromUnitToUnitFactor( mSettings.units(), units );
return measure;
}
}
示例2: QgsRectangle
void TestQgsRectangle::include()
{
QgsRectangle rect1 = QgsRectangle( 10.0, 20.0, 110.0, 220.0 );
// inside
rect1.include( QgsPointXY( 15, 50 ) );
QCOMPARE( rect1.xMinimum(), 10.0 );
QCOMPARE( rect1.yMinimum(), 20.0 );
QCOMPARE( rect1.xMaximum(), 110.0 );
QCOMPARE( rect1.yMaximum(), 220.0 );
rect1.include( QgsPointXY( 5, 50 ) );
QCOMPARE( rect1.xMinimum(), 5.0 );
QCOMPARE( rect1.yMinimum(), 20.0 );
QCOMPARE( rect1.xMaximum(), 110.0 );
QCOMPARE( rect1.yMaximum(), 220.0 );
rect1.include( QgsPointXY( 15, 12 ) );
QCOMPARE( rect1.xMinimum(), 5.0 );
QCOMPARE( rect1.yMinimum(), 12.0 );
QCOMPARE( rect1.xMaximum(), 110.0 );
QCOMPARE( rect1.yMaximum(), 220.0 );
rect1.include( QgsPointXY( 115, 12 ) );
QCOMPARE( rect1.xMinimum(), 5.0 );
QCOMPARE( rect1.yMinimum(), 12.0 );
QCOMPARE( rect1.xMaximum(), 115.0 );
QCOMPARE( rect1.yMaximum(), 220.0 );
rect1.include( QgsPointXY( 115, 242 ) );
QCOMPARE( rect1.xMinimum(), 5.0 );
QCOMPARE( rect1.yMinimum(), 12.0 );
QCOMPARE( rect1.xMaximum(), 115.0 );
QCOMPARE( rect1.yMaximum(), 242.0 );
}
示例3: QgsPointXY
void QgsGrassRegionEdit::drawRegion( QgsMapCanvas *canvas, QgsRubberBand *rubberBand, const QgsRectangle &rect, const QgsCoordinateTransform &coordinateTransform, bool isPolygon )
{
QVector<QgsPointXY> points;
points.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
points.append( QgsPointXY( rect.xMaximum(), rect.yMinimum() ) );
points.append( QgsPointXY( rect.xMaximum(), rect.yMaximum() ) );
points.append( QgsPointXY( rect.xMinimum(), rect.yMaximum() ) );
if ( !isPolygon )
{
points.append( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
}
if ( coordinateTransform.isValid() )
{
transform( canvas, points, coordinateTransform );
}
rubberBand->reset( isPolygon ? QgsWkbTypes::PolygonGeometry : QgsWkbTypes::LineGeometry );
for ( int i = 0; i < points.size(); i++ )
{
bool update = false; // true to update canvas
if ( i == points.size() - 1 )
update = true;
rubberBand->addPoint( points[i], update );
}
rubberBand->show();
}
示例4: baseContext
QgsCadUtils::AlignMapPointContext baseContext()
{
QgsCadUtils::AlignMapPointContext context;
context.snappingUtils = mSnappingUtils;
context.mapUnitsPerPixel = mMapSettings.mapUnitsPerPixel();
context.cadPointList << QgsPointXY() << QgsPointXY( 30, 20 ) << QgsPointXY( 30, 30 );
return context;
}
示例5: QgsRubberBand
void QgsMapToolLabel::createRubberBands()
{
delete mLabelRubberBand;
delete mFeatureRubberBand;
//label rubber band
QgsRectangle rect = mCurrentLabel.pos.labelRect;
mLabelRubberBand = new QgsRubberBand( mCanvas, QgsWkbTypes::LineGeometry );
mLabelRubberBand->addPoint( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
mLabelRubberBand->addPoint( QgsPointXY( rect.xMinimum(), rect.yMaximum() ) );
mLabelRubberBand->addPoint( QgsPointXY( rect.xMaximum(), rect.yMaximum() ) );
mLabelRubberBand->addPoint( QgsPointXY( rect.xMaximum(), rect.yMinimum() ) );
mLabelRubberBand->addPoint( QgsPointXY( rect.xMinimum(), rect.yMinimum() ) );
mLabelRubberBand->setColor( QColor( 0, 255, 0, 65 ) );
mLabelRubberBand->setWidth( 3 );
mLabelRubberBand->show();
//feature rubber band
QgsVectorLayer *vlayer = mCurrentLabel.layer;
if ( vlayer )
{
QgsFeature f;
if ( currentFeature( f, true ) )
{
QgsGeometry geom = f.geometry();
if ( !geom.isNull() )
{
QgsSettings settings;
int r = settings.value( QStringLiteral( "qgis/digitizing/line_color_red" ), 255 ).toInt();
int g = settings.value( QStringLiteral( "qgis/digitizing/line_color_green" ), 0 ).toInt();
int b = settings.value( QStringLiteral( "qgis/digitizing/line_color_blue" ), 0 ).toInt();
int a = settings.value( QStringLiteral( "qgis/digitizing/line_color_alpha" ), 200 ).toInt();
mFeatureRubberBand = new QgsRubberBand( mCanvas, geom.type() );
mFeatureRubberBand->setColor( QColor( r, g, b, a ) );
mFeatureRubberBand->setToGeometry( geom, vlayer );
mFeatureRubberBand->show();
}
}
//fixpoint rubber band
QgsPointXY fixPoint;
if ( currentLabelRotationPoint( fixPoint, false, false ) )
{
if ( mCanvas )
{
const QgsMapSettings &s = mCanvas->mapSettings();
fixPoint = s.mapToLayerCoordinates( vlayer, fixPoint );
}
QgsGeometry pointGeom = QgsGeometry::fromPointXY( fixPoint );
mFixPointRubberBand = new QgsRubberBand( mCanvas, QgsWkbTypes::LineGeometry );
mFixPointRubberBand->setColor( QColor( 0, 0, 255, 65 ) );
mFixPointRubberBand->setToGeometry( pointGeom, vlayer );
mFixPointRubberBand->show();
}
}
}
示例6: QgsDebugMsg
void QgsGrassNewMapset::setCurrentRegion()
{
QgsRectangle ext = mIface->mapCanvas()->extent();
QgsCoordinateReferenceSystem srs = mIface->mapCanvas()->mapSettings().destinationCrs();
QgsDebugMsg( "srs = " + srs.toWkt() );
std::vector<QgsPointXY> points;
// TODO: this is not perfect
points.push_back( QgsPointXY( ext.xMinimum(), ext.yMinimum() ) );
points.push_back( QgsPointXY( ext.xMaximum(), ext.yMaximum() ) );
// TODO add a method, this code is copy-paste from setSelectedRegion
if ( srs.isValid() && mCrs.isValid()
&& srs.srsid() != mCrs.srsid() )
{
QgsCoordinateTransform trans( srs, mCrs );
bool ok = true;
for ( int i = 0; i < 2; i++ )
{
try
{
points[i] = trans.transform( points[i] );
}
catch ( QgsCsException &cse )
{
Q_UNUSED( cse );
QgsDebugMsg( "Cannot transform point" );
ok = false;
break;
}
}
if ( !ok )
{
QgsGrass::warning( tr( "Cannot reproject region" ) );
return;
}
}
mNorthLineEdit->setText( QString::number( points[1].y() ) );
mSouthLineEdit->setText( QString::number( points[0].y() ) );
mEastLineEdit->setText( QString::number( points[1].x() ) );
mWestLineEdit->setText( QString::number( points[0].x() ) );
mRegionModified = true;
checkRegion();
drawRegion();
QgsDebugMsg( "setCurrentRegion - End" );
}
示例7: allLayerFeatureIds
void QgsGeometryFollowBoundariesCheck::collectErrors( QList<QgsGeometryCheckError *> &errors, QStringList &/*messages*/, QAtomicInt *progressCounter, const QMap<QString, QgsFeatureIds> &ids ) const
{
if ( !mIndex || !mCheckLayer )
{
return;
}
QMap<QString, QgsFeatureIds> featureIds = ids.isEmpty() ? allLayerFeatureIds() : ids;
featureIds.remove( mCheckLayer->id() ); // Don't check layer against itself
QgsGeometryCheckerUtils::LayerFeatures layerFeatures( mContext->featurePools, featureIds, mCompatibleGeometryTypes, progressCounter );
for ( const QgsGeometryCheckerUtils::LayerFeature &layerFeature : layerFeatures )
{
const QgsAbstractGeometry *geom = layerFeature.geometry();
// The geometry to crs of the check layer
QgsCoordinateTransform crst = QgsCoordinateTransformCache::instance()->transform( layerFeature.layer().crs().authid(), mCheckLayer->crs().authid() );
QScopedPointer<QgsAbstractGeometry> geomt( geom->clone() );
geomt->transform( crst );
QSharedPointer<QgsGeometryEngine> geomEngine = QgsGeometryCheckerUtils::createGeomEngine( geomt.data(), mContext->tolerance );
// Get potential reference features
QgsRectangle searchBounds = geomt->boundingBox();
searchBounds.grow( mContext->tolerance );
QgsFeatureIds refFeatureIds = mIndex->intersects( searchBounds ).toSet();
QgsFeatureRequest refFeatureRequest = QgsFeatureRequest().setFilterFids( refFeatureIds ).setSubsetOfAttributes( QgsAttributeList() );
QgsFeatureIterator refFeatureIt = mCheckLayer->getFeatures( refFeatureRequest );
if ( refFeatureIds.isEmpty() )
{
// If no potential reference features are found, the geometry is definitely not following boundaries of reference layer features
errors.append( new QgsGeometryCheckError( this, layerFeature, QgsPointXY( geom->centroid() ) ) );
}
else
{
// All reference features must be either contained or disjoint from tested geometry
QgsFeature refFeature;
while ( refFeatureIt.nextFeature( refFeature ) )
{
QgsAbstractGeometry *refGeom = refFeature.geometry().geometry();
QSharedPointer<QgsGeometryEngine> refgeomEngine = QgsGeometryCheckerUtils::createGeomEngine( refGeom, mContext->tolerance );
QScopedPointer<QgsAbstractGeometry> reducedRefGeom( refgeomEngine->buffer( -mContext->tolerance, 0 ) );
if ( !( geomEngine->contains( reducedRefGeom.data() ) || geomEngine->disjoint( reducedRefGeom.data() ) ) )
{
errors.append( new QgsGeometryCheckError( this, layerFeature, QgsPointXY( geom->centroid() ) ) );
break;
}
}
}
}
}
示例8: testPointInPolygon
void testPointInPolygon()
{
QgsPointLocator loc( mVL );
QgsPointLocator::MatchList mValid = loc.pointInPolygon( QgsPointXY( 0.8, 0.8 ) );
QCOMPARE( mValid.count(), 1 );
QgsPointLocator::Match m = mValid[0];
QVERIFY( m.isValid() );
QVERIFY( m.hasArea() );
QCOMPARE( m.layer(), mVL );
QCOMPARE( m.featureId(), ( QgsFeatureId )1 );
QgsPointLocator::MatchList mInvalid = loc.pointInPolygon( QgsPointXY( 0, 0 ) );
QCOMPARE( mInvalid.count(), 0 );
}
示例9: testEdgesInTolerance
void testEdgesInTolerance()
{
QgsPointLocator loc( mVL );
QgsPointLocator::MatchList lst = loc.edgesInRect( QgsPointXY( 0, 0 ), 2 );
QCOMPARE( lst.count(), 3 );
QgsPointLocator::MatchList lst2 = loc.edgesInRect( QgsPointXY( 0, 0 ), 0.9 );
QCOMPARE( lst2.count(), 1 );
// test match filtering
FilterExcludeEdge myFilter( QgsPointXY( 1, 0 ), QgsPointXY( 0, 1 ) );
QgsPointLocator::MatchList lst3 = loc.edgesInRect( QgsPointXY( 0, 0 ), 2, &myFilter );
QCOMPARE( lst3.count(), 2 );
}
示例10: testCopy
void testCopy()
{
std::unique_ptr< QgsVectorLayer > vl = qgis::make_unique< QgsVectorLayer >( "Point", QString(), QStringLiteral( "memory" ) );
for ( QgsFeature f : _pointFeatures() )
vl->dataProvider()->addFeature( f );
std::unique_ptr< QgsSpatialIndexKDBush > index( new QgsSpatialIndexKDBush( *vl->dataProvider() ) );
// create copy of the index
std::unique_ptr< QgsSpatialIndexKDBush > indexCopy( new QgsSpatialIndexKDBush( *index ) );
QVERIFY( index->d == indexCopy->d );
QVERIFY( index->d->ref == 2 );
// test that copied index works
QList<QgsSpatialIndexKDBushData> fids = indexCopy->intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 1 );
QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) );
// check that the index is still shared
QVERIFY( index->d == indexCopy->d );
QVERIFY( index->d->ref == 2 );
index.reset();
// test that copied index still works
fids = indexCopy->intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 1 );
QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) );
QVERIFY( indexCopy->d->ref == 1 );
// assignment operator
std::unique_ptr< QgsVectorLayer > vl2 = qgis::make_unique< QgsVectorLayer >( "Point", QString(), QStringLiteral( "memory" ) );
QgsSpatialIndexKDBush index3( *vl2->dataProvider() );
QVERIFY( index3.size() == 0 );
fids = index3.intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 0 );
QVERIFY( index3.d->ref == 1 );
index3 = *indexCopy;
QVERIFY( index3.d == indexCopy->d );
QVERIFY( index3.d->ref == 2 );
fids = index3.intersects( QgsRectangle( 0, 0, 10, 10 ) );
QVERIFY( fids.count() == 1 );
QVERIFY( testContains( fids, 1, QgsPointXY( 1, 1 ) ) );
indexCopy.reset();
QVERIFY( index3.d->ref == 1 );
}
示例11: testExtent
void testExtent()
{
QgsRectangle bbox1( 10, 10, 11, 11 ); // out of layer's bounds
QgsPointLocator loc1( mVL, QgsCoordinateReferenceSystem(), &bbox1 );
QgsPointLocator::Match m1 = loc1.nearestVertex( QgsPointXY( 2, 2 ), 999 );
QVERIFY( !m1.isValid() );
QgsRectangle bbox2( 0, 0, 1, 1 ); // in layer's bounds
QgsPointLocator loc2( mVL, QgsCoordinateReferenceSystem(), &bbox2 );
QgsPointLocator::Match m2 = loc2.nearestVertex( QgsPointXY( 2, 2 ), 999 );
QVERIFY( m2.isValid() );
QCOMPARE( m2.point(), QgsPointXY( 1, 1 ) );
}
示例12: transformInPlace
QgsPointXY QgsMapToPixel::transform( const QgsPointXY &p ) const
{
qreal x = p.x(), y = p.y();
transformInPlace( x, y );
// QgsDebugMsg(QString("Point to pixel...X : %1-->%2, Y: %3 -->%4").arg(p.x()).arg(dx).arg(p.y()).arg(dy));
return QgsPointXY( x, y );
}
示例13: while
void QgsMapToolCapture::stopCapturing()
{
if ( mRubberBand )
{
delete mRubberBand;
mRubberBand = nullptr;
}
if ( mTempRubberBand )
{
delete mTempRubberBand;
mTempRubberBand = nullptr;
}
while ( !mGeomErrorMarkers.isEmpty() )
{
delete mGeomErrorMarkers.takeFirst();
}
mGeomErrors.clear();
mTracingStartPoint = QgsPointXY();
mCapturing = false;
mCaptureCurve.clear();
mSnappingMatches.clear();
if ( currentVectorLayer() )
currentVectorLayer()->triggerRepaint();
}
示例14: QgsFeatureRequest
void QgsNetworkAnalysisAlgorithmBase::loadPoints( QgsFeatureSource *source, QVector< QgsPointXY > &points, QHash< int, QgsAttributes > &attributes, QgsProcessingContext &context, QgsProcessingFeedback *feedback )
{
feedback->pushInfo( QObject::tr( "Loading points…" ) );
QgsFeature feat;
int i = 0;
int pointId = 1;
double step = source->featureCount() > 0 ? 100.0 / source->featureCount() : 0;
QgsFeatureIterator features = source->getFeatures( QgsFeatureRequest().setDestinationCrs( mNetwork->sourceCrs(), context.transformContext() ) );
while ( features.nextFeature( feat ) )
{
i++;
if ( feedback->isCanceled() )
{
break;
}
feedback->setProgress( i * step );
if ( !feat.hasGeometry() )
continue;
QgsGeometry geom = feat.geometry();
QgsAbstractGeometry::vertex_iterator it = geom.vertices_begin();
while ( it != geom.vertices_end() )
{
points.push_back( QgsPointXY( *it ) );
attributes.insert( pointId, feat.attributes() );
it++;
pointId++;
}
}
}
示例15: _pointFeature
static QgsFeature _pointFeature( QgsFeatureId id, qreal x, qreal y )
{
QgsFeature f( id );
QgsGeometry g = QgsGeometry::fromPointXY( QgsPointXY( x, y ) );
f.setGeometry( g );
return f;
}