@@ -470,8 +470,15 @@ bool QgsGeometry::insertVertexBefore(double x, double y,
470
470
471
471
case geos::GEOS_POLYGON: // a polygon
472
472
{
473
- // TODO
474
- break ;
473
+ if (insertVertexToPolygon (beforeVertex.back (), x, y))
474
+ {
475
+ mDirtyWkb = true ;
476
+ return true ;
477
+ }
478
+ else
479
+ {
480
+ return false ;
481
+ }
475
482
} // case geos::GEOS_POLYGON
476
483
477
484
case geos::GEOS_MULTIPOINT: // a collection of points
@@ -915,7 +922,8 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
915
922
double *thisx,*thisy;
916
923
double *prevx,*prevy;
917
924
double testdist;
918
-
925
+ int closestSegmentIndex;
926
+
919
927
// Initialise some stuff
920
928
beforeVertex.clear ();
921
929
sqrDist = std::numeric_limits<double >::max ();
@@ -925,15 +933,8 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
925
933
exportGeosToWkb ();
926
934
}
927
935
928
- // TODO: Convert this to a GEOS comparison not a WKB comparison.
929
936
if (mGeometry )
930
- {
931
- // int wkbType;
932
- // double x,y;
933
- // double *thisx,*thisy;
934
- // double *prevx,*prevy;
935
- // double testdist;
936
-
937
+ {
937
938
memcpy (&wkbType, (mGeometry +1 ), sizeof (int ));
938
939
939
940
switch (wkbType)
@@ -943,7 +944,7 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
943
944
return QgsPoint (0 ,0 );
944
945
945
946
case QGis::WKBLineString:
946
- int closestSegmentIndex = 0 ;
947
+ closestSegmentIndex = 0 ;
947
948
unsigned char * ptr = mGeometry + 5 ;
948
949
int * npoints = (int *) ptr;
949
950
ptr += sizeof (int );
@@ -988,8 +989,11 @@ QgsPoint QgsGeometry::closestSegmentWithContext(QgsPoint& point,
988
989
989
990
break ;
990
991
991
- // TODO: Other geometry types
992
-
992
+ // todo: add wkb parsing
993
+ case QGis::WKBPolygon:
994
+ {
995
+ break ;
996
+ }
993
997
} // switch (wkbType)
994
998
995
999
} // if (mGeometry)
@@ -2064,7 +2068,6 @@ bool QgsGeometry::movePolygonVertex(int atVertex, double x, double y)
2064
2068
2065
2069
geos::CoordinateSequence* coordinates = originalpoly->getCoordinates ();
2066
2070
std::vector<int > rings (originalpoly->getNumInteriorRing () + 1 ); // a vector storing the number of points in each ring
2067
- // todo: consider that the point to be moved could be the starting point/ end point of a ring
2068
2071
const geos::LineString* outerRing = originalpoly->getExteriorRing ();
2069
2072
int pointcounter = 0 ;
2070
2073
@@ -2125,7 +2128,6 @@ bool QgsGeometry::deleteVertexFromPolygon(int atVertex)
2125
2128
2126
2129
geos::CoordinateSequence* coordinates = originalpoly->getCoordinates ();
2127
2130
std::vector<int > rings (originalpoly->getNumInteriorRing () + 1 ); // a vector storing the number of points in each ring
2128
- // todo: consider that the point to be moved could be the starting point/ end point of a ring
2129
2131
const geos::LineString* outerRing = originalpoly->getExteriorRing ();
2130
2132
int pointcounter = 0 ;
2131
2133
@@ -2187,7 +2189,68 @@ bool QgsGeometry::deleteVertexFromPolygon(int atVertex)
2187
2189
2188
2190
bool QgsGeometry::insertVertexToPolygon (int beforeVertex, double x, double y)
2189
2191
{
2190
- return false ; // soon
2192
+ if (!mGeos )
2193
+ {
2194
+ return false ;
2195
+ }
2196
+
2197
+ geos::Polygon* originalpoly = dynamic_cast <geos::Polygon*>(mGeos );
2198
+ if (!originalpoly)
2199
+ {
2200
+ return false ;
2201
+ }
2202
+
2203
+ geos::CoordinateSequence* coordinates = originalpoly->getCoordinates ();
2204
+ // the sequence where the point will be inserted
2205
+ geos::CoordinateSequence* newSequence = new geos::DefaultCoordinateSequence ();
2206
+ std::vector<int > rings (originalpoly->getNumInteriorRing () + 1 ); // a vector storing the number of points in each ring
2207
+ const geos::LineString* outerRing = originalpoly->getExteriorRing ();
2208
+
2209
+ int coordinateCounter = 0 ;
2210
+ int numRingPoints = 0 ;
2211
+ for (int i = 0 ; i < outerRing->getNumPoints (); ++i)
2212
+ {
2213
+ newSequence->add (coordinates->getAt (coordinateCounter), true );
2214
+ ++coordinateCounter;
2215
+ ++numRingPoints;
2216
+ if (coordinateCounter == beforeVertex)
2217
+ {
2218
+ ++numRingPoints;
2219
+ newSequence->add (geos::Coordinate (x, y), true );
2220
+ }
2221
+ }
2222
+ rings[0 ] = numRingPoints;
2223
+
2224
+ for (int i = 0 ; i < originalpoly->getNumInteriorRing (); ++i)
2225
+ {
2226
+ numRingPoints = 0 ;
2227
+ const geos::LineString* innerRing = originalpoly->getInteriorRingN (i);
2228
+ for (int j = 0 ; j < originalpoly->getNumInteriorRing (); ++j)
2229
+ {
2230
+ newSequence->add (coordinates->getAt (coordinateCounter), true );
2231
+ ++numRingPoints;
2232
+ ++coordinateCounter;
2233
+ if (coordinateCounter == beforeVertex)
2234
+ {
2235
+ ++numRingPoints;
2236
+ newSequence->add (geos::Coordinate (x, y), true );
2237
+ }
2238
+ }
2239
+ rings[i+1 ] = numRingPoints;
2240
+ }
2241
+ geos::Polygon* newPolygon = createPolygonFromCoordSequence (newSequence, rings);
2242
+ delete coordinates;
2243
+ delete newSequence;
2244
+ if (newPolygon)
2245
+ {
2246
+ delete mGeos ;
2247
+ mGeos = newPolygon;
2248
+ return true ;
2249
+ }
2250
+ else
2251
+ {
2252
+ return false ;
2253
+ }
2191
2254
}
2192
2255
2193
2256
geos::Polygon* QgsGeometry::createPolygonFromCoordSequence (const geos::CoordinateSequence* coords, const std::vector<int >& pointsInRings) const
0 commit comments