In my maps I have a symbol, his type is polygon, I want to change the line style of the border, actually is solid , I had to put it in dash
Is there a simple way to change it ? i think to the QgsLineSymbolV2 ?
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It only takes a minute to sign up.
Sign up to join this communityIn my maps I have a symbol, his type is polygon, I want to change the line style of the border, actually is solid , I had to put it in dash
Is there a simple way to change it ? i think to the QgsLineSymbolV2 ?
Here is the code in C++ based on the post here : How to set Marker Line symbol for QgsVectorLayer by using Python?
thanks to Durga for the link in his answer.
So here is the code in c++ to change the style of the border of a polygon, in this exemple the color is white and the penstyle is dashed.
QgsSymbolLayerV2Registry * MyRegistry = QgsSymbolLayerV2Registry::instance();
QgsSymbolLayerV2AbstractMetadata * MyLineMeta;
MyLineMeta = MyRegistry->symbolLayerMetadata("SimpleLine");
//create lineMap Properties
QgsStringMap MyLineMap;
QStringList MyLineMapProperties;
MyLineMapProperties <<"width" << "color" << "offset" << "penstyle" << "use_custom_dash" << "joinstyle" << "capstyle";
QStringList MyLineMapValues;
MyLineMapValues << "0.25" << "255,255,255" << "0" << "dash" << "0" << "bevel" << "square";
for (int i =0; i < MyLineMapProperties.size(); i++){
MyLineMap.insert(MyLineMapProperties.at(i),MyLineMapValues.at(i));
}
QgsSymbolLayerV2 * MyLineLayer = MyLineMeta->createSymbolLayer(MyLineMap);
pLayer->rendererV2()->symbols()[0]->setColor(QColor("#c545c3"));
pLayer->rendererV2()->symbols()[0]->appendSymbolLayer(MyLineLayer);
pLayer->setRendererV2(lrenderer);
Now you can change the color or the pen-style, you can also add some properties if you need that, the properties list can be found in the book The PyQGis Programmer's Guide page 92 to 97