Skip to content
Permalink
Browse files

Merge pull request #5144 from boundlessgeo/Backport_Fix_uom_reading

[bugfix] backport from 3.0 Fix unit of sizes when reading a SLD file (fixes #8978)
  • Loading branch information
elpaso committed Sep 13, 2017
2 parents b3a8d6f + 439477a commit 1d702d296e2148a8fad2bd4b605f0c234d7dba2d
@@ -57,6 +57,14 @@ class QgsSymbolLayerV2Utils
static QString encodeSldUom( QgsSymbolV2::OutputUnit unit, double *scaleFactor );
static QgsSymbolV2::OutputUnit decodeSldUom( const QString& str, double *scaleFactor );

/** Returns the size scaled in pixels according to the uom attribute.
* \param uom The uom attribute from SLD 1.1 version
* \param size The original size
* \returns the size in pixels
* \since QGIS 3.0
*/
static double sizeInPixelsFromSldUom( const QString &uom, double size );

static QString encodeScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
static QgsSymbolV2::ScaleMethod decodeScaleMethod( const QString& str );

@@ -490,6 +490,10 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::createFromSld( QDomElement &element )
if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderStyle, borderWidth, size ) )
return nullptr;

const QString uom = element.attribute( QString( "uom" ), "" );
size = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, size );
borderWidth = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, borderWidth );

double angle = 0.0;
QString angleFunc;
if ( QgsSymbolLayerV2Utils::rotationFromSldElement( graphicElem, angleFunc ) )
@@ -501,6 +505,7 @@ QgsSymbolLayerV2* QgsEllipseSymbolLayerV2::createFromSld( QDomElement &element )
}

QgsEllipseSymbolLayerV2 *m = new QgsEllipseSymbolLayerV2();
m->setOutputUnit( QgsSymbolV2::Pixel );
m->setSymbolName( name );
m->setFillColor( fillColor );
m->setOutlineColor( borderColor );
@@ -390,7 +390,13 @@ QgsSymbolLayerV2* QgsSimpleFillSymbolLayerV2::createFromSld( QDomElement &elemen
QPointF offset;
QgsSymbolLayerV2Utils::displacementFromSldElement( element, offset );

QString uom = element.attribute( QString( "uom" ), "" );
offset.setX( QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, offset.x() ) );
offset.setY( QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, offset.y() ) );
borderWidth = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, borderWidth );

QgsSimpleFillSymbolLayerV2* sl = new QgsSimpleFillSymbolLayerV2( color, fillStyle, borderColor, borderStyle, borderWidth );
sl->setOutputUnit( QgsSymbolV2::Pixel );
sl->setOffset( offset );
return sl;
}
@@ -2159,6 +2165,10 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::createFromSld( QDomElement &element )

QgsSymbolLayerV2Utils::lineFromSld( graphicElem, penStyle, borderColor, borderWidth );

QString uom = element.attribute( QString( "uom" ), "" );
size = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, size );
borderWidth = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, borderWidth );

double angle = 0.0;
QString angleFunc;
if ( QgsSymbolLayerV2Utils::rotationFromSldElement( graphicElem, angleFunc ) )
@@ -2170,6 +2180,7 @@ QgsSymbolLayerV2* QgsSVGFillSymbolLayer::createFromSld( QDomElement &element )
}

QgsSVGFillSymbolLayer* sl = new QgsSVGFillSymbolLayer( path, size, angle );
sl->setOutputUnit( QgsSymbolV2::Pixel );
sl->setSvgFillColor( fillColor );
sl->setSvgOutlineColor( borderColor );
sl->setSvgOutlineWidth( borderWidth );
@@ -3018,7 +3029,12 @@ QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::createFromSld( QDomElement &ele
offset = sqrt( pow( vectOffset.x(), 2 ) + pow( vectOffset.y(), 2 ) );
}

QString uom = element.attribute( QString( "uom" ), "" );
size = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, size );
lineWidth = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, lineWidth );

QgsLinePatternFillSymbolLayer* sl = new QgsLinePatternFillSymbolLayer();
sl->setOutputUnit( QgsSymbolV2::Pixel );
sl->setColor( lineColor );
sl->setLineWidth( lineWidth );
sl->setLineAngle( angle );
@@ -471,7 +471,12 @@ QgsSymbolLayerV2* QgsSimpleLineSymbolLayerV2::createFromSld( QDomElement &elemen
offset = d;
}

QString uom = element.attribute( QString( "uom" ), "" );
width = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, width );
offset = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, offset );

