Skip to content

Commit

Permalink
further vertex editing changes
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5250 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 11, 2006
1 parent 60ecfb2 commit da21e23
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 70 deletions.
70 changes: 16 additions & 54 deletions src/core/qgsgeometry.cpp
Expand Up @@ -524,11 +524,12 @@ bool QgsGeometry::moveVertexAt(double x, double y,
geos::CoordinateSequence* sequence = mGeos->getCoordinates();
sequence->setAt(geos::Coordinate(x, y), atVertex.back());
setGeos( static_cast<geos::Geometry*>( geosGeometryFactory->createLineString(sequence) ) );
break;
mDirtyWkb = true;
return true;
}
case geos::GEOS_POLYGON:
{
if(moveVertexFromPolygon(atVertex.back(), x, y))
if(movePolygonVertex(atVertex.back(), x, y))
{
mDirtyWkb = true;
return true;
Expand All @@ -538,49 +539,12 @@ bool QgsGeometry::moveVertexAt(double x, double y,
return false;
}
}
mDirtyWkb = true;
return true;
}
}

return false;
}


bool QgsGeometry::deleteVertexAt(int atVertex,
const geos::CoordinateSequence* old_sequence,
geos::CoordinateSequence** new_sequence)
{
int numPoints = old_sequence->getSize();

// Bounds checking
if (
(atVertex < 0) ||
(atVertex >= numPoints) ||
(numPoints <= 2) // guard against collapsing to a point
)
{
(*new_sequence) = 0;
return FALSE;
}

// Copy to the new sequence, excepting the deleted vertex
(*new_sequence) = new geos::DefaultCoordinateSequence();

for (int i = 0; i < numPoints; i++)
{
// Do we delete (omit) the vertex here?
if (atVertex != i)
{
(*new_sequence)->add( old_sequence->getAt(i) );
}
}

// TODO: Check that the sequence is still simple, e.g. with geos::Geometry->isSimple()
return true;
}


bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)
{

Expand Down Expand Up @@ -608,21 +572,19 @@ bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)
{
// Get the embedded GEOS Coordinate Sequence
geos::LineString* geosls = static_cast<geos::LineString*>(mGeos);
const geos::CoordinateSequence* old_sequence = geosls->getCoordinatesRO();
geos::CoordinateSequence* new_sequence;

if ( deleteVertexAt(atVertex.back(), old_sequence, (&new_sequence) ) )
{
// Put in the new GEOS geometry
setGeos( static_cast<geos::Geometry*>( geosGeometryFactory->createLineString(new_sequence) ) );
mDirtyWkb = true;
return TRUE;
}
geos::CoordinateSequence* sequence = geosls->getCoordinates();
sequence->deleteAt(atVertex.back());
geos::LineString* newLineString = geosGeometryFactory->createLineString(sequence);
if(newLineString)
{
setGeos(newLineString);
mDirtyWkb = true;
return TRUE;
}
else
{
return FALSE;
}

{
return FALSE;
}
} // case geos::GEOS_LINESTRING

case geos::GEOS_LINEARRING: // a linear ring (linestring with 1st point == last point)
Expand Down Expand Up @@ -2087,7 +2049,7 @@ double QgsGeometry::distanceSquaredPointToSegment(QgsPoint& point,

}

bool QgsGeometry::moveVertexFromPolygon(int atVertex, double x, double y)
bool QgsGeometry::movePolygonVertex(int atVertex, double x, double y)
{
if(!mGeos)
{
Expand Down
17 changes: 1 addition & 16 deletions src/core/qgsgeometry.h
Expand Up @@ -243,24 +243,9 @@ class QgsGeometry {
const geos::CoordinateSequence* old_sequence,
geos::CoordinateSequence** new_sequence);

/** Removes the vertex at the given vertex index (first number is index 0)
* in the given GEOS Coordinate Sequence.
* @param old_sequence The sequence to update (The caller remains the owner).
* @param new_sequence The updated sequence (The caller becomes the owner if the function returns TRUE).
* Returns FALSE if atVertex does not correspond to a valid vertex number
* on the Coordinate Sequence, or if the number of remaining verticies
* would be less than two.
* It is up to the caller to distinguish between
* these error conditions. (Or maybe we add another method to this
* object to help make the distinction?)
*/
bool deleteVertexAt(int atVertex,
const geos::CoordinateSequence* old_sequence,
geos::CoordinateSequence** new_sequence);

/**Moves a vertex of mGeos to a new position. Internally, a new polygon is created instead of mGeos.
Returns true in case of success*/
bool moveVertexFromPolygon(int atVertex, double x, double y);
bool movePolygonVertex(int atVertex, double x, double y);

bool deleteVertexFromPolygon(int atVertex);

Expand Down

0 comments on commit da21e23

Please sign in to comment.