Skip to content

Commit 86a20e9

Browse files
committed
SLD support: convert SLD rotated lines back to line pattern fill (partially fix #6173)
1 parent 727a27e commit 86a20e9

File tree

2 files changed

+107
-4
lines changed

2 files changed

+107
-4
lines changed

src/core/symbology-ng/qgsfillsymbollayerv2.cpp

Lines changed: 71 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -863,14 +863,82 @@ void QgsLinePatternFillSymbolLayer::toSld( QDomDocument &doc, QDomElement &eleme
863863
QgsSymbolLayerV2Utils::createRotationElement( doc, graphicElem, angleFunc );
864864

865865
// <se:Displacement>
866-
QPointF lineOffset( qSin( mLineAngle ) * mOffset, qCos( mLineAngle ) * mOffset );
866+
QPointF lineOffset( sin( mLineAngle ) * mOffset, cos( mLineAngle ) * mOffset );
867867
QgsSymbolLayerV2Utils::createDisplacementElement( doc, graphicElem, lineOffset );
868+
869+
if ( mOutline )
870+
{
871+
// the outline sub symbol should be stored within the Stroke element,
872+
// but it will be stored in a separated LineSymbolizer because it could
873+
// have more than one layer
874+
mOutline->toSld( doc, element, props );
875+
}
868876
}
869877

870878
QgsSymbolLayerV2* QgsLinePatternFillSymbolLayer::createFromSld( QDomElement &element )
871879
{
872-
Q_UNUSED( element );
873-
return NULL;
880+
QgsDebugMsg( "Entered." );
881+
882+
QString name;
883+
QColor fillColor, lineColor;
884+
double size, lineWidth;
885+
886+
QDomElement fillElem = element.firstChildElement( "Fill" );
887+
if ( fillElem.isNull() )
888+
return NULL;
889+
890+
QDomElement graphicFillElem = fillElem.firstChildElement( "GraphicFill" );
891+
if ( graphicFillElem.isNull() )
892+
return NULL;
893+
894+
QDomElement graphicElem = graphicFillElem.firstChildElement( "Graphic" );
895+
if ( graphicElem.isNull() )
896+
return NULL;
897+
898+
if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, fillColor, lineColor, lineWidth, size ) )
899+
return NULL;
900+
901+
if ( name != "horline" )
902+
return NULL;
903+
904+
double angle = 0.0;
905+
QString angleFunc;
906+
if ( QgsSymbolLayerV2Utils::rotationFromSldElement( graphicElem, angleFunc ) )
907+
{
908+
bool ok;
909+
double d = angleFunc.toDouble( &ok );
910+
if ( ok )
911+
angle = d;
912+
}
913+
914+
double offset = 0.0;
915+
QPointF vectOffset;
916+
if ( QgsSymbolLayerV2Utils::displacementFromSldElement( graphicElem, vectOffset ) )
917+
{
918+
offset = sqrt( pow( vectOffset.x(), 2 ) + pow( vectOffset.y(), 2 ) );
919+
}
920+
921+
QgsLinePatternFillSymbolLayer* sl = new QgsLinePatternFillSymbolLayer();
922+
sl->setColor( lineColor );
923+
sl->setLineWidth( lineWidth );
924+
sl->setLineAngle( angle );
925+
sl->setOffset( offset );
926+
sl->setDistance( size );
927+
928+
// try to get the outline
929+
QDomElement strokeElem = element.firstChildElement( "Stroke" );
930+
if ( !strokeElem.isNull() )
931+
{
932+
QgsSymbolLayerV2 *l = QgsSymbolLayerV2Utils::createLineLayerFromSld( strokeElem );
933+
if ( l )
934+
{
935+
QgsSymbolLayerV2List layers;
936+
layers.append( l );
937+
sl->setSubSymbol( new QgsLineSymbolV2( layers ) );
938+
}
939+
}
940+
941+
return sl;
874942
}
875943

876944
////////////////////////

src/core/symbology-ng/qgssymbollayerv2utils.cpp

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1097,7 +1097,42 @@ bool QgsSymbolLayerV2Utils::needMarkerLine( QDomElement &element )
10971097
return hasWellKnownMark( graphicStrokeElem );
10981098
}
10991099

1100-
bool QgsSymbolLayerV2Utils::needLinePatternFill( QDomElement &element ) { Q_UNUSED( element ); return false; }
1100+
bool QgsSymbolLayerV2Utils::needLinePatternFill( QDomElement &element ) {
1101+
QDomElement fillElem = element.firstChildElement( "Fill" );
1102+
if ( fillElem.isNull() )
1103+
return false;
1104+
1105+
QDomElement graphicFillElem = fillElem.firstChildElement( "GraphicFill" );
1106+
if ( graphicFillElem.isNull() )
1107+
return false;
1108+
1109+
QDomElement graphicElem = graphicFillElem.firstChildElement( "Graphic" );
1110+
if ( graphicElem.isNull() )
1111+
return false;
1112+
1113+
// line pattern fill uses horline wellknown marker with an angle
1114+
1115+
QString name;
1116+
QColor fillColor, borderColor;
1117+
double size, borderWidth;
1118+
if ( !QgsSymbolLayerV2Utils::wellKnownMarkerFromSld( graphicElem, name, fillColor, borderColor, borderWidth, size ) )
1119+
return false;
1120+
1121+
if ( name != "horline" )
1122+
return false;
1123+
1124+
QString angleFunc;
1125+
if ( !QgsSymbolLayerV2Utils::rotationFromSldElement( graphicElem, angleFunc ) )
1126+
return false;
1127+
1128+
bool ok;
1129+
double angle = angleFunc.toDouble( &ok );
1130+
if ( !ok || angle == 0 )
1131+
return false;
1132+
1133+
return true;
1134+
}
1135+
11011136
bool QgsSymbolLayerV2Utils::needPointPatternFill( QDomElement &element ) { Q_UNUSED( element ); return false; }
11021137

11031138
bool QgsSymbolLayerV2Utils::needSvgFill( QDomElement &element )

0 commit comments

Comments
 (0)