Skip to content
Permalink
Browse files

Add methods to directly retrieve/set coordinates for linestring nodes

Also add method to create QgsPointV2 from a QPointF
  • Loading branch information
nyalldawson committed Nov 18, 2015
1 parent 0b0c413 commit 5019fe244c4e4a4c152c633d686da28edc3219e0
@@ -26,6 +26,68 @@ class QgsLineStringV2: public QgsCurveV2
*/
QgsPointV2 pointN( int i ) const;

/** Returns the x-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns x-coordinate of node, or 0.0 if index is out of bounds
* @see setXAt()
*/
double xAt( int index ) const;

/** Returns the y-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns y-coordinate of node, or 0.0 if index is out of bounds
* @see setYAt()
*/
double yAt( int index ) const;

/** Returns the z-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns z-coordinate of node, or 0.0 if index is out of bounds or the line
* does not have a z dimension
* @see setZAt()
*/
double zAt( int index ) const;

/** Returns the m value of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns m value of node, or 0.0 if index is out of bounds or the line
* does not have m values
* @see setMAt()
*/
double mAt( int index ) const;

/** Sets the x-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0. Corresponding
* node must already exist in line string.
* @param x x-coordinate of node
* @see xAt()
*/
void setXAt( int index, double x );

/** Sets the y-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0. Corresponding
* node must already exist in line string.
* @param y y-coordinate of node
* @see yAt()
*/
void setYAt( int index, double y );

/** Sets the z-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0. Corresponding
* node must already exist in line string, and the line string must have z-dimension.
* @param z z-coordinate of node
* @see zAt()
*/
void setZAt( int index, double z );

/** Sets the m value of the specified node in the line string.
* @param index index of node, where the first node in the line is 0. Corresponding
* node must already exist in line string, and the line string must have m values.
* @param m m value of node
* @see mAt()
*/
void setMAt( int index, double m );

/** Resets the line string to match the specified list of points.
* @param points new points for line string. If empty, line string will be cleared.
*/
@@ -20,7 +20,11 @@ class QgsPointV2: public QgsAbstractGeometryV2

/** Construct a QgsPointV2 from a QgsPoint object
*/
QgsPointV2( const QgsPoint& p );
explicit QgsPointV2( const QgsPoint& p );

/** Construct a QgsPointV2 from a QPointF
*/
explicit QgsPointV2( const QPointF& p );

/** Construct a point with a specified type (eg PointZ, PointM) and initial x, y, z, and m values.
* @param type point type
@@ -45,6 +45,7 @@ void QgsLineStringV2::clear()
mZ.clear();
mM.clear();
mWkbType = QgsWKBTypes::Unknown;
mBoundingBox = QgsRectangle();
}

bool QgsLineStringV2::fromWkb( const unsigned char* wkb )
@@ -228,6 +229,64 @@ QgsPointV2 QgsLineStringV2::pointN( int i ) const
return QgsPointV2( t, x, y, z, m );
}

double QgsLineStringV2::xAt( int index ) const
{
if ( index >= 0 && index < mX.size() )
return mX.at( index );
else
return 0.0;
}

double QgsLineStringV2::yAt( int index ) const
{
if ( index >= 0 && index < mY.size() )
return mY.at( index );
else
return 0.0;
}

double QgsLineStringV2::zAt( int index ) const
{
if ( index >= 0 && index < mZ.size() )
return mZ.at( index );
else
return 0.0;
}

double QgsLineStringV2::mAt( int index ) const
{
if ( index >= 0 && index < mM.size() )
return mM.at( index );
else
return 0.0;
}

void QgsLineStringV2::setXAt( int index, double x )
{
if ( index >= 0 && index < mX.size() )
mX[ index ] = x;
mBoundingBox = QgsRectangle();
}

void QgsLineStringV2::setYAt( int index, double y )
{
if ( index >= 0 && index < mY.size() )
mY[ index ] = y;
mBoundingBox = QgsRectangle();
}

void QgsLineStringV2::setZAt( int index, double z )
{
if ( index >= 0 && index < mZ.size() )
mZ[ index ] = z;
}

void QgsLineStringV2::setMAt( int index, double m )
{
if ( index >= 0 && index < mM.size() )
mM[ index ] = m;
}

void QgsLineStringV2::points( QList<QgsPointV2>& pts ) const
{
pts.clear();
@@ -387,7 +446,7 @@ void QgsLineStringV2::transform( const QgsCoordinateTransform& ct, QgsCoordinate
{
delete[] zArray;
}

mBoundingBox = QgsRectangle();
}

void QgsLineStringV2::transform( const QTransform& t )
@@ -399,6 +458,7 @@ void QgsLineStringV2::transform( const QTransform& t )
t.map( mX.at( i ), mY.at( i ), &x, &y );
mX[i] = x; mY[i] = y;
}
mBoundingBox = QgsRectangle();
}

bool QgsLineStringV2::insertVertex( const QgsVertexId& position, const QgsPointV2& vertex )
@@ -45,6 +45,68 @@ class CORE_EXPORT QgsLineStringV2: public QgsCurveV2
*/
QgsPointV2 pointN( int i ) const;

/** Returns the x-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns x-coordinate of node, or 0.0 if index is out of bounds
* @see setXAt()
*/
double xAt( int index ) const;

/** Returns the y-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns y-coordinate of node, or 0.0 if index is out of bounds
* @see setYAt()
*/
double yAt( int index ) const;

/** Returns the z-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns z-coordinate of node, or 0.0 if index is out of bounds or the line
* does not have a z dimension
* @see setZAt()
*/
double zAt( int index ) const;

/** Returns the m value of the specified node in the line string.
* @param index index of node, where the first node in the line is 0
* @returns m value of node, or 0.0 if index is out of bounds or the line
* does not have m values
* @see setMAt()
*/
double mAt( int index ) const;

/** Sets the x-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0. Corresponding
* node must already exist in line string.
* @param x x-coordinate of node
* @see xAt()
*/
void setXAt( int index, double x );

/** Sets the y-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0. Corresponding
* node must already exist in line string.
* @param y y-coordinate of node
* @see yAt()
*/
void setYAt( int index, double y );

/** Sets the z-coordinate of the specified node in the line string.
* @param index index of node, where the first node in the line is 0. Corresponding
* node must already exist in line string, and the line string must have z-dimension.
* @param z z-coordinate of node
* @see zAt()
*/
void setZAt( int index, double z );

/** Sets the m value of the specified node in the line string.
* @param index index of node, where the first node in the line is 0. Corresponding
* node must already exist in line string, and the line string must have m values.
* @param m m value of node
* @see mAt()
*/
void setMAt( int index, double m );

/** Resets the line string to match the specified list of points.
* @param points new points for line string. If empty, line string will be cleared.
*/
@@ -34,6 +34,11 @@ QgsPointV2::QgsPointV2( const QgsPoint& p ): QgsAbstractGeometryV2(), mX( p.x()
mWkbType = QgsWKBTypes::Point;
}

QgsPointV2::QgsPointV2( const QPointF& p ): QgsAbstractGeometryV2(), mX( p.x() ), mY( p.y() ), mZ( 0.0 ), mM( 0.0 )
{
mWkbType = QgsWKBTypes::Point;
}

QgsPointV2::QgsPointV2( QgsWKBTypes::Type type, double x, double y, double z, double m ): mX( x ), mY( y ), mZ( z ), mM( m )
{
mWkbType = type;
@@ -75,6 +80,7 @@ bool QgsPointV2::fromWkb( const unsigned char* wkb )
if ( isMeasure() )
wkbPtr >> mM;

mBoundingBox = QgsRectangle(); //set bounding box invalid
return true;
}

@@ -197,11 +203,13 @@ void QgsPointV2::clear()
{
mWkbType = QgsWKBTypes::Unknown;
mX = mY = mZ = mM = 0.;
mBoundingBox = QgsRectangle(); //set bounding box invalid
}

void QgsPointV2::transform( const QgsCoordinateTransform& ct, QgsCoordinateTransform::TransformDirection d )
{
ct.transformInPlace( mX, mY, mZ, d );
mBoundingBox = QgsRectangle(); //set bounding box invalid
}

void QgsPointV2::coordinateSequence( QList< QList< QList< QgsPointV2 > > >& coord ) const
@@ -282,4 +290,5 @@ void QgsPointV2::transform( const QTransform& t )
qreal x, y;
t.map( mX, mY, &x, &y );
mX = x; mY = y;
mBoundingBox = QgsRectangle(); //set bounding box invalid
}
@@ -37,7 +37,11 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2

/** Construct a QgsPointV2 from a QgsPoint object
*/
QgsPointV2( const QgsPoint& p );
explicit QgsPointV2( const QgsPoint& p );

/** Construct a QgsPointV2 from a QPointF
*/
explicit QgsPointV2( const QPointF& p );

/** Construct a point with a specified type (eg PointZ, PointM) and initial x, y, z, and m values.
* @param type point type
@@ -111,13 +115,13 @@ class CORE_EXPORT QgsPointV2: public QgsAbstractGeometryV2
* @see x()
* @see rx()
*/
void setX( double x ) { mX = x; }
void setX( double x ) { mX = x; mBoundingBox = QgsRectangle(); }

/** Sets the point's y-coordinate.
* @see y()
* @see ry()
*/
void setY( double y ) { mY = y; }
void setY( double y ) { mY = y; mBoundingBox = QgsRectangle(); }

/** Sets the point's z-coordinate.
* @see z()

0 comments on commit 5019fe2

Please sign in to comment.
You can’t perform that action at this time.