Skip to content

Commit

Permalink
fix geometry editing:
Browse files Browse the repository at this point in the history
- 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
  • Loading branch information
jef committed Sep 12, 2008
1 parent 3e84274 commit b17d5a9
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
40 changes: 34 additions & 6 deletions src/core/qgsgeometry.cpp
Expand Up @@ -38,26 +38,46 @@ email : morb at ozemail dot com dot au
class GEOSException
{
public:
GEOSException( const char *theMsg )
GEOSException( char *theMsg )
{
msg = theMsg;
if ( strcmp( theMsg, "Unknown exception thrown" ) == 0 && lastMsg )
{
delete [] theMsg;
msg = new char[strlen( lastMsg )+1];
strcpy( msg, lastMsg );
}
else
{
msg = theMsg;
lastMsg = msg;
}
}

// copy constructor
GEOSException( const GEOSException &rhs )
{
*this = rhs;
}

~GEOSException()
{
if ( lastMsg == msg )
lastMsg = NULL;
delete [] msg;
}


const char *what()
{
return msg;
}

private:
const char *msg;
char *msg;
static const char *lastMsg;
};

const char *GEOSException::lastMsg = NULL;

void throwGEOSException( const char *fmt, ... )
{
va_list ap;
Expand Down Expand Up @@ -2080,7 +2100,11 @@ QgsPoint QgsGeometry::vertexAt( int atVertex )
{
try
{
const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( mGeos );
const GEOSGeometry *g = GEOSGetExteriorRing( mGeos );
if ( !g )
return QgsPoint( 0, 0 );

const GEOSCoordSequence *cs = GEOSGeom_getCoordSeq( g );
GEOSCoordSeq_getX( cs, atVertex, &x );
GEOSCoordSeq_getY( cs, atVertex, &y );
return QgsPoint( x, y );
Expand Down Expand Up @@ -2317,7 +2341,11 @@ double QgsGeometry::closestVertexWithContext( const QgsPoint& point, int& atVert
// set up the GEOS geometry
exportWkbToGeos();

const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( mGeos );
const GEOSGeometry *g = GEOSGetExteriorRing( mGeos );
if ( g == NULL )
return -1;

const GEOSCoordSequence *sequence = GEOSGeom_getCoordSeq( g );

unsigned int n;
GEOSCoordSeq_getSize( sequence, &n );
Expand Down
8 changes: 8 additions & 0 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -2745,6 +2745,14 @@ bool QgsVectorLayer::commitChanges()
//
if ( mAddedFeatures.size() > 0 )
{
for ( QgsFeatureList::iterator iter = mAddedFeatures.begin(); iter != mAddedFeatures.end(); ++iter )
{
if ( mChangedGeometries.contains( iter->featureId() ) )
{
iter->setGeometry( mChangedGeometries.take( iter->featureId() ) );
}
}

if (( cap & QgsVectorDataProvider::AddFeatures ) && mDataProvider->addFeatures( mAddedFeatures ) )
{
mCommitErrors << tr( "SUCCESS: %1 features added." ).arg( mAddedFeatures.size() );
Expand Down

0 comments on commit b17d5a9

Please sign in to comment.