Skip to content

Commit b17d5a9

Browse files
author
jef
committedSep 12, 2008
fix geometry editing:
- store geometry changes to added features - fix GEOS exception handling - fix QgsGeometry::vertexAt() and QgsGeometry::closestVertexWithContext() git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@9304 c8812cc2-4d05-0410-92ff-de0c093fc19c

File tree

2 files changed

+42
-6
lines changed

2 files changed

+42
-6
lines changed
 

‎src/core/qgsgeometry.cpp

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,26 +38,46 @@ email : morb at ozemail dot com dot au
3838
class GEOSException
3939
{
4040
public:
41-
GEOSException( const char *theMsg )
41+
GEOSException( char *theMsg )
4242
{
43-
msg = theMsg;
43+
if ( strcmp( theMsg, "Unknown exception thrown" ) == 0 && lastMsg )
44+
{
45+
delete [] theMsg;
46+
msg = new char[strlen( lastMsg )+1];
47+
strcpy( msg, lastMsg );
48+
}
49+
else
50+
{
51+
msg = theMsg;
52+
lastMsg = msg;
53+
}
54+
}
55+
56+
// copy constructor
57+
GEOSException( const GEOSException &rhs )
58+
{
59+
*this = rhs;
4460
}
4561

4662
~GEOSException()
4763
{
64+
if ( lastMsg == msg )
65+
lastMsg = NULL;
4866
delete [] msg;
4967
}
5068

51-
5269
const char *what()
5370
{
5471
return msg;
5572
}
5673

5774
private:
58-
const char *msg;
75+
char *msg;
76+
static const char *lastMsg;
5977
};
6078

79+
const char *GEOSException::lastMsg = NULL;
80+
6181
void throwGEOSException( const char *fmt, ... )
6282
{
6383
va_list ap;
@@ -2080,7 +2100,11 @@ QgsPoint QgsGeometry::vertexAt( int atVertex )
20802100
{
20812101
try
20822102
{
2083-
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( mGeos );
2103+
const GEOSGeometry *g = GEOSGetExteriorRing( mGeos );
2104+
if ( !g )
2105+
return QgsPoint( 0, 0 );
2106+
2107+
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g );
20842108
GEOSCoordSeq_getX( cs, atVertex, &x );
20852109
GEOSCoordSeq_getY( cs, atVertex, &y );
20862110
return QgsPoint( x, y );
@@ -2317,7 +2341,11 @@ double QgsGeometry::closestVertexWithContext( const QgsPoint& point, int& atVert
23172341
// set up the GEOS geometry
23182342
exportWkbToGeos();
23192343

2320-
const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( mGeos );
2344+
const GEOSGeometry *g = GEOSGetExteriorRing( mGeos );
2345+
if ( g == NULL )
2346+
return -1;
2347+
2348+
const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( g );
23212349

23222350
unsigned int n;
23232351
GEOSCoordSeq_getSize( sequence, &n );

‎src/core/qgsvectorlayer.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2745,6 +2745,14 @@ bool QgsVectorLayer::commitChanges()
27452745
//
27462746
if ( mAddedFeatures.size() > 0 )
27472747
{
2748+
for ( QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter )
2749+
{
2750+
if ( mChangedGeometries.contains( iter->featureId() ) )
2751+
{
2752+
iter->setGeometry( mChangedGeometries.take( iter->featureId() ) );
2753+
}
2754+
}
2755+
27482756
if (( cap & QgsVectorDataProvider::AddFeatures ) && mDataProvider->addFeatures( mAddedFeatures ) )
27492757
{
27502758
mCommitErrors << tr( "SUCCESS: %1 features added." ).arg( mAddedFeatures.size() );

0 commit comments

Comments
 (0)
Please sign in to comment.