Skip to content

Commit

Permalink
- more sane function prototypes for searching for closest vertex/segment
Browse files Browse the repository at this point in the history
- fixed some problems in python bindings


git-svn-id: http://svn.osgeo.org/qgis/trunk@6896 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Apr 18, 2007
1 parent 6096bf4 commit 5a4d23f
Show file tree
Hide file tree
Showing 10 changed files with 130 additions and 139 deletions.
42 changes: 20 additions & 22 deletions python/core/qgsgeometry.sip
Expand Up @@ -206,7 +206,7 @@ class QgsGeometry
*/
// SIP: buffer will be transferred from python to C++
// TODO: create pythonic interface that will receive wkb as a string
void setWkbAndOwnership(unsigned char * wkb /Transfer/, size_t length);
void setWkbAndOwnership(unsigned char * wkb /Transfer, Array/, size_t length /ArraySize/);

/**
Returns the buffer containing this geometry in WKB format.
Expand Down Expand Up @@ -298,36 +298,34 @@ class QgsGeometry

*/
double sqrDistToVertexAt(QgsPoint& point,
QgsGeometryVertexIndex& atVertex);
QgsGeometryVertexIndex& atVertex /Out/);

/**
* Modifies x and y to indicate the location of
* the vertex at the given position number,
* ring and item (first number is index 0)
* to the given coordinates
*
* Returns TRUE if atVertex is a valid position on
* the geometry, otherwise FALSE.
*
* If FALSE, x and y are not modified.
* Returns coordinates of a vertex.
* @param atVertex index of the vertex
* @return Coordinates of the vertex or QgsPoint(0,0) on error
*/
bool vertexAt(double &x, double &y, QgsGeometryVertexIndex atVertex);
QgsPoint vertexAt(const QgsGeometryVertexIndex& atVertex);

/**
Returns, in atVertex, the closest vertex in this geometry to the given point.
The squared cartesian distance is also returned in sqrDist.
* Searches for the the closest vertex in this geometry to the given point.
* @param point Specifiest the point for search
* @param atVertex Receives index of the closest vertex
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
*/
QgsPoint closestVertexWithContext(QgsPoint& point,
QgsGeometryVertexIndex& atVertex,
double& sqrDist);
double closestVertexWithContext(const QgsPoint& point,
QgsGeometryVertexIndex& atVertex /Out/);

/**
Returns, in beforeVertex, the closest segment in this geometry to the given point.
The squared cartesian distance is also returned in sqrDist.
* Searches for the closest segment of geometry to the given point
* @param point Specifies the point for search
* @param minDistPoint Receives the nearest point on the segment
* @param beforeVertex Receives index of the vertex before the closest segment
* @return The squared cartesian distance is also returned in sqrDist, negative number on error
*/
QgsPoint closestSegmentWithContext(QgsPoint& point,
QgsGeometryVertexIndex& beforeVertex,
double& sqrDist);
double closestSegmentWithContext(const QgsPoint& point,
QgsPoint& minDistPoint /Out/,
QgsGeometryVertexIndex& beforeVertex /Out/);

/**Returns the bounding box of this feature*/
QgsRect boundingBox();
Expand Down
3 changes: 3 additions & 0 deletions python/core/qgspoint.sip
Expand Up @@ -62,6 +62,9 @@ public:
/**Returns the squared distance between this point and x,y*/
double sqrDist(double x, double y) const;

/**Returns the squared distance between this and other point*/
double sqrDist(const QgsPoint& other);

//! equality operator
bool operator==(const QgsPoint &other);

Expand Down
20 changes: 10 additions & 10 deletions python/core/qgsvectorlayer.sip
Expand Up @@ -185,7 +185,7 @@ public:
If there is no point within this tolerance, point is left unchanged.
@param tolerance The snapping tolerance
@return true if the position of point has been changed, and false otherwise */
bool snapPoint(QgsPoint& point, double tolerance);
bool snapPoint(QgsPoint& point /In, Out/, double tolerance);

/**Snaps a point to the closest vertex if there is one within the snapping tolerance
@param atVertex Set to a vertex index of the snapped-to vertex
Expand All @@ -199,11 +199,11 @@ public:
TODO: Handle returning multiple verticies if they are coincident
*/
bool snapVertexWithContext(QgsPoint& point,
QgsGeometryVertexIndex& atVertex,
int& beforeVertexIndex,
int& afterVertexIndex,
int& snappedFeatureId,
QgsGeometry& snappedGeometry,
QgsGeometryVertexIndex& atVertex /Out/,
int& beforeVertexIndex /Out/,
int& afterVertexIndex /Out/,
int& snappedFeatureId /Out/,
QgsGeometry& snappedGeometry /Out/,
double tolerance);

/**Snaps a point to the closest line segment if there is one within the snapping tolerance
Expand All @@ -215,10 +215,10 @@ public:

TODO: Handle returning multiple lineFeatures if they are coincident
*/
bool snapSegmentWithContext(QgsPoint& point,
QgsGeometryVertexIndex& beforeVertex,
int& snappedFeatureId,
QgsGeometry& snappedGeometry,
bool snapSegmentWithContext(QgsPoint& point /In, Out/,
QgsGeometryVertexIndex& beforeVertex /Out/,
int& snappedFeatureId /Out/,
QgsGeometry& snappedGeometry /Out/,
double tolerance);

/**
Expand Down
24 changes: 11 additions & 13 deletions src/app/qgsmaptoolvertexedit.cpp
Expand Up @@ -99,8 +99,6 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
{
QgsPoint point = toMapCoords(e->pos());

double x1, y1;
double x2, y2;
QgsGeometryVertexIndex index, rb1Index, rb2Index; //rb1Index/rb2Index is for rubberbanding

if (mTool == AddVertex)
Expand All @@ -122,20 +120,20 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)

index = mSnappedBeforeVertex;
// Get the endpoint of the snapped-to segment
mSnappedAtGeometry.vertexAt(x2, y2, index);
QgsPoint pnt2 = mSnappedAtGeometry.vertexAt(index);

// Get the startpoint of the snapped-to segment
index.decrement_back();
mStartPointValid = mSnappedAtGeometry.vertexAt(x1, y1, index);
QgsPoint pnt1 = mSnappedAtGeometry.vertexAt(index);

createRubberBand();

if (mStartPointValid)
if (pnt1 != QgsPoint(0,0))
{
mRubberBand->addPoint(QgsPoint(x1,y1));
mRubberBand->addPoint(pnt1);
}
mRubberBand->addPoint(toMapCoords(e->pos()));
mRubberBand->addPoint(QgsPoint(x2,y2));
mRubberBand->addPoint(pnt2);
}
else if (mTool == MoveVertex)
{
Expand Down Expand Up @@ -190,8 +188,8 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
if(mRubberBandIndex1 != -1)
{
rb1Index.push_back(mRubberBandIndex1);
mSnappedAtGeometry.vertexAt(x1, y1, rb1Index);
mRubberBand->addPoint(QgsPoint(x1,y1));
QgsPoint pnt1 = mSnappedAtGeometry.vertexAt(rb1Index);
mRubberBand->addPoint(pnt1);
mStartPointValid = true;
}
else
Expand All @@ -205,8 +203,8 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
if(mRubberBandIndex2 != -1)
{
rb2Index.push_back(mRubberBandIndex2);
mSnappedAtGeometry.vertexAt(x2, y2, rb2Index);
mRubberBand->addPoint(QgsPoint(x2,y2));
QgsPoint pnt2 = mSnappedAtGeometry.vertexAt(rb2Index);
mRubberBand->addPoint(pnt2);
}
#ifdef QGISDEBUG
qWarning("Creating rubber band for moveVertex");
Expand All @@ -230,11 +228,11 @@ void QgsMapToolVertexEdit::canvasPressEvent(QMouseEvent * e)
}

// Get the point of the snapped-to vertex
mSnappedAtGeometry.vertexAt(x1, y1, mSnappedAtVertex);
QgsPoint pnt = mSnappedAtGeometry.vertexAt(mSnappedAtVertex);

mCross = new QgsVertexMarker(mCanvas);
mCross->setIconType(QgsVertexMarker::ICON_X);
mCross->setCenter(QgsPoint(x1,y1));
mCross->setCenter(pnt);
}

}
Expand Down

0 comments on commit 5a4d23f

Please sign in to comment.