ポリゴンのシンボルQgsFillSymbolの設定(構築)はQgsFillSymbolクラスのメソッドcreateSimpleにスタイルを渡して設定する。
内部の色、外周の色を設定する時は
QgsFillSymbol.createSimple({'color': '0,0,0,0','outline_color': '255,0,0,255'})
更に内部のパターンを設定する時は
QgsFillSymbol.createSimple({'color': '0,0,0,0','outline_color': '255,0,0,255','style' : 'diagonal_x'})
設定のキーはQgsSymbolLayer::createを参考
QgsSymbolLayer *QgsSimpleFillSymbolLayer::create( const QgsStringMap &props ) { QColor color = DEFAULT_SIMPLEFILL_COLOR; Qt::BrushStyle style = DEFAULT_SIMPLEFILL_STYLE; QColor strokeColor = DEFAULT_SIMPLEFILL_BORDERCOLOR; Qt::PenStyle strokeStyle = DEFAULT_SIMPLEFILL_BORDERSTYLE; double strokeWidth = DEFAULT_SIMPLEFILL_BORDERWIDTH; Qt::PenJoinStyle penJoinStyle = DEFAULT_SIMPLEFILL_JOINSTYLE; QPointF offset; if ( props.contains( QStringLiteral( "color" ) ) ) color = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color" )] ); if ( props.contains( QStringLiteral( "style" ) ) ) style = QgsSymbolLayerUtils::decodeBrushStyle( props[QStringLiteral( "style" )] ); if ( props.contains( QStringLiteral( "color_border" ) ) ) { //pre 2.5 projects used "color_border" strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "color_border" )] ); } else if ( props.contains( QStringLiteral( "outline_color" ) ) ) { strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "outline_color" )] ); } else if ( props.contains( QStringLiteral( "line_color" ) ) ) { strokeColor = QgsSymbolLayerUtils::decodeColor( props[QStringLiteral( "line_color" )] ); } if ( props.contains( QStringLiteral( "style_border" ) ) ) { //pre 2.5 projects used "style_border" strokeStyle = QgsSymbolLayerUtils::decodePenStyle( props[QStringLiteral( "style_border" )] ); } else if ( props.contains( QStringLiteral( "outline_style" ) ) ) { strokeStyle = QgsSymbolLayerUtils::decodePenStyle( props[QStringLiteral( "outline_style" )] ); } else if ( props.contains( QStringLiteral( "line_style" ) ) ) { strokeStyle = QgsSymbolLayerUtils::decodePenStyle( props[QStringLiteral( "line_style" )] ); } if ( props.contains( QStringLiteral( "width_border" ) ) ) { //pre 2.5 projects used "width_border" strokeWidth = props[QStringLiteral( "width_border" )].toDouble(); } else if ( props.contains( QStringLiteral( "outline_width" ) ) ) { strokeWidth = props[QStringLiteral( "outline_width" )].toDouble(); } else if ( props.contains( QStringLiteral( "line_width" ) ) ) { strokeWidth = props[QStringLiteral( "line_width" )].toDouble(); } if ( props.contains( QStringLiteral( "offset" ) ) ) offset = QgsSymbolLayerUtils::decodePoint( props[QStringLiteral( "offset" )] ); if ( props.contains( QStringLiteral( "joinstyle" ) ) ) penJoinStyle = QgsSymbolLayerUtils::decodePenJoinStyle( props[QStringLiteral( "joinstyle" )] ); QgsSimpleFillSymbolLayer *sl = new QgsSimpleFillSymbolLayer( color, style, strokeColor, strokeStyle, strokeWidth, penJoinStyle ); sl->setOffset( offset ); if ( props.contains( QStringLiteral( "border_width_unit" ) ) ) { sl->setStrokeWidthUnit( QgsUnitTypes::decodeRenderUnit( props[QStringLiteral( "border_width_unit" )] ) ); } else if ( props.contains( QStringLiteral( "outline_width_unit" ) ) ) { sl->setStrokeWidthUnit( QgsUnitTypes::decodeRenderUnit( props[QStringLiteral( "outline_width_unit" )] ) ); } else if ( props.contains( QStringLiteral( "line_width_unit" ) ) ) { sl->setStrokeWidthUnit( QgsUnitTypes::decodeRenderUnit( props[QStringLiteral( "line_width_unit" )] ) ); } if ( props.contains( QStringLiteral( "offset_unit" ) ) ) sl->setOffsetUnit( QgsUnitTypes::decodeRenderUnit( props[QStringLiteral( "offset_unit" )] ) ); if ( props.contains( QStringLiteral( "border_width_map_unit_scale" ) ) ) sl->setStrokeWidthMapUnitScale( QgsSymbolLayerUtils::decodeMapUnitScale( props[QStringLiteral( "border_width_map_unit_scale" )] ) ); if ( props.contains( QStringLiteral( "offset_map_unit_scale" ) ) ) sl->setOffsetMapUnitScale( QgsSymbolLayerUtils::decodeMapUnitScale( props[QStringLiteral( "offset_map_unit_scale" )] ) ); sl->restoreOldDataDefinedProperties( props ); return sl; }
設定値はQgsSymbolLayerUtilsを参照
Qt::BrushStyle QgsSymbolLayerUtils::decodeBrushStyle( const QString &str ) { if ( str == QLatin1String( "solid" ) ) return Qt::SolidPattern; if ( str == QLatin1String( "horizontal" ) ) return Qt::HorPattern; if ( str == QLatin1String( "vertical" ) ) return Qt::VerPattern; if ( str == QLatin1String( "cross" ) ) return Qt::CrossPattern; if ( str == QLatin1String( "b_diagonal" ) ) return Qt::BDiagPattern; if ( str == QLatin1String( "f_diagonal" ) ) return Qt::FDiagPattern; if ( str == QLatin1String( "diagonal_x" ) ) return Qt::DiagCrossPattern; if ( str == QLatin1String( "dense1" ) ) return Qt::Dense1Pattern; if ( str == QLatin1String( "dense2" ) ) return Qt::Dense2Pattern; if ( str == QLatin1String( "dense3" ) ) return Qt::Dense3Pattern; if ( str == QLatin1String( "dense4" ) ) return Qt::Dense4Pattern; if ( str == QLatin1String( "dense5" ) ) return Qt::Dense5Pattern; if ( str == QLatin1String( "dense6" ) ) return Qt::Dense6Pattern; if ( str == QLatin1String( "dense7" ) ) return Qt::Dense7Pattern; if ( str == QLatin1String( "no" ) ) return Qt::NoBrush; return Qt::SolidPattern; } QString QgsSymbolLayerUtils::encodeSldBrushStyle( Qt::BrushStyle style ) { switch ( style ) { case Qt::CrossPattern: return QStringLiteral( "cross" ); case Qt::DiagCrossPattern: return QStringLiteral( "x" ); /* The following names are taken from the presentation "GeoServer * Cartographic Rendering" by Andrea Aime at the FOSS4G 2010. * (see http://2010.foss4g.org/presentations/3588.pdf) */ case Qt::HorPattern: return QStringLiteral( "horline" ); case Qt::VerPattern: return QStringLiteral( "line" ); case Qt::BDiagPattern: return QStringLiteral( "slash" ); case Qt::FDiagPattern: return QStringLiteral( "backslash" ); /* define the other names following the same pattern used above */ case Qt::Dense1Pattern: case Qt::Dense2Pattern: case Qt::Dense3Pattern: case Qt::Dense4Pattern: case Qt::Dense5Pattern: case Qt::Dense6Pattern: case Qt::Dense7Pattern: return QStringLiteral( "brush://%1" ).arg( encodeBrushStyle( style ) ); default: return QString(); } }