QgsRectangle QgsMapSettings::computeExtentForScale( const QgsPointXY &point, double scale, const QgsCoordinateReferenceSystem &sourceCrs ) const { QgsPointXY center = QgsCoordinateTransform( sourceCrs, destinationCrs(), mTransformContext ).transform( point ); // Output width in inches double outWIn = outputSize().width() / double( outputDpi() ); // Desired visible width (honouring scale) double scaledWIn = outWIn * scale; if ( mapUnits() == QgsUnitTypes::DistanceDegrees ) { // Start with an 1x1 extent around the center QgsRectangle ext( center.x() - 0.5, center.y() - 0.5, center.x() + 0.5, center.y() + 0.5 ); // Get scale at extent, and then scale extent to the desired scale double testScale = mScaleCalculator.calculate( ext, outputSize().width() ); ext.scale( scale / testScale ); return ext; } // Conversion from inches to mapUnits double conversionFactor = 12 * QgsUnitTypes::fromUnitToUnitFactor( QgsUnitTypes::DistanceFeet, mapUnits() ); double delta = 0.5 * scaledWIn * conversionFactor; return QgsRectangle( center.x() - delta, center.y() - delta, center.x() + delta, center.y() + delta ); }
bool QgsClockwiseAngleComparer::operator()( const QgsPointXY &a, const QgsPointXY &b ) const { const bool aIsLeft = a.x() < mVertex.x(); const bool bIsLeft = b.x() < mVertex.x(); if ( aIsLeft != bIsLeft ) return bIsLeft; if ( qgsDoubleNear( a.x(), mVertex.x() ) && qgsDoubleNear( b.x(), mVertex.x() ) ) { if ( a.y() >= mVertex.y() || b.y() >= mVertex.y() ) { return b.y() < a.y(); } else { return a.y() < b.y(); } } else { const QgsVector oa = a - mVertex; const QgsVector ob = b - mVertex; const double det = oa.crossProduct( ob ); if ( qgsDoubleNear( det, 0.0 ) ) { return oa.lengthSquared() < ob.lengthSquared(); } else { return det < 0; } } }
bool QgsExifTools::geoTagImage( const QString &imagePath, const QgsPointXY &location, const GeoTagDetails &details ) { try { std::unique_ptr< Exiv2::Image > image( Exiv2::ImageFactory::open( imagePath.toStdString() ) ); if ( !image ) return false; image->readMetadata(); Exiv2::ExifData &exifData = image->exifData(); exifData["Exif.GPSInfo.GPSVersionID"] = "2 0 0 0"; exifData["Exif.GPSInfo.GPSMapDatum"] = "WGS-84"; exifData["Exif.GPSInfo.GPSLatitude"] = doubleToExifCoordinate( location.y() ).toStdString(); exifData["Exif.GPSInfo.GPSLongitude"] = doubleToExifCoordinate( location.x() ).toStdString(); if ( !std::isnan( details.elevation ) ) { const QString elevationString = QStringLiteral( "%1/1000" ).arg( static_cast< int>( std::floor( std::abs( details.elevation ) * 1000 ) ) ); exifData["Exif.GPSInfo.GPSAltitude"] = elevationString.toStdString(); exifData["Exif.GPSInfo.GPSAltitudeRef"] = details.elevation < 0.0 ? "1" : "0"; } exifData["Exif.GPSInfo.GPSLatitudeRef"] = location.y() > 0 ? "N" : "S"; exifData["Exif.GPSInfo.GPSLongitudeRef"] = location.x() > 0 ? "E" : "W"; exifData["Exif.Image.GPSTag"] = 4908; image->writeMetadata(); } catch ( ... ) { return false; } return true; }
// // distance of point q from line through p in direction v // return >0 => q lies left of the line // <0 => q lies right of the line // double QgsGeometryValidator::distLine2Point( const QgsPointXY &p, QgsVector v, const QgsPointXY &q ) { if ( qgsDoubleNear( v.length(), 0 ) ) { throw QgsException( QObject::tr( "invalid line" ) ); } return ( v.x() * ( q.y() - p.y() ) - v.y() * ( q.x() - p.x() ) ) / v.length(); }
void CoordinateCapture::update( const QgsPointXY &point ) { //this is the coordinate resolved back to lat / lon QgsPointXY myUserCrsPoint = mTransform.transform( point ); mpUserCrsEdit->setText( QString::number( myUserCrsPoint.x(), 'f', mUserCrsDisplayPrecision ) + ',' + QString::number( myUserCrsPoint.y(), 'f', mUserCrsDisplayPrecision ) ); // This is the coordinate space of the map canvas mpCanvasEdit->setText( QString::number( point.x(), 'f', mCanvasDisplayPrecision ) + ',' + QString::number( point.y(), 'f', mCanvasDisplayPrecision ) ); }
void QgsMapToolRotateFeature::applyRotation( double rotation ) { mRotation = rotation; mRotationActive = false; QgsVectorLayer *vlayer = currentVectorLayer(); if ( !vlayer ) { deleteRubberband(); notifyNotVectorLayer(); return; } //calculations for affine transformation double angle = -1 * mRotation * ( M_PI / 180 ); QgsPointXY anchorPoint = toLayerCoordinates( vlayer, mStartPointMapCoords ); double a = std::cos( angle ); double b = -1 * std::sin( angle ); double c = anchorPoint.x() - std::cos( angle ) * anchorPoint.x() + std::sin( angle ) * anchorPoint.y(); double d = std::sin( angle ); double ee = std::cos( angle ); double f = anchorPoint.y() - std::sin( angle ) * anchorPoint.x() - std::cos( angle ) * anchorPoint.y(); vlayer->beginEditCommand( tr( "Features Rotated" ) ); int start; if ( vlayer->geometryType() == 2 ) { start = 1; } else { start = 0; } int i = 0; Q_FOREACH ( QgsFeatureId id, mRotatedFeatures ) { QgsFeature feat; vlayer->getFeatures( QgsFeatureRequest().setFilterFid( id ) ).nextFeature( feat ); QgsGeometry geom = feat.geometry(); i = start; QgsPointXY vertex = geom.vertexAt( i ); while ( vertex != QgsPointXY( 0, 0 ) ) { double newX = a * vertex.x() + b * vertex.y() + c; double newY = d * vertex.x() + ee * vertex.y() + f; vlayer->moveVertex( newX, newY, id, i ); i = i + 1; vertex = geom.vertexAt( i ); } }
QgsPointXY QgsMapToolRotateLabel::rotatePointClockwise( const QgsPointXY &input, const QgsPointXY ¢erPoint, double degrees ) const { double rad = -degrees / 180 * M_PI; double v1x = input.x() - centerPoint.x(); double v1y = input.y() - centerPoint.y(); double v2x = std::cos( rad ) * v1x - std::sin( rad ) * v1y; double v2y = std::sin( rad ) * v1x + std::cos( rad ) * v1y; return QgsPointXY( centerPoint.x() + v2x, centerPoint.y() + v2y ); }
bool QgsMapToolPinLabels::pinUnpinCurrentDiagram( bool pin ) { // skip diagrams if ( ! mCurrentLabel.pos.isDiagram ) return false; // verify attribute table has x, y fields mapped int xCol, yCol; double xPosOrig, yPosOrig; bool xSuccess, ySuccess; if ( !currentLabelDataDefinedPosition( xPosOrig, xSuccess, yPosOrig, ySuccess, xCol, yCol ) ) return false; // edit attribute table QgsVectorLayer *vlayer = mCurrentLabel.layer; int fid = mCurrentLabel.pos.featureId; bool writeFailed = false; QString labelText = currentLabelText( 24 ); if ( pin ) { QgsPointXY referencePoint = mCurrentLabel.pos.labelRect.center(); double labelX = referencePoint.x(); double labelY = referencePoint.y(); // transform back to layer crs QgsPointXY transformedPoint = mCanvas->mapSettings().mapToLayerCoordinates( vlayer, referencePoint ); labelX = transformedPoint.x(); labelY = transformedPoint.y(); vlayer->beginEditCommand( tr( "Pinned diagram" ) + QStringLiteral( " '%1'" ).arg( labelText ) ); writeFailed = !vlayer->changeAttributeValue( fid, xCol, labelX ); if ( !vlayer->changeAttributeValue( fid, yCol, labelY ) ) writeFailed = true; vlayer->endEditCommand(); } else { vlayer->beginEditCommand( tr( "Unpinned diagram" ) + QStringLiteral( " '%1'" ).arg( labelText ) ); writeFailed = !vlayer->changeAttributeValue( fid, xCol, QVariant( QString() ) ); if ( !vlayer->changeAttributeValue( fid, yCol, QVariant( QString() ) ) ) writeFailed = true; vlayer->endEditCommand(); } return !writeFailed; }
bool QgsGeometryValidator::intersectLines( const QgsPointXY &p, QgsVector v, const QgsPointXY &q, QgsVector w, QgsPointXY &s ) { double d = v.y() * w.x() - v.x() * w.y(); if ( qgsDoubleNear( d, 0 ) ) return false; double dx = q.x() - p.x(); double dy = q.y() - p.y(); double k = ( dy * w.x() - dx * w.y() ) / d; s = p + v * k; return true; }
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 ); }
void Qgs3DUtils::clampAltitudes( QgsLineString *lineString, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::AltitudeBinding altBind, const QgsPoint ¢roid, float height, const Qgs3DMapSettings &map ) { for ( int i = 0; i < lineString->nCoordinates(); ++i ) { float terrainZ = 0; if ( altClamp == Qgs3DTypes::AltClampRelative || altClamp == Qgs3DTypes::AltClampTerrain ) { QgsPointXY pt; if ( altBind == Qgs3DTypes::AltBindVertex ) { pt.setX( lineString->xAt( i ) ); pt.setY( lineString->yAt( i ) ); } else { pt.set( centroid.x(), centroid.y() ); } terrainZ = map.terrainGenerator()->heightAt( pt.x(), pt.y(), map ); } float geomZ = 0; if ( altClamp == Qgs3DTypes::AltClampAbsolute || altClamp == Qgs3DTypes::AltClampRelative ) geomZ = lineString->zAt( i ); float z = ( terrainZ + geomZ ) * map.terrainVerticalScale() + height; lineString->setZAt( i, z ); } }
QgsFeatureList QgsAddXYFieldsAlgorithm::processFeature( const QgsFeature &feature, QgsProcessingContext &context, QgsProcessingFeedback *feedback ) { if ( mTransformNeedsInitialization ) { mTransform = QgsCoordinateTransform( mSourceCrs, mCrs, context.transformContext() ); mTransformNeedsInitialization = false; } QVariant x; QVariant y; if ( feature.hasGeometry() ) { if ( feature.geometry().isMultipart() ) throw QgsProcessingException( QObject::tr( "Multipoint features are not supported - please convert to single point features first." ) ); const QgsPointXY point = feature.geometry().asPoint(); try { const QgsPointXY transformed = mTransform.transform( point ); x = transformed.x(); y = transformed.y(); } catch ( QgsCsException & ) { feedback->reportError( QObject::tr( "Could not transform point to destination CRS" ) ); } } QgsFeature f = feature; QgsAttributes attributes = f.attributes(); attributes << x << y; f.setAttributes( attributes ); return QgsFeatureList() << f; }
void QgsMapCanvasAnnotationItem::setFeatureForMapPosition() { if ( !mAnnotation || !mAnnotation->hasFixedMapPosition() ) return; QgsVectorLayer *vectorLayer = qobject_cast< QgsVectorLayer * >( mAnnotation->mapLayer() ); if ( !vectorLayer ) return; double halfIdentifyWidth = QgsMapTool::searchRadiusMU( mMapCanvas ); QgsPointXY mapPosition = mAnnotation->mapPosition(); try { QgsCoordinateTransform ct( mAnnotation->mapPositionCrs(), mMapCanvas->mapSettings().destinationCrs(), QgsProject::instance() ); if ( ct.isValid() ) mapPosition = ct.transform( mapPosition ); } catch ( QgsCsException & ) { } QgsRectangle searchRect( mapPosition.x() - halfIdentifyWidth, mapPosition.y() - halfIdentifyWidth, mapPosition.x() + halfIdentifyWidth, mapPosition.y() + halfIdentifyWidth ); searchRect = mMapCanvas->mapSettings().mapToLayerCoordinates( vectorLayer, searchRect ); QgsFeatureIterator fit = vectorLayer->getFeatures( QgsFeatureRequest().setFilterRect( searchRect ).setFlags( QgsFeatureRequest::ExactIntersect ).setLimit( 1 ) ); QgsFeature currentFeature; ( void )fit.nextFeature( currentFeature ); mAnnotation->setAssociatedFeature( currentFeature ); }
QgsPoint QgsMapToolCapture::mapPoint( const QgsPointXY &point ) const { QgsPoint newPoint( QgsWkbTypes::Point, point.x(), point.y() ); // get current layer QgsVectorLayer *vlayer = qobject_cast<QgsVectorLayer *>( mCanvas->currentLayer() ); if ( !vlayer ) { return newPoint; } // convert to the corresponding type for a full ZM support const QgsWkbTypes::Type type = vlayer->wkbType(); if ( QgsWkbTypes::hasZ( type ) && !QgsWkbTypes::hasM( type ) ) { newPoint.convertTo( QgsWkbTypes::PointZ ); } else if ( !QgsWkbTypes::hasZ( type ) && QgsWkbTypes::hasM( type ) ) { newPoint.convertTo( QgsWkbTypes::PointM ); } else if ( QgsWkbTypes::hasZ( type ) && QgsWkbTypes::hasM( type ) ) { newPoint.convertTo( QgsWkbTypes::PointZM ); } // set z value if necessary if ( QgsWkbTypes::hasZ( newPoint.wkbType() ) ) { newPoint.setZ( defaultZValue() ); } return newPoint; }
void QgsTessellatedPolygonGeometry::setPolygons( const QList<QgsPolygon *> &polygons, const QList<QgsFeatureId> &featureIds, const QgsPointXY &origin, float extrusionHeight, const QList<float> &extrusionHeightPerPolygon ) { Q_ASSERT( polygons.count() == featureIds.count() ); mTriangleIndexStartingIndices.reserve( polygons.count() ); mTriangleIndexFids.reserve( polygons.count() ); QgsTessellator tessellator( origin.x(), origin.y(), mWithNormals, mInvertNormals, mAddBackFaces ); for ( int i = 0; i < polygons.count(); ++i ) { Q_ASSERT( tessellator.dataVerticesCount() % 3 == 0 ); uint startingTriangleIndex = static_cast<uint>( tessellator.dataVerticesCount() / 3 ); mTriangleIndexStartingIndices.append( startingTriangleIndex ); mTriangleIndexFids.append( featureIds[i] ); QgsPolygon *polygon = polygons.at( i ); float extr = extrusionHeightPerPolygon.isEmpty() ? extrusionHeight : extrusionHeightPerPolygon.at( i ); tessellator.addPolygon( *polygon, extr ); } qDeleteAll( polygons ); QByteArray data( ( const char * )tessellator.data().constData(), tessellator.data().count() * sizeof( float ) ); int nVerts = data.count() / tessellator.stride(); mVertexBuffer->setData( data ); mPositionAttribute->setCount( nVerts ); if ( mNormalAttribute ) mNormalAttribute->setCount( nVerts ); }
void Qgs3DMapConfigWidget::apply() { QgsRasterLayer *demLayer = qobject_cast<QgsRasterLayer *>( cboTerrainLayer->currentLayer() ); bool needsUpdateOrigin = false; if ( demLayer ) { bool tGenNeedsUpdate = true; if ( mMap->terrainGenerator()->type() == QgsTerrainGenerator::Dem ) { // if we already have a DEM terrain generator, check whether there was actually any change QgsDemTerrainGenerator *oldDemTerrainGen = static_cast<QgsDemTerrainGenerator *>( mMap->terrainGenerator() ); if ( oldDemTerrainGen->layer() == demLayer && oldDemTerrainGen->resolution() == spinTerrainResolution->value() && oldDemTerrainGen->skirtHeight() == spinTerrainSkirtHeight->value() ) tGenNeedsUpdate = false; } if ( tGenNeedsUpdate ) { QgsDemTerrainGenerator *demTerrainGen = new QgsDemTerrainGenerator; demTerrainGen->setCrs( mMap->crs(), QgsProject::instance()->transformContext() ); demTerrainGen->setLayer( demLayer ); demTerrainGen->setResolution( spinTerrainResolution->value() ); demTerrainGen->setSkirtHeight( spinTerrainSkirtHeight->value() ); mMap->setTerrainGenerator( demTerrainGen ); needsUpdateOrigin = true; } } else if ( !demLayer && mMap->terrainGenerator()->type() != QgsTerrainGenerator::Flat ) { QgsFlatTerrainGenerator *flatTerrainGen = new QgsFlatTerrainGenerator; flatTerrainGen->setCrs( mMap->crs() ); flatTerrainGen->setExtent( mMainCanvas->fullExtent() ); mMap->setTerrainGenerator( flatTerrainGen ); needsUpdateOrigin = true; } if ( needsUpdateOrigin ) { // reproject terrain's extent to map CRS QgsRectangle te = mMap->terrainGenerator()->extent(); QgsCoordinateTransform terrainToMapTransform( mMap->terrainGenerator()->crs(), mMap->crs(), QgsProject::instance() ); te = terrainToMapTransform.transformBoundingBox( te ); QgsPointXY center = te.center(); mMap->setOrigin( QgsVector3D( center.x(), center.y(), 0 ) ); } mMap->setTerrainVerticalScale( spinTerrainScale->value() ); mMap->setMapTileResolution( spinMapResolution->value() ); mMap->setMaxTerrainScreenError( spinScreenError->value() ); mMap->setMaxTerrainGroundError( spinGroundError->value() ); mMap->setShowLabels( chkShowLabels->isChecked() ); mMap->setShowTerrainTilesInfo( chkShowTileInfo->isChecked() ); mMap->setShowTerrainBoundingBoxes( chkShowBoundingBoxes->isChecked() ); mMap->setShowCameraViewCenter( chkShowCameraViewCenter->isChecked() ); }
void QgsAnnotation::updateBalloon() { //first test if the point is in the frame. In that case we don't need a balloon. if ( !mHasFixedMapPosition || ( mOffsetFromReferencePoint.x() < 0 && ( mOffsetFromReferencePoint.x() + mFrameSize.width() ) > 0 && mOffsetFromReferencePoint.y() < 0 && ( mOffsetFromReferencePoint.y() + mFrameSize.height() ) > 0 ) ) { mBalloonSegment = -1; return; } //edge list QList<QLineF> segmentList; segmentList << segment( 0 ); segmentList << segment( 1 ); segmentList << segment( 2 ); segmentList << segment( 3 ); //find closest edge / closest edge point double minEdgeDist = std::numeric_limits<double>::max(); int minEdgeIndex = -1; QLineF minEdge; QgsPointXY minEdgePoint; QgsPointXY origin( 0, 0 ); for ( int i = 0; i < 4; ++i ) { QLineF currentSegment = segmentList.at( i ); QgsPointXY currentMinDistPoint; double currentMinDist = origin.sqrDistToSegment( currentSegment.x1(), currentSegment.y1(), currentSegment.x2(), currentSegment.y2(), currentMinDistPoint ); if ( currentMinDist < minEdgeDist ) { minEdgeIndex = i; minEdgePoint = currentMinDistPoint; minEdgeDist = currentMinDist; minEdge = currentSegment; } } if ( minEdgeIndex < 0 ) { return; } //make that configurable for the item double segmentPointWidth = 10; mBalloonSegment = minEdgeIndex; QPointF minEdgeEnd = minEdge.p2(); mBalloonSegmentPoint1 = QPointF( minEdgePoint.x(), minEdgePoint.y() ); if ( std::sqrt( minEdgePoint.sqrDist( minEdgeEnd.x(), minEdgeEnd.y() ) ) < segmentPointWidth ) { mBalloonSegmentPoint1 = pointOnLineWithDistance( minEdge.p2(), minEdge.p1(), segmentPointWidth ); } mBalloonSegmentPoint2 = pointOnLineWithDistance( mBalloonSegmentPoint1, minEdge.p2(), 10 ); }
QgsTriangle::QgsTriangle( const QgsPointXY &p1, const QgsPointXY &p2, const QgsPointXY &p3 ) { mWkbType = QgsWkbTypes::Triangle; QgsPoint pt1( p1 ); QgsPoint pt2( p2 ); QgsPoint pt3( p3 ); if ( !validateGeom( pt1, pt2, pt3 ) ) { return; } QVector< double > x; x << p1.x() << p2.x() << p3.x(); QVector< double > y; y << p1.y() << p2.y() << p3.y(); QgsLineString *ext = new QgsLineString( x, y ); setExteriorRing( ext ); }
void QgsMapToolIdentify::closestPointAttributes( const QgsAbstractGeometry &geometry, QgsMapLayer *layer, const QgsPointXY &layerPoint, QMap< QString, QString > &derivedAttributes ) { Q_UNUSED( layer ); // measure if ( QgsWkbTypes::hasM( geometry.wkbType() ) ) { QgsPoint closestPoint = QgsGeometryUtils::closestPoint( geometry, QgsPoint( layerPoint.x(), layerPoint.y() ) ); QString str = QLocale::system().toString( closestPoint.m(), 'g', 10 ); derivedAttributes.insert( QStringLiteral( "Closest point M" ), str ); } }
// return ratio [mu/lu] between map units and layer units // this is of course only an approximation double _ratioMU2LU( const QgsMapSettings &mapSettings, QgsMapLayer *layer ) { double distMU = mapSettings.mapUnitsPerPixel(); QgsPointXY ptMapCenterMU = mapSettings.visibleExtent().center(); QgsPointXY ptMapCenterRightMU( ptMapCenterMU.x() + distMU, ptMapCenterMU.y() ); QgsPointXY ptMapCenterLU = mapSettings.mapToLayerCoordinates( layer, ptMapCenterMU ); QgsPointXY ptMapCenterRightLU = mapSettings.mapToLayerCoordinates( layer, ptMapCenterRightMU ); double distLU = std::sqrt( ptMapCenterLU.sqrDist( ptMapCenterRightLU ) ); double ratio = distMU / distLU; return ratio; }
bool QgsAdvancedDigitizingDockWidget::alignToSegment( QgsMapMouseEvent *e, CadConstraint::LockMode lockMode ) { if ( mAdditionalConstraint == NoConstraint ) { return false; } bool previousPointExist, penulPointExist, snappedSegmentExist; QgsPointXY previousPt = previousPoint( &previousPointExist ); QgsPointXY penultimatePt = penultimatePoint( &penulPointExist ); mSnappedSegment = snapSegmentToAllLayers( e->originalMapPoint(), &snappedSegmentExist ); if ( !previousPointExist || !snappedSegmentExist ) { return false; } double angle = std::atan2( mSnappedSegment[0].y() - mSnappedSegment[1].y(), mSnappedSegment[0].x() - mSnappedSegment[1].x() ); if ( mAngleConstraint->relative() && penulPointExist ) { angle -= std::atan2( previousPt.y() - penultimatePt.y(), previousPt.x() - penultimatePt.x() ); } if ( mAdditionalConstraint == Perpendicular ) { angle += M_PI_2; } angle *= 180 / M_PI; mAngleConstraint->setValue( angle ); mAngleConstraint->setLockMode( lockMode ); if ( lockMode == CadConstraint::HardLock ) { mAdditionalConstraint = NoConstraint; } return true; }
QList<QgsFeatureId> QgsSpatialIndex::nearestNeighbor( const QgsPointXY &point, int neighbors ) const { QList<QgsFeatureId> list; QgisVisitor visitor( list ); double pt[2] = { point.x(), point.y() }; Point p( pt, 2 ); QMutexLocker locker( &d->mMutex ); d->mRTree->nearestNeighborQuery( neighbors, p, visitor ); return list; }
void QgsAdvancedDigitizingDockWidget::updateUnlockedConstraintValues( const QgsPointXY &point ) { bool previousPointExist, penulPointExist; QgsPointXY previousPt = previousPoint( &previousPointExist ); QgsPointXY penultimatePt = penultimatePoint( &penulPointExist ); // --- angle if ( !mAngleConstraint->isLocked() && previousPointExist ) { double angle = 0.0; if ( penulPointExist && mAngleConstraint->relative() ) { // previous angle angle = std::atan2( previousPt.y() - penultimatePt.y(), previousPt.x() - penultimatePt.x() ); } angle = ( std::atan2( point.y() - previousPt.y(), point.x() - previousPt.x() ) - angle ) * 180 / M_PI; // modulus angle = std::fmod( angle, 360.0 ); mAngleConstraint->setValue( angle ); } // --- distance if ( !mDistanceConstraint->isLocked() && previousPointExist ) { mDistanceConstraint->setValue( std::sqrt( previousPt.sqrDist( point ) ) ); } // --- X if ( !mXConstraint->isLocked() ) { if ( previousPointExist && mXConstraint->relative() ) { mXConstraint->setValue( point.x() - previousPt.x() ); } else { mXConstraint->setValue( point.x() ); } } // --- Y if ( !mYConstraint->isLocked() ) { if ( previousPointExist && mYConstraint->relative() ) { mYConstraint->setValue( point.y() - previousPt.y() ); } else { mYConstraint->setValue( point.y() ); } } }
float Qgs3DUtils::clampAltitude( const QgsPoint &p, Qgs3DTypes::AltitudeClamping altClamp, Qgs3DTypes::AltitudeBinding altBind, float height, const QgsPoint ¢roid, const Qgs3DMapSettings &map ) { float terrainZ = 0; if ( altClamp == Qgs3DTypes::AltClampRelative || altClamp == Qgs3DTypes::AltClampTerrain ) { QgsPointXY pt = altBind == Qgs3DTypes::AltBindVertex ? p : centroid; terrainZ = map.terrainGenerator()->heightAt( pt.x(), pt.y(), map ); } float geomZ = altClamp == Qgs3DTypes::AltClampAbsolute || altClamp == Qgs3DTypes::AltClampRelative ? p.z() : 0; float z = ( terrainZ + geomZ ) * map.terrainVerticalScale() + height; return z; }
void QgsLabelSearchTree::label( const QgsPointXY &p, QList<QgsLabelPosition *> &posList ) const { double c_min[2]; c_min[0] = p.x() - 0.1; c_min[1] = p.y() - 0.1; double c_max[2]; c_max[0] = p.x() + 0.1; c_max[1] = p.y() + 0.1; QList<QgsLabelPosition *> searchResults; mSpatialIndex.Search( c_min, c_max, searchCallback, &searchResults ); //tolerance +-0.1 could be high in case of degree crs, so check if p is really contained in the results posList.clear(); QList<QgsLabelPosition *>::const_iterator resultIt = searchResults.constBegin(); for ( ; resultIt != searchResults.constEnd(); ++resultIt ) { if ( ( *resultIt )->labelRect.contains( p ) ) { posList.push_back( *resultIt ); } } }
QgsRasterIdentifyResult QgsGrassRasterProvider::identify( const QgsPointXY &point, QgsRaster::IdentifyFormat format, const QgsRectangle &boundingBox, int width, int height, int /*dpi*/ ) { Q_UNUSED( boundingBox ); Q_UNUSED( width ); Q_UNUSED( height ); QMap<int, QVariant> results; QMap<int, QVariant> noDataResults; noDataResults.insert( 1, QVariant() ); QgsRasterIdentifyResult noDataResult( QgsRaster::IdentifyFormatValue, results ); if ( format != QgsRaster::IdentifyFormatValue ) { return QgsRasterIdentifyResult( QGS_ERROR( tr( "Format not supported" ) ) ); } if ( !extent().contains( point ) ) { return noDataResult; } // TODO: use doubles instead of strings // attention, value tool does his own tricks with grass identify() so it stops to refresh values outside extent or null values e.g. bool ok; double value = mRasterValue.value( point.x(), point.y(), &ok ); if ( !ok ) { return QgsRasterIdentifyResult( QGS_ERROR( tr( "Cannot read data" ) ) ); } // no data? if ( std::isnan( value ) || qgsDoubleNear( value, mNoDataValue ) ) { return noDataResult; } // Apply user no data QgsRasterRangeList myNoDataRangeList = userNoDataValues( 1 ); if ( QgsRasterRange::contains( value, myNoDataRangeList ) ) { return noDataResult; } results.insert( 1, value ); return QgsRasterIdentifyResult( QgsRaster::IdentifyFormatValue, results ); }
QgsPointXY QgsGeometryAnalyzer::createPointOffset( double x, double y, double dist, const QgsGeometry &lineGeom ) const { QgsPointXY p( x, y ); QgsPointXY minDistPoint; int afterVertexNr; lineGeom.closestSegmentWithContext( p, minDistPoint, afterVertexNr ); int beforeVertexNr = afterVertexNr - 1; QgsPointXY beforeVertex = lineGeom.vertexAt( beforeVertexNr ); QgsPointXY afterVertex = lineGeom.vertexAt( afterVertexNr ); //get normal vector double dx = afterVertex.x() - beforeVertex.x(); double dy = afterVertex.y() - beforeVertex.y(); double normalX = -dy; double normalY = dx; //#spellok double normalLength = sqrt( normalX * normalX + normalY * normalY ); //#spellok normalX *= ( dist / normalLength ); normalY *= ( dist / normalLength ); //#spellok double debugLength = sqrt( normalX * normalX + normalY * normalY ); //control //#spellok Q_UNUSED( debugLength ); return QgsPointXY( x - normalX, y - normalY ); //negative values -> left side, positive values -> right side //#spellok }
void QgsMapToolMoveLabel::canvasMoveEvent( QgsMapMouseEvent *e ) { if ( mLabelRubberBand ) { QgsPointXY pointCanvasCoords = toMapCoordinates( e->pos() ); double offsetX = pointCanvasCoords.x() - mStartPointMapCoords.x(); double offsetY = pointCanvasCoords.y() - mStartPointMapCoords.y(); mLabelRubberBand->setTranslationOffset( offsetX, offsetY ); mLabelRubberBand->updatePosition(); mLabelRubberBand->update(); mFixPointRubberBand->setTranslationOffset( offsetX, offsetY ); mFixPointRubberBand->updatePosition(); mFixPointRubberBand->update(); } }
void QgsMeshVectorRenderer::drawVectorArrow( const QgsPointXY &lineStart, double xVal, double yVal, double magnitude ) { QgsPointXY lineEnd; double vectorLength; double cosAlpha, sinAlpha; if ( calcVectorLineEnd( lineEnd, vectorLength, cosAlpha, sinAlpha, lineStart, xVal, yVal, magnitude ) ) return; // Make a set of vector head coordinates that we will place at the end of each vector, // scale, translate and rotate. QgsPointXY vectorHeadPoints[3]; QVector<QPointF> finalVectorHeadPoints( 3 ); double vectorHeadWidthRatio = mCfg.arrowHeadWidthRatio(); double vectorHeadLengthRatio = mCfg.arrowHeadLengthRatio(); // First head point: top of -> vectorHeadPoints[0].setX( -1.0 * vectorHeadLengthRatio ); vectorHeadPoints[0].setY( vectorHeadWidthRatio * 0.5 ); // Second head point: right of -> vectorHeadPoints[1].setX( 0.0 ); vectorHeadPoints[1].setY( 0.0 ); // Third head point: bottom of -> vectorHeadPoints[2].setX( -1.0 * vectorHeadLengthRatio ); vectorHeadPoints[2].setY( -1.0 * vectorHeadWidthRatio * 0.5 ); // Determine the arrow head coords for ( int j = 0; j < 3; j++ ) { finalVectorHeadPoints[j].setX( lineEnd.x() + ( vectorHeadPoints[j].x() * cosAlpha * vectorLength ) - ( vectorHeadPoints[j].y() * sinAlpha * vectorLength ) ); finalVectorHeadPoints[j].setY( lineEnd.y() - ( vectorHeadPoints[j].x() * sinAlpha * vectorLength ) - ( vectorHeadPoints[j].y() * cosAlpha * vectorLength ) ); } // Now actually draw the vector mContext.painter()->drawLine( lineStart.toQPointF(), lineEnd.toQPointF() ); mContext.painter()->drawPolygon( finalVectorHeadPoints ); }
void QgsMapToolMoveFeature::cadCanvasMoveEvent( QgsMapMouseEvent *e ) { if ( mRubberBand ) { QgsPointXY pointCanvasCoords = e->mapPoint(); double offsetX = pointCanvasCoords.x() - mStartPointMapCoords.x(); double offsetY = pointCanvasCoords.y() - mStartPointMapCoords.y(); mRubberBand->setTranslationOffset( offsetX, offsetY ); mRubberBand->updatePosition(); mRubberBand->update(); mSnapIndicator->setMatch( e->mapPointMatch() ); } else { mSnapIndicator->setMatch( e->mapPointMatch() ); } }