230 changes: 115 additions & 115 deletions src/core/qgsmaptopixelgeometrysimplifier.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/core/qgsmaptopixelgeometrysimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
int mSimplifyFlags;

//! For transformation between coordinate systems from current layer to map target. Can be 0 if on-the-fly reprojection is not used
const QgsCoordinateTransform* mMapCoordTransform;
const QgsCoordinateTransform* mMapCoordTransform;
//! For transformation between map coordinates and device coordinates
const QgsMapToPixel* mMapToPixel;
//! Factor tolterance to apply in transformation between map coordinates and device coordinates
Expand Down Expand Up @@ -81,18 +81,18 @@ class CORE_EXPORT QgsMapToPixelSimplifier : public QgsAbstractGeometrySimplifier
//! Simplifies the specified geometry
virtual bool simplifyGeometry( QgsGeometry* geometry );

// MapToPixel simplification helper methods
// MapToPixel simplification helper methods
public:

//! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
static bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope,
const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mapToPixel, float mapToPixelTol = 1.0f );
const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mapToPixel, float mapToPixelTol = 1.0f );

//! Returns whether the envelope can be replaced by its BBOX when is applied the specified map2pixel context
inline bool canbeGeneralizedByMapBoundingBox( const QgsRectangle& envelope ) const { return canbeGeneralizedByMapBoundingBox( envelope, mMapCoordTransform, mMapToPixel, mMapToPixelTol ); }

//! Simplifies the geometry when is applied the specified map2pixel context
static bool simplifyGeometry( QgsGeometry* geometry,
static bool simplifyGeometry( QgsGeometry* geometry,
int simplifyFlags, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mapToPixel, float mapToPixelTol = 1.0f );

};
Expand Down
8 changes: 4 additions & 4 deletions src/core/qgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1370,7 +1370,7 @@ QString QgsProject::readPath( QString src ) const
QString vsiPrefix = qgsVsiPrefix( src );
if ( ! vsiPrefix.isEmpty() )
{
src.remove(0, vsiPrefix.size());
src.remove( 0, vsiPrefix.size() );
}