QgsSimpleLineSymbolLayerV2* l = new QgsSimpleLineSymbolLayerV2( color, width, penStyle );
l->setOutputUnit( QgsSymbolV2::Pixel );
l->setOffset( offset );
l->setPenJoinStyle( penJoinStyle );
l->setPenCapStyle( penCapStyle );
@@ -1551,7 +1556,12 @@ QgsSymbolLayerV2* QgsMarkerLineSymbolLayerV2::createFromSld( QDomElement &elemen
offset = d;
}

QString uom = element.attribute( QString( "uom" ), "" );
interval = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, interval );
offset = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, offset );

QgsMarkerLineSymbolLayerV2* x = new QgsMarkerLineSymbolLayerV2( rotateMarker );
x->setOutputUnit( QgsSymbolV2::Pixel );
x->setPlacement( placement );
x->setInterval( interval );
x->setSubSymbol( marker );
@@ -1239,7 +1239,13 @@ QgsSymbolLayerV2* QgsSimpleMarkerSymbolLayerV2::createFromSld( QDomElement &elem

Shape shape = decodeShape( name );

QString uom = element.attribute( QString( "uom" ), "" );
size = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, size );
offset.setX( QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, offset.x() ) );
offset.setY( QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, offset.y() ) );

QgsSimpleMarkerSymbolLayerV2 *m = new QgsSimpleMarkerSymbolLayerV2( shape, size );
m->setOutputUnit( QgsSymbolV2::Pixel );
m->setColor( color );
m->setBorderColor( borderColor );
m->setAngle( angle );
@@ -2266,6 +2272,9 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
if ( !QgsSymbolLayerV2Utils::externalGraphicFromSld( graphicElem, path, mimeType, fillColor, size ) )
return nullptr;

QString uom = element.attribute( QString( "uom" ), "" );
size = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, size );

if ( mimeType != "image/svg+xml" )
return nullptr;

@@ -2283,6 +2292,7 @@ QgsSymbolLayerV2* QgsSvgMarkerSymbolLayerV2::createFromSld( QDomElement &element
QgsSymbolLayerV2Utils::displacementFromSldElement( graphicElem, offset );

QgsSvgMarkerSymbolLayerV2* m = new QgsSvgMarkerSymbolLayerV2( path, size );
m->setOutputUnit( QgsSymbolV2::Pixel );
m->setFillColor( fillColor );
//m->setOutlineColor( outlineColor );
//m->setOutlineWidth( outlineWidth );
@@ -2945,7 +2955,13 @@ QgsSymbolLayerV2* QgsFontMarkerSymbolLayerV2::createFromSld( QDomElement &elemen
QPointF offset;
QgsSymbolLayerV2Utils::displacementFromSldElement( graphicElem, offset );

QString uom = element.attribute( QString( "uom" ), "" );
offset.setX( QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, offset.x() ) );
offset.setY( QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, offset.y() ) );
size = QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( uom, size );

QgsMarkerSymbolLayerV2 *m = new QgsFontMarkerSymbolLayerV2( fontFamily, chr, size, color );
m->setOutputUnit( QgsSymbolV2::Pixel );
m->setAngle( angle );
m->setOffset( offset );
return m;
@@ -4231,3 +4231,23 @@ void QgsSymbolLayerV2Utils::mergeScaleDependencies( int mScaleMinDenom, int mSca
props[ "scaleMaxDenom" ] = QString::number( qMin( parentScaleMaxDenom, mScaleMaxDenom ) );
}
}

double QgsSymbolLayerV2Utils::sizeInPixelsFromSldUom( const QString &uom, double size )
{
double scale = 1.0;

if ( uom == QLatin1String( "http://www.opengeospatial.org/se/units/metre" ) )
{
scale = 1.0 / 0.00028; // from meters to pixels
}
else if ( uom == QLatin1String( "http://www.opengeospatial.org/se/units/foot" ) )
{
scale = 304.8 / 0.28; // from feet to pixels
}
else
{
scale = 1.0; // from pixels to pixels (default unit)
}

return size * scale;
}
@@ -103,6 +103,14 @@ class CORE_EXPORT QgsSymbolLayerV2Utils
static QString encodeScaleMethod( QgsSymbolV2::ScaleMethod scaleMethod );
static QgsSymbolV2::ScaleMethod decodeScaleMethod( const QString& str );

/** Returns the size scaled in pixels according to the uom attribute.
* @param uom The uom attribute from SLD 1.1 version
* @param size The original size
* @returns the size in pixels
* @note added in QGIS 2.18 and 3.0
*/
static double sizeInPixelsFromSldUom( const QString &uom, double size );

static QPainter::CompositionMode decodeBlendMode( const QString& s );

static QIcon symbolPreviewIcon( QgsSymbolV2* symbol, QSize size );

0 comments on commit 1d702d2

Please sign in to comment.
You can’t perform that action at this time.