Skip to content

Commit

Permalink
catch more projection errors
Browse files Browse the repository at this point in the history
git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@12665 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
jef committed Jan 2, 2010
1 parent 18e8e57 commit 60d2eae
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 9 deletions.
5 changes: 5 additions & 0 deletions src/app/legend/qgslegendlayer.cpp
Expand Up @@ -606,6 +606,11 @@ void QgsLegendLayer::saveAsShapefileGeneral( bool saveOnlySelection )
QMessageBox::warning( 0, tr( "Error" ),
tr( "Creation of an attribute failed" ) );
break;

case QgsVectorFileWriter::ErrProjection:
QMessageBox::warning( 0, tr( "Error" ),
tr( "Reprojection failed" ) );
break;
}
}

Expand Down
17 changes: 16 additions & 1 deletion src/core/qgsvectorfilewriter.cpp
Expand Up @@ -422,7 +422,22 @@ QgsVectorFileWriter::writeAsShapefile( QgsVectorLayer* layer,

if ( shallTransform )
{
fet.geometry()->transform( *ct );
try
{
fet.geometry()->transform( *ct );
}
catch ( QgsCsException &e )
{
delete ct;
delete writer;

QString msg( "Failed to transform a point while drawing a feature of type '"
+ fet.typeName() + "'. Writing stopped." );
msg += cse.what();
QgsLogger::warning( msg );

return ErrProjection;
}
}
writer->addFeature( fet );
}
Expand Down
3 changes: 2 additions & 1 deletion src/core/qgsvectorfilewriter.h
Expand Up @@ -49,7 +49,8 @@ class CORE_EXPORT QgsVectorFileWriter
ErrCreateDataSource,
ErrCreateLayer,
ErrAttributeTypeUnsupported,
ErrAttributeCreationFailed
ErrAttributeCreationFailed,
ErrProjection // added in 1.5
};

/** Write contents of vector layer to a shapefile */
Expand Down
14 changes: 7 additions & 7 deletions src/core/qgsvectorlayer.cpp
Expand Up @@ -1024,11 +1024,11 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
catch ( QgsCsException &cse )
{
QString msg( "Failed to transform a point while drawing a feature of type '"
+ fet.typeName() + "'. Ignoring this feature." );
+ fet.typeName() + "'. Rendering stopped." );
msg += cse.what();
QgsLogger::warning( msg );
return false;
}

}
else
{
Expand All @@ -1040,7 +1040,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
QgsDebugMsg( QString( "Cached %1 geometries." ).arg( mCachedGeometries.count() ) );
}

return TRUE; // Assume success always
return true; // Assume success always
}

void QgsVectorLayer::deleteCachedGeometries()
Expand Down Expand Up @@ -1942,7 +1942,7 @@ int QgsVectorLayer::addIsland( const QList<QgsPoint>& ring )
}

//look if id of selected feature belongs to an added feature
/*
#if 0
for ( QgsFeatureList::iterator addedIt = mAddedFeatures.begin(); addedIt != mAddedFeatures.end(); ++addedIt )
{
if ( addedIt->id() == selectedFeatureId )
Expand All @@ -1951,7 +1951,7 @@ int QgsVectorLayer::addIsland( const QList<QgsPoint>& ring )
mCachedGeometries[selectedFeatureId] = *addedIt->geometry();
}
}
*/
#endif

//is the feature contained in the view extent (mCachedGeometries) ?
QgsGeometryMap::iterator cachedIt = mCachedGeometries.find( selectedFeatureId );
Expand Down Expand Up @@ -2000,15 +2000,15 @@ int QgsVectorLayer::translateFeature( int featureId, double dx, double dy )
}

//look if id of selected feature belongs to an added feature
/*
#if 0
for ( QgsFeatureList::iterator addedIt = mAddedFeatures.begin(); addedIt != mAddedFeatures.end(); ++addedIt )
{
if ( addedIt->id() == featureId )
{
return addedIt->geometry()->translate( dx, dy );
}
}
*/
#endif

//else look in mCachedGeometries to make access faster
QgsGeometryMap::iterator cachedIt = mCachedGeometries.find( featureId );
Expand Down

0 comments on commit 60d2eae

Please sign in to comment.