// relative path should always start with ./ or ../
Expand Down Expand Up @@ -1465,7 +1465,7 @@ QString QgsProject::readPath( QString src ) const
// return the absolute or relative path to write it to the project file
QString QgsProject::writePath( QString src ) const
{
if ( readBoolEntry( "Paths", "/Absolute", false ) || src.isEmpty() )
if ( readBoolEntry( "Paths", "/Absolute", false ) || src.isEmpty() )
{
return src;
}
Expand All @@ -1474,15 +1474,15 @@ QString QgsProject::writePath( QString src ) const
QString projPath = fileName();

if ( projPath.isEmpty() )
{
{
return src;
}

// if this is a VSIFILE, remove the VSI prefix and append to final result
QString vsiPrefix = qgsVsiPrefix( src );
if ( ! vsiPrefix.isEmpty() )
{
srcPath.remove(0, vsiPrefix.size());
srcPath.remove( 0, vsiPrefix.size() );
}

#if defined( Q_OS_WIN )
Expand Down
16 changes: 8 additions & 8 deletions src/core/qgsvectorlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ QgsVectorLayer::QgsVectorLayer( QString vectorLayerPath,

// Default simplify drawing configuration
QSettings settings;
setSimplifyDrawingHints( settings.value( "/qgis/simplifyDrawingHints", (int)mSimplifyDrawingHints ).toInt() );
setSimplifyDrawingHints( settings.value( "/qgis/simplifyDrawingHints", ( int )mSimplifyDrawingHints ).toInt() );
setSimplifyDrawingTol( settings.value( "/qgis/simplifyDrawingTol", mSimplifyDrawingTol ).toFloat() );

} // QgsVectorLayer ctor
Expand Down Expand Up @@ -698,17 +698,17 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
mRendererV2->startRender( rendererContext, this );

QgsFeatureRequest& featureRequest = QgsFeatureRequest()
.setFilterRect( rendererContext.extent() )
.setSubsetOfAttributes( attributes );
.setFilterRect( rendererContext.extent() )
.setSubsetOfAttributes( attributes );

QgsFeatureIterator fit = QgsFeatureIterator();

// Enable the simplification of the geometries (Using the current map2pixel context) before fetch the features.
if ( simplifyDrawingCanbeApplied( QgsVectorLayer::GeometrySimplification | QgsVectorLayer::EnvelopeSimplification ) && !(featureRequest.flags() & QgsFeatureRequest::NoGeometry) && !rendererContext.renderingPrintComposition() )
if ( simplifyDrawingCanbeApplied( QgsVectorLayer::GeometrySimplification | QgsVectorLayer::EnvelopeSimplification ) && !( featureRequest.flags() & QgsFeatureRequest::NoGeometry ) && !rendererContext.renderingPrintComposition() )
{
QPainter* p = rendererContext.painter();
float dpi = ( p->device()->logicalDpiX() + p->device()->logicalDpiY() ) / 2;
float map2pixelTol = mSimplifyDrawingTol * 96.0f/dpi;
float map2pixelTol = mSimplifyDrawingTol * 96.0f / dpi;

int simplifyFlags = QgsMapToPixelSimplifier::NoFlags;
if ( mSimplifyDrawingHints & QgsVectorLayer::GeometrySimplification ) simplifyFlags |= QgsMapToPixelSimplifier::SimplifyGeometry;
Expand All @@ -723,7 +723,7 @@ bool QgsVectorLayer::draw( QgsRenderContext& rendererContext )
featureRequest.setMapToPixel( &rendererContext.mapToPixel() );
featureRequest.setMapToPixelTol( map2pixelTol );

QgsMapToPixelSimplifier* simplifier =
QgsMapToPixelSimplifier* simplifier =
new QgsMapToPixelSimplifier( simplifyFlags, rendererContext.coordinateTransform(), &rendererContext.mapToPixel(), map2pixelTol );

fit = QgsFeatureIterator( new QgsSimplifiedVectorLayerFeatureIterator( this, featureRequest, simplifier ) );
Expand Down Expand Up @@ -1247,9 +1247,9 @@ bool QgsVectorLayer::setSubsetString( QString subset )
return res;
}

bool QgsVectorLayer::simplifyDrawingCanbeApplied( int simplifyHint ) const
bool QgsVectorLayer::simplifyDrawingCanbeApplied( int simplifyHint ) const
{
return mDataProvider && ( mSimplifyDrawingHints & simplifyHint ) && !mEditBuffer && ( !mCurrentRendererContext || !mCurrentRendererContext->renderingPrintComposition() );
return mDataProvider && ( mSimplifyDrawingHints & simplifyHint ) && !mEditBuffer && ( !mCurrentRendererContext || !mCurrentRendererContext->renderingPrintComposition() );
}

QgsFeatureIterator QgsVectorLayer::getFeatures( const QgsFeatureRequest& request )
Expand Down
6 changes: 3 additions & 3 deletions src/core/qgsvectorlayerfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -607,8 +607,8 @@ void QgsVectorLayerFeatureIterator::updateFeatureGeometry( QgsFeature &f )
***************************************************************************/

QgsSimplifiedVectorLayerFeatureIterator::QgsSimplifiedVectorLayerFeatureIterator( QgsVectorLayer* layer, const QgsFeatureRequest& request, QgsAbstractGeometrySimplifier* simplifier )
: QgsVectorLayerFeatureIterator( layer, request )
, mSimplifier( simplifier )
: QgsVectorLayerFeatureIterator( layer, request )
, mSimplifier( simplifier )
{
mSupportsPresimplify = layer->dataProvider()->capabilities() & QgsVectorDataProvider::SimplifyGeometries;
}
Expand All @@ -624,7 +624,7 @@ QgsSimplifiedVectorLayerFeatureIterator::~QgsSimplifiedVectorLayerFeatureIterato
//! fetch next feature, return true on success
bool QgsSimplifiedVectorLayerFeatureIterator::fetchFeature( QgsFeature& feature )
{
if (QgsVectorLayerFeatureIterator::fetchFeature( feature ))
if ( QgsVectorLayerFeatureIterator::fetchFeature( feature ) )
{
const QgsMapToPixel* mtp = mRequest.mapToPixel();
if ( mtp && !mSupportsPresimplify && mSimplifier ) mSimplifier->simplifyGeometry( feature.geometry() );
Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsvectorlayerfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class CORE_EXPORT QgsSimplifiedVectorLayerFeatureIterator : public QgsVectorLaye
{
public:
QgsSimplifiedVectorLayerFeatureIterator( QgsVectorLayer* layer, const QgsFeatureRequest& request, QgsAbstractGeometrySimplifier* simplifier );
~QgsSimplifiedVectorLayerFeatureIterator( );
~QgsSimplifiedVectorLayerFeatureIterator( );

protected:
//! fetch next feature, return true on success
Expand Down
2 changes: 1 addition & 1 deletion src/core/symbology-ng/qgslinesymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ void QgsSimpleLineSymbolLayerV2::renderPolyline( const QPolygonF& points, QgsSym
p->setPen( context.selected() ? mSelPen : mPen );

// Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #2 points).
if ( points.size()<=2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyDrawingTol() ) && (p->renderHints() & QPainter::Antialiasing) )
if ( points.size() <= 2 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyDrawingTol() ) && ( p->renderHints() & QPainter::Antialiasing ) )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->drawPolyline( points );
Expand Down
10 changes: 5 additions & 5 deletions src/core/symbology-ng/qgsrendererv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ const unsigned char* QgsFeatureRendererV2::_getLineString( QPolygonF& pts, QgsRe

bool hasZValue = ( wkbType == QGis::WKBLineString25D );

int sizeOfDoubleX = sizeof(double);
int sizeOfDoubleY = hasZValue ? 2*sizeof(double) : sizeof(double);
int sizeOfDoubleX = sizeof( double );
int sizeOfDoubleY = hasZValue ? 2 * sizeof( double ) : sizeof( double );

double x, y;
const QgsCoordinateTransform* ct = context.coordinateTransform();
Expand Down Expand Up @@ -126,8 +126,8 @@ const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QP

bool hasZValue = ( wkbType == QGis::WKBPolygon25D );

int sizeOfDoubleX = sizeof(double);
int sizeOfDoubleY = hasZValue ? 2*sizeof(double) : sizeof(double);
int sizeOfDoubleX = sizeof( double );
int sizeOfDoubleY = hasZValue ? 2 * sizeof( double ) : sizeof( double );

double x, y;
holes.clear();
Expand Down Expand Up @@ -160,7 +160,7 @@ const unsigned char* QgsFeatureRendererV2::_getPolygon( QPolygonF& pts, QList<QP

//clip close to view extent, if needed
QRectF ptsRect = poly.boundingRect();
if (!context.extent().contains( ptsRect )) QgsClipper::trimPolygon( poly, clipRect );
if ( !context.extent().contains( ptsRect ) ) QgsClipper::trimPolygon( poly, clipRect );

//transform the QPolygonF to screen coordinates
if ( ct )
Expand Down
10 changes: 5 additions & 5 deletions src/core/symbology-ng/qgssymbollayerv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,9 @@ QgsMarkerSymbolLayerV2::QgsMarkerSymbolLayerV2( bool locked )
: QgsSymbolLayerV2( QgsSymbolV2::Marker, locked ), mSizeUnit( QgsSymbolV2::MM ), mOffsetUnit( QgsSymbolV2::MM ),
mHorizontalAnchorPoint( HCenter ), mVerticalAnchorPoint( VCenter )
{
mOffsetExpression = NULL;
mHorizontalAnchorExpression = NULL;
mVerticalAnchorExpression = NULL;
mOffsetExpression = NULL;
mHorizontalAnchorExpression = NULL;
mVerticalAnchorExpression = NULL;
}

QgsLineSymbolLayerV2::QgsLineSymbolLayerV2( bool locked )
Expand Down Expand Up @@ -359,9 +359,9 @@ void QgsFillSymbolLayerV2::_renderPolygon( QPainter* p, const QPolygonF& points,
}

// Disable 'Antialiasing' if the geometry was generalized in the current RenderContext (We known that it must have least #5 points).
if ( points.size()<=5 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyDrawingTol() ) && (p->renderHints() & QPainter::Antialiasing) )
if ( points.size() <= 5 && context.layer() && context.layer()->simplifyDrawingCanbeApplied( QgsVectorLayer::AntialiasingSimplification ) && QgsAbstractGeometrySimplifier::canbeGeneralizedByDeviceBoundingBox( points, context.layer()->simplifyDrawingTol() ) && ( p->renderHints() & QPainter::Antialiasing ) )
{
p->setRenderHint( QPainter::Antialiasing, false );
p->setRenderHint( QPainter::Antialiasing, false );
p->drawRect( points.boundingRect() );
p->setRenderHint( QPainter::Antialiasing, true );
return;
Expand Down
2 changes: 1 addition & 1 deletion src/mapserver/qgis_map_serv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ int main( int argc, char * argv[] )
delete theServer;
continue;
}
}
}
else if ( serviceString == "WFS" )
{
delete theServer;
Expand Down
12 changes: 6 additions & 6 deletions src/mapserver/qgsprojectparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ void QgsProjectParser::wcsContentMetadata( QDomElement& parentElement, QDomDocum

//lonLatEnvelope
const QgsCoordinateReferenceSystem& layerCrs = layer->crs();
QgsCoordinateTransform t( layerCrs, QgsCoordinateReferenceSystem(4326) );
QgsCoordinateTransform t( layerCrs, QgsCoordinateReferenceSystem( 4326 ) );
//transform
QgsRectangle BBox = t.transformBoundingBox( layer->extent() );
QDomElement lonLatElem = doc.createElement( "lonLatEnvelope" );
Expand Down Expand Up @@ -696,7 +696,7 @@ void QgsProjectParser::describeCoverage( const QString& aCoveName, QDomElement&

//lonLatEnvelope
const QgsCoordinateReferenceSystem& layerCrs = layer->crs();
QgsCoordinateTransform t( layerCrs, QgsCoordinateReferenceSystem(4326) );
QgsCoordinateTransform t( layerCrs, QgsCoordinateReferenceSystem( 4326 ) );
//transform
QgsRectangle BBox = t.transformBoundingBox( layer->extent() );
QDomElement lonLatElem = doc.createElement( "lonLatEnvelope" );
Expand Down Expand Up @@ -742,7 +742,7 @@ void QgsProjectParser::describeCoverage( const QString& aCoveName, QDomElement&
lowElem.appendChild( lowText );
gridEnvElem.appendChild( lowElem );
QDomElement highElem = doc.createElement( "gml:high" );
QDomText highText = doc.createTextNode( QString::number( rLayer->width() )+" "+QString::number( rLayer->height() ) );
QDomText highText = doc.createTextNode( QString::number( rLayer->width() ) + " " + QString::number( rLayer->height() ) );
highElem.appendChild( highText );
gridEnvElem.appendChild( highElem );
spatialDomainElem.appendChild( rectGridElem );
Expand All @@ -764,12 +764,12 @@ void QgsProjectParser::describeCoverage( const QString& aCoveName, QDomElement&
spatialDomainElem.appendChild( originElem );

QDomElement xOffsetElem = doc.createElement( "gml:offsetVector" );
QDomText xOffsetText = doc.createTextNode( QString::number( rLayer->rasterUnitsPerPixelX() )+" 0" );
QDomText xOffsetText = doc.createTextNode( QString::number( rLayer->rasterUnitsPerPixelX() ) + " 0" );
xOffsetElem.appendChild( xOffsetText );
spatialDomainElem.appendChild( xOffsetElem );

QDomElement yOffsetElem = doc.createElement( "gml:offsetVector" );
QDomText yOffsetText = doc.createTextNode( "0 "+QString::number( rLayer->rasterUnitsPerPixelY() ) );
QDomText yOffsetText = doc.createTextNode( "0 " + QString::number( rLayer->rasterUnitsPerPixelY() ) );
yOffsetElem.appendChild( yOffsetText );
spatialDomainElem.appendChild( yOffsetElem );

Expand Down Expand Up @@ -3105,7 +3105,7 @@ void QgsProjectParser::serviceWCSCapabilities( QDomElement& parentElement, QDomD
serviceElem.appendChild( wcsKeywordsElem );
}
}

//Fees
QDomElement feesElem = propertiesElem.firstChildElement( "WMSFees" );
if ( !feesElem.isNull() )
Expand Down
26 changes: 15 additions & 11 deletions src/mapserver/qgswcsserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ QDomDocument QgsWCSServer::getCapabilities()
{
mConfigParser->serviceCapabilities( wcsCapabilitiesElement, doc );
}

//INSERT Service

//wcs:Capability element
Expand Down Expand Up @@ -149,7 +149,7 @@ QDomDocument QgsWCSServer::describeCoverage()
coveDescElement.setAttribute( "version", "1.0.0" );
coveDescElement.setAttribute( "updateSequence", "0" );
doc.appendChild( coveDescElement );

//defining coverage name
QString coveName = "";
//read COVERAGE
Expand All @@ -158,7 +158,8 @@ QDomDocument QgsWCSServer::describeCoverage()
{
coveName = cove_name_it.value();
}
if ( coveName == "" ) {
if ( coveName == "" )
{
QMap<QString, QString>::const_iterator cove_name_it = mParameterMap.find( "IDENTIFIER" );
if ( cove_name_it != mParameterMap.end() )
{
Expand All @@ -183,20 +184,22 @@ QByteArray* QgsWCSServer::getCoverage()
{
coveName = cove_name_it.value();
}
if ( coveName == "" ) {
if ( coveName == "" )
{
QMap<QString, QString>::const_iterator cove_name_it = mParameterMap.find( "IDENTIFIER" );
if ( cove_name_it != mParameterMap.end() )
{
coveName = cove_name_it.value();
}
}

if ( coveName == "" ) {
if ( coveName == "" )
{
mErrors << QString( "COVERAGE is mandatory" );
}

layerList = mConfigParser->mapLayerFromCoverage( coveName );
if ( layerList.size() < 1 )
if ( layerList.size() < 1 )
{
mErrors << QString( "The layer for the COVERAGE '%1' is not found" ).arg( coveName );
}
Expand Down Expand Up @@ -229,7 +232,7 @@ QByteArray* QgsWCSServer::getCoverage()
maxy = bbString.section( ",", 3, 3 ).toDouble( &conversionSuccess );
if ( !conversionSuccess ) {bboxOk = false;}
}
if ( !bboxOk )
if ( !bboxOk )
{
mErrors << QString( "The BBOX is mandatory and has to be xx.xxx,yy.yyy,xx.xxx,yy.yyy" );
}
Expand All @@ -244,7 +247,7 @@ QByteArray* QgsWCSServer::getCoverage()
{
height = 0;
}

if ( width < 0 || height < 0 )
{
mErrors << QString( "The WIDTH and HEIGHT are mandatory and have to be integer" );
Expand All @@ -260,7 +263,7 @@ QByteArray* QgsWCSServer::getCoverage()
{
mErrors << QString( "Could not create output CRS" );
}

if ( mErrors.count() != 0 )
{
throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
Expand All @@ -270,7 +273,8 @@ QByteArray* QgsWCSServer::getCoverage()

QgsMapLayer* layer = layerList.at( 0 );
QgsRasterLayer* rLayer = dynamic_cast<QgsRasterLayer*>( layer );
if ( rLayer ) {
if ( rLayer )
{
QTemporaryFile tempFile;
tempFile.open();
QgsRasterFileWriter fileWriter( tempFile.fileName() );
Expand All @@ -294,7 +298,7 @@ QByteArray* QgsWCSServer::getCoverage()
throw QgsMapServiceException( "RequestNotWellFormed", mErrors.join( ". " ) );
}
}

QgsRasterFileWriter::WriterError err = fileWriter.writeRaster( pipe, width, height, rect, outputCRS );
if ( err != QgsRasterFileWriter::NoError )
{
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/roadgraph/roadgraphplugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ const QgsGraphDirector* RoadGraphPlugin::director() const
if ( layer == NULL )
return NULL;
if ( layer->wkbType() == QGis::WKBLineString
|| layer->wkbType() == QGis::WKBMultiLineString)
|| layer->wkbType() == QGis::WKBMultiLineString )
{
QgsVectorDataProvider *provider = dynamic_cast< QgsVectorDataProvider* >( layer->dataProvider() );
if ( provider == NULL )
Expand Down
10 changes: 5 additions & 5 deletions src/providers/ogr/qgsogrfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,9 @@ void QgsOgrFeatureIterator::fetchedFeature( OGRFeatureH feature, OGRGeometryH ge
***************************************************************************/

//! Provides a specialized FeatureIterator for enable simplification of the geometries
QgsOgrSimplifiedFeatureIterator::QgsOgrSimplifiedFeatureIterator( QgsOgrProvider* p, const QgsFeatureRequest& request )
: QgsOgrFeatureIterator( p, request )
, mSimplifier( NULL )
QgsOgrSimplifiedFeatureIterator::QgsOgrSimplifiedFeatureIterator( QgsOgrProvider* p, const QgsFeatureRequest& request )
: QgsOgrFeatureIterator( p, request )
, mSimplifier( NULL )
{
QgsFeatureRequest::Flags requestFlags = request.flags();

Expand All @@ -326,9 +326,9 @@ QgsOgrSimplifiedFeatureIterator::~QgsOgrSimplifiedFeatureIterator( )
//! Notified a new OGRFeatureH fecthed from data provider
void QgsOgrSimplifiedFeatureIterator::fetchedFeature( OGRFeatureH feature, OGRGeometryH geometry )
{
if ( mSimplifier && (mSimplifier->simplifyFlags() & (QgsMapToPixelSimplifier::SimplifyGeometry | QgsMapToPixelSimplifier::SimplifyEnvelope) ) )
if ( mSimplifier && ( mSimplifier->simplifyFlags() & ( QgsMapToPixelSimplifier::SimplifyGeometry | QgsMapToPixelSimplifier::SimplifyEnvelope ) ) )
{
mSimplifier->simplifyGeometry( (OGRGeometry*) geometry );
mSimplifier->simplifyGeometry(( OGRGeometry* ) geometry );
}
QgsOgrFeatureIterator::fetchedFeature( feature, geometry );
}
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrfeatureiterator.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class QgsOgrSimplifiedFeatureIterator : public QgsOgrFeatureIterator
{
public:
QgsOgrSimplifiedFeatureIterator( QgsOgrProvider* p, const QgsFeatureRequest& request );
~QgsOgrSimplifiedFeatureIterator( );
~QgsOgrSimplifiedFeatureIterator( );

protected:
//! Notified a new OGRFeatureH fecthed from data provider
Expand Down
106 changes: 53 additions & 53 deletions src/providers/ogr/qgsogrmaptopixelgeometrysimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
QgsOgrMapToPixelSimplifier::QgsOgrMapToPixelSimplifier( int simplifyFlags, const QgsCoordinateTransform* coordinateTransform, const QgsMapToPixel* mapTolPixel, float mapToPixelTol ) : QgsMapToPixelSimplifier( simplifyFlags, coordinateTransform, mapTolPixel, mapToPixelTol )
{
mPointBufferCount = 512;
mPointBufferPtr = (OGRRawPoint*)OGRMalloc( mPointBufferCount * sizeof(OGRRawPoint) );
mPointBufferPtr = ( OGRRawPoint* )OGRMalloc( mPointBufferCount * sizeof( OGRRawPoint ) );
}
QgsOgrMapToPixelSimplifier::~QgsOgrMapToPixelSimplifier()
{
Expand All @@ -39,10 +39,10 @@ OGRRawPoint* QgsOgrMapToPixelSimplifier::mallocPoints( int numPoints )
OGRFree( mPointBufferPtr );
mPointBufferPtr = NULL;
}
if ( mPointBufferPtr==NULL )
if ( mPointBufferPtr == NULL )
{
mPointBufferCount = numPoints;
mPointBufferPtr = (OGRRawPoint*)OGRMalloc( mPointBufferCount * sizeof(OGRRawPoint) );
mPointBufferPtr = ( OGRRawPoint* )OGRMalloc( mPointBufferCount * sizeof( OGRRawPoint ) );
}
return mPointBufferPtr;
}
Expand All @@ -51,7 +51,7 @@ OGRRawPoint* QgsOgrMapToPixelSimplifier::mallocPoints( int numPoints )
// Helper simplification methods

//! Simplifies the OGR-geometry (Removing duplicated points) when is applied the specified map2pixel context
bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount)
bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount )
{
bool canbeGeneralizable = ( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyGeometry );

Expand All @@ -61,19 +61,19 @@ bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( QGis::GeometryType geometr

double map2pixelTol = mMapToPixelTol * QgsMapToPixelSimplifier::calculateViewPixelTolerance( envelope, mMapCoordTransform, mMapToPixel );
map2pixelTol *= map2pixelTol; //-> Use mappixelTol for 'LengthSquare' calculations.
double x,y, lastX=0, lastY=0;
double x, y, lastX = 0, lastY = 0;

char* xsourcePtr = (char*)xptr;
char* ysourcePtr = (char*)yptr;
char* xtargetPtr = (char*)xptr;
char* ytargetPtr = (char*)yptr;
char* xsourcePtr = ( char* )xptr;
char* ysourcePtr = ( char* )yptr;
char* xtargetPtr = ( char* )xptr;
char* ytargetPtr = ( char* )yptr;

for ( int i = 0, numPoints = geometryType==QGis::Polygon ? pointCount-1 : pointCount; i < numPoints; ++i )
for ( int i = 0, numPoints = geometryType == QGis::Polygon ? pointCount - 1 : pointCount; i < numPoints; ++i )
{
memcpy( &x, xsourcePtr, sizeof( double ) ); xsourcePtr += xStride;
memcpy( &y, ysourcePtr, sizeof( double ) ); ysourcePtr += yStride;

if ( i==0 || !canbeGeneralizable || QgsMapToPixelSimplifier::calculateLengthSquared2D(x,y,lastX,lastY)>map2pixelTol )
if ( i == 0 || !canbeGeneralizable || QgsMapToPixelSimplifier::calculateLengthSquared2D( x, y, lastX, lastY ) > map2pixelTol )
{
memcpy( xtargetPtr, &x, sizeof( double ) ); lastX = x; xtargetPtr += xStride;
memcpy( ytargetPtr, &y, sizeof( double ) ); lastY = y; ytargetPtr += yStride;
Expand All @@ -86,7 +86,7 @@ bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( QGis::GeometryType geometr
memcpy( ytargetPtr, yptr, sizeof( double ) );
pointSimplifiedCount++;
}
return pointSimplifiedCount!=pointCount;
return pointSimplifiedCount != pointCount;
}

//! Simplifies the OGR-geometry (Removing duplicated points) when is applied the specified map2pixel context
Expand All @@ -97,17 +97,17 @@ bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( OGRGeometry* geometry, boo
// Simplify the geometry rewriting temporally its WKB-stream for saving calloc's.
if ( wkbGeometryType == wkbLineString )
{
OGRLineString* lineString = (OGRLineString*)geometry;
OGRLineString* lineString = ( OGRLineString* )geometry;

int numPoints = lineString->getNumPoints();
if ( (isaLinearRing && numPoints<=5) || (!isaLinearRing && numPoints<=2) ) return false;
if (( isaLinearRing && numPoints <= 5 ) || ( !isaLinearRing && numPoints <= 2 ) ) return false;

OGREnvelope env;
geometry->getEnvelope( &env );
QgsRectangle envelope( env.MinX, env.MinY, env.MaxX, env.MaxY );

// Can replace the geometry by its BBOX ?
if ( (mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyEnvelope) && canbeGeneralizedByMapBoundingBox( envelope ) )
if (( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyEnvelope ) && canbeGeneralizedByMapBoundingBox( envelope ) )
{
OGRRawPoint* points = NULL;
int numPoints = 0;
Expand Down Expand Up @@ -139,50 +139,50 @@ bool QgsOgrMapToPixelSimplifier::simplifyOgrGeometry( OGRGeometry* geometry, boo
return true;
}
else
if ( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyGeometry )
{
QGis::GeometryType geometryType = isaLinearRing ? QGis::Polygon : QGis::Line;
int numSimplifiedPoints = 0;

OGRRawPoint* points = mallocPoints( numPoints );
double* xptr = (double*)points;
double* yptr = xptr+1;
lineString->getPoints( points );

if ( simplifyOgrGeometry( geometryType, envelope, xptr, 16, yptr, 16, numPoints, numSimplifiedPoints ) )
if ( mSimplifyFlags & QgsMapToPixelSimplifier::SimplifyGeometry )
{
lineString->setPoints( numSimplifiedPoints, points );
lineString->flattenTo2D();
QGis::GeometryType geometryType = isaLinearRing ? QGis::Polygon : QGis::Line;
int numSimplifiedPoints = 0;

OGRRawPoint* points = mallocPoints( numPoints );
double* xptr = ( double* )points;
double* yptr = xptr + 1;
lineString->getPoints( points );

if ( simplifyOgrGeometry( geometryType, envelope, xptr, 16, yptr, 16, numPoints, numSimplifiedPoints ) )
{
lineString->setPoints( numSimplifiedPoints, points );
lineString->flattenTo2D();
}
return numSimplifiedPoints != numPoints;
}
return numSimplifiedPoints!=numPoints;
}
}
else
if ( wkbGeometryType == wkbPolygon )
{
OGRPolygon* polygon = (OGRPolygon*)geometry;
bool result = simplifyOgrGeometry( polygon->getExteriorRing(), true );

for ( int i = 0, numInteriorRings = polygon->getNumInteriorRings(); i < numInteriorRings; ++i )
if ( wkbGeometryType == wkbPolygon )
{
result |= simplifyOgrGeometry( polygon->getInteriorRing(i), true );
}
if ( result ) polygon->flattenTo2D();
return result;
}
else
if ( wkbGeometryType == wkbMultiLineString || wkbGeometryType == wkbMultiPolygon )
{
OGRGeometryCollection* collection = (OGRGeometryCollection*)geometry;
bool result = false;
OGRPolygon* polygon = ( OGRPolygon* )geometry;
bool result = simplifyOgrGeometry( polygon->getExteriorRing(), true );

for ( int i = 0, numGeometries = collection->getNumGeometries(); i < numGeometries; ++i )
{
result |= simplifyOgrGeometry( collection->getGeometryRef(i), wkbGeometryType==wkbMultiPolygon );
for ( int i = 0, numInteriorRings = polygon->getNumInteriorRings(); i < numInteriorRings; ++i )
{
result |= simplifyOgrGeometry( polygon->getInteriorRing( i ), true );
}
if ( result ) polygon->flattenTo2D();
return result;
}
if ( result ) collection->flattenTo2D();
return result;
}
else
if ( wkbGeometryType == wkbMultiLineString || wkbGeometryType == wkbMultiPolygon )
{
OGRGeometryCollection* collection = ( OGRGeometryCollection* )geometry;
bool result = false;

for ( int i = 0, numGeometries = collection->getNumGeometries(); i < numGeometries; ++i )
{
result |= simplifyOgrGeometry( collection->getGeometryRef( i ), wkbGeometryType == wkbMultiPolygon );
}
if ( result ) collection->flattenTo2D();
return result;
}
return false;
}

Expand All @@ -195,7 +195,7 @@ bool QgsOgrMapToPixelSimplifier::simplifyGeometry( OGRGeometry* geometry )

if ( wkbGeometryType == wkbLineString || wkbGeometryType == wkbPolygon )
{
return simplifyOgrGeometry( geometry, wkbGeometryType==wkbPolygon );
return simplifyOgrGeometry( geometry, wkbGeometryType == wkbPolygon );
}
return false;
}
2 changes: 1 addition & 1 deletion src/providers/ogr/qgsogrmaptopixelgeometrysimplifier.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class QgsOgrMapToPixelSimplifier : public QgsMapToPixelSimplifier
int mPointBufferCount;

//! Simplifies the OGR-geometry (Removing duplicated points) when is applied the specified map2pixel context
bool simplifyOgrGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount);
bool simplifyOgrGeometry( QGis::GeometryType geometryType, const QgsRectangle& envelope, double* xptr, int xStride, double* yptr, int yStride, int pointCount, int& pointSimplifiedCount );
//! Simplifies the OGR-geometry (Removing duplicated points) when is applied the specified map2pixel context
bool simplifyOgrGeometry( OGRGeometry* geometry, bool isaLinearRing );

Expand Down