Skip to content
Permalink
Browse files

Added method to delete vertices from polygons

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5249 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent
mhugent committed Apr 11, 2006
1 parent 927f5d5 commit b371ae3177ce26ccf3ca1cb7c316d043166bd54b
Showing with 82 additions and 18 deletions.
  1. +0 −1 configure.in
  2. +81 −16 src/core/qgsgeometry.cpp
  3. +1 −1 src/plugins/Makefile.am
@@ -506,7 +506,6 @@ AC_CONFIG_FILES([
tests/src/core/Makefile
tests/src/gui/Makefile
qgis.spec
src/plugins/qgis_community/Makefile
])

AC_OUTPUT
@@ -633,9 +633,16 @@ bool QgsGeometry::deleteVertexAt(QgsGeometryVertexIndex atVertex)

case geos::GEOS_POLYGON: // a polygon
{
// TODO
break;
} // case geos::GEOS_POLYGON
if(deleteVertexFromPolygon(atVertex.back()))
{
mDirtyWkb = true;
return true;
}
else
{
return false;
}
}

case geos::GEOS_MULTIPOINT: // a collection of points
{
@@ -2143,7 +2150,77 @@ bool QgsGeometry::moveVertexFromPolygon(int atVertex, double x, double y)

bool QgsGeometry::deleteVertexFromPolygon(int atVertex)
{
return false; //soon
if(!mGeos)
{
return false;
}

geos::Polygon* originalpoly = dynamic_cast<geos::Polygon*>(mGeos);
if(!originalpoly)
{
return false;
}

geos::CoordinateSequence* coordinates = originalpoly->getCoordinates();
std::vector<int> rings(originalpoly->getNumInteriorRing() + 1); //a vector storing the number of points in each ring
//todo: consider that the point to be moved could be the starting point/ end point of a ring
const geos::LineString* outerRing = originalpoly->getExteriorRing();
int pointcounter = 0;

if(atVertex == 0 || atVertex == outerRing->getNumPoints()-1)
{
coordinates->setAt(coordinates->getAt(1), outerRing->getNumPoints()-1);
coordinates->deleteAt(0);
rings[0] = outerRing->getNumPoints()-1;
pointcounter += outerRing->getNumPoints()-1;
}
else if(atVertex < outerRing->getNumPoints())
{
coordinates->deleteAt(atVertex);
rings[0] = outerRing->getNumPoints()-1;
pointcounter += outerRing->getNumPoints()-1;
}
else
{
rings[0] = outerRing->getNumPoints();
pointcounter += outerRing->getNumPoints();
}

for(int i = 0; i < originalpoly->getNumInteriorRing(); ++i)
{
const geos::LineString* innerRing = originalpoly->getInteriorRingN(i);
if(atVertex == pointcounter || atVertex== pointcounter + innerRing->getNumPoints()-1)
{
coordinates->setAt(coordinates->getAt(pointcounter+1), pointcounter + innerRing->getNumPoints()-1);
coordinates->deleteAt(pointcounter);
pointcounter += innerRing->getNumPoints()-1;
rings[i+1] = innerRing->getNumPoints()-1;
}
else if(atVertex > pointcounter && atVertex < pointcounter + innerRing->getNumPoints()-1)
{
coordinates->deleteAt(atVertex);
rings[i+1] = innerRing->getNumPoints()-1;
pointcounter += innerRing->getNumPoints()-1;
}
else
{
rings[i+1] = innerRing->getNumPoints();
pointcounter += innerRing->getNumPoints();
}
}

geos::Polygon* newPolygon = createPolygonFromCoordSequence(coordinates, rings);
delete coordinates;
if(newPolygon)
{
delete mGeos;
mGeos = newPolygon;
return true;
}
else
{
return false;
}
}

bool QgsGeometry::insertVertexToPolygon(int beforeVertex, double x, double y)
@@ -2168,7 +2245,6 @@ geos::Polygon* QgsGeometry::createPolygonFromCoordSequence(const geos::Coordinat
}
catch(geos::IllegalArgumentException* e)
{
delete outerRingSequence;
return 0;
}

@@ -2189,12 +2265,6 @@ geos::Polygon* QgsGeometry::createPolygonFromCoordSequence(const geos::Coordinat
}
catch(geos::IllegalArgumentException* e)
{
delete outerRingSequence;
//also delete the already created rings
for(int j = 0; j < i; ++j)
{
delete (*newInnerRings)[i];
}
return 0;
}
(*newInnerRings)[i] = newInnerRing;
@@ -2207,11 +2277,6 @@ geos::Polygon* QgsGeometry::createPolygonFromCoordSequence(const geos::Coordinat
}
catch(geos::IllegalArgumentException* e)
{
delete newOuterRing;
for(int i = 0; i < newInnerRings->size(); ++i)
{
delete (*newInnerRings)[i];
}
return 0;
}

@@ -14,7 +14,7 @@ endif


SUBDIRS = $(GEOPROCESSING) \
qgis_community \
#qgis_community \
$(SPIT) \
$(GRASS) \
$(COMMUNITY) \

0 comments on commit b371ae3

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