Skip to content

Commit

Permalink
Added method to delete vertices from polygons
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk@5249 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
mhugent committed Apr 11, 2006
1 parent bb46cb8 commit 60ecfb2
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 18 deletions.
1 change: 0 additions & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ AC_CONFIG_FILES([
tests/src/core/Makefile
tests/src/gui/Makefile
qgis.spec
src/plugins/qgis_community/Makefile
])

AC_OUTPUT
Expand Down
97 changes: 81 additions & 16 deletions src/core/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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)
Expand All @@ -2168,7 +2245,6 @@ geos::Polygon* QgsGeometry::createPolygonFromCoordSequence(const geos::Coordinat
}
catch(geos::IllegalArgumentException* e)
{
delete outerRingSequence;
return 0;
}

Expand All @@ -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;
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/plugins/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ endif


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

0 comments on commit 60ecfb2

Please sign in to comment.