Skip to content

Commit d3b74cc

Browse files
author
mhugent
committed
further vertex editing changes
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5250 c8812cc2-4d05-0410-92ff-de0c093fc19c
1 parent b371ae3 commit d3b74cc

File tree

2 files changed

+17
-70
lines changed

2 files changed

+17
-70
lines changed

src/core/qgsgeometry.cpp

+16-54
Original file line numberDiff line numberDiff line change
@@ -524,11 +524,12 @@ bool QgsGeometry::moveVertexAt(double x, double y,
524524
geos::CoordinateSequence* sequence = mGeos->getCoordinates();
525525
sequence->setAt(geos::Coordinate(x, y), atVertex.back());
526526
setGeos( static_cast<geos::Geometry*>( geosGeometryFactory->createLineString(sequence) ) );
527-
break;
527+
mDirtyWkb = true;
528+
return true;
528529
}
529530
case geos::GEOS_POLYGON:
530531
{
531-
if(moveVertexFromPolygon(atVertex.back(), x, y))
532+
if(movePolygonVertex(atVertex.back(), x, y))
532533
{
533534
mDirtyWkb = true;
534535
return true;
@@ -538,49 +539,12 @@ bool QgsGeometry::moveVertexAt(double x, double y,
538539
return false;
539540
}
540541
}
541-
mDirtyWkb = true;
542-
return true;
543542
}
544543
}
545544

546545
return false;
547546
}
548547

549-
550-
bool QgsGeometry::deleteVertexAt(int atVertex,
551-
const geos::CoordinateSequence* old_sequence,
552-
geos::CoordinateSequence** new_sequence)
553-
{
554-
int numPoints = old_sequence->getSize();
555-
556-
// Bounds checking
557-
if (
558-
(atVertex < 0) ||
559-
(atVertex >= numPoints) ||
560-
(numPoints <= 2) // guard against collapsing to a point
561-
)
562-
{
563-
(*new_sequence) = 0;
564-
return FALSE;
565-
}
566-
567-
// Copy to the new sequence, excepting the deleted vertex
568-
(*new_sequence) = new geos::DefaultCoordinateSequence();
569-
570-
for (int i = 0; i < numPoints; i++)
571-
{
572-
// Do we delete (omit) the vertex here?
573-
if (atVertex != i)
574-
{
575-
(*new_sequence)->add( old_sequence->getAt(i) );
576-
}
577-
}
578-
579-
// TODO: Check that the sequence is still simple, e.g. with geos::Geometry->isSimple()
580-
return true;
581-
}
582-
583-
584548
bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)
585549
{
586550

@@ -608,21 +572,19 @@ bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)
608572
{
609573
// Get the embedded GEOS Coordinate Sequence
610574
geos::LineString* geosls = static_cast<geos::LineString*>(mGeos);
611-
const geos::CoordinateSequence* old_sequence = geosls->getCoordinatesRO();
612-
geos::CoordinateSequence* new_sequence;
613-
614-
if ( deleteVertexAt(atVertex.back(), old_sequence, (&new_sequence) ) )
615-
{
616-
// Put in the new GEOS geometry
617-
setGeos( static_cast<geos::Geometry*>( geosGeometryFactory->createLineString(new_sequence) ) );
618-
mDirtyWkb = true;
619-
return TRUE;
620-
}
575+
geos::CoordinateSequence* sequence = geosls->getCoordinates();
576+
sequence->deleteAt(atVertex.back());
577+
geos::LineString* newLineString = geosGeometryFactory->createLineString(sequence);
578+
if(newLineString)
579+
{
580+
setGeos(newLineString);
581+
mDirtyWkb = true;
582+
return TRUE;
583+
}
621584
else
622-
{
623-
return FALSE;
624-
}
625-
585+
{
586+
return FALSE;
587+
}
626588
} // case geos::GEOS_LINESTRING
627589

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

20882050
}
20892051

2090-
bool QgsGeometry::moveVertexFromPolygon(int atVertex, double x, double y)
2052+
bool QgsGeometry::movePolygonVertex(int atVertex, double x, double y)
20912053
{
20922054
if(!mGeos)
20932055
{

src/core/qgsgeometry.h

+1-16
Original file line numberDiff line numberDiff line change
@@ -243,24 +243,9 @@ class QgsGeometry {
243243
const geos::CoordinateSequence* old_sequence,
244244
geos::CoordinateSequence** new_sequence);
245245

246-
/** Removes the vertex at the given vertex index (first number is index 0)
247-
* in the given GEOS Coordinate Sequence.
248-
* @param old_sequence The sequence to update (The caller remains the owner).
249-
* @param new_sequence The updated sequence (The caller becomes the owner if the function returns TRUE).
250-
* Returns FALSE if atVertex does not correspond to a valid vertex number
251-
* on the Coordinate Sequence, or if the number of remaining verticies
252-
* would be less than two.
253-
* It is up to the caller to distinguish between
254-
* these error conditions. (Or maybe we add another method to this
255-
* object to help make the distinction?)
256-
*/
257-
bool deleteVertexAt(int atVertex,
258-
const geos::CoordinateSequence* old_sequence,
259-
geos::CoordinateSequence** new_sequence);
260-
261246
/**Moves a vertex of mGeos to a new position. Internally, a new polygon is created instead of mGeos.
262247
Returns true in case of success*/
263-
bool moveVertexFromPolygon(int atVertex, double x, double y);
248+
bool movePolygonVertex(int atVertex, double x, double y);
264249

265250
bool deleteVertexFromPolygon(int atVertex);
266251

0 commit comments

Comments
 (0)