Tell me more ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

below is the code that i currently have on my application that i can't have working! Each time i select a point in the mapcanvas do not display my symbol.

can anyone give me an help or point me the direction to have the code working?

thanks

i found the solution my self and i shared it here, to help others.

//create Vector layer in memory for adding iamge markers
QgsVectorLayer *symbolsLayer = new QgsVectorLayer("Point", "temporairy_points", "memory");

QgsVectorDataProvider *provider = symbolsLayer->dataProvider();

//create new feature
QgsFeature feature = QgsFeature();

QgsPoint point = ui.qgsMapCanvas->getCoordinateTransform()->toMapCoordinates(e->pos().x(), e->pos().y());
QgsGeometry *geometry = geometry->fromPoint(point);         
feature.setGeometry(geometry);

QgsSvgMarkerSymbolLayerV2 svgMarkersymbolLayerV2 = new QgsSvgMarkerSymbolLayerV2(QCoreApplication::applicationDirPath () + "/data/symbols/test.svg");

QgsSymbolLayerV2List symbolLayerV2List;
symbolLayerV2List.clear();
symbolLayerV2List.append(svgMarkersymbolLayerV2);

QgsMarkerSymbolV2 *markerSymbolV2 = new QgsMarkerSymbolV2(symbolLayerV2List);

QgsRendererCategoryV2 *rendererCategoryV2 = new QgsRendererCategoryV2(0, markerSymbolV2, "0");

QgsCategoryList categoryList;
categoryList.clear();
categoryList.append(*rendererCategoryV2);

QgsCategorizedSymbolRendererV2 *categorizedSymbolRendererV2 = new QgsCategorizedSymbolRendererV2("A", categoryList);

symbolsLayer->startEditing();
symbolsLayer->setRendererV2(categorizedSymbolRendererV2);               
symbolsLayer->addAttribute(QgsField("A", QVariant::String, "String", 4, 0, ""));

QList<QgsField> lstFields;
lstFields.insert(0, QgsField("A", QVariant::String, "String", 4, 0, ""));
provider->addAttributes(lstFields);

categorizedSymbolRendererV2->startRender(QgsRenderContext(), symbolsLayer);

feature.clearAttributeMap();
QgsAttributeMap attributeMap;
attributeMap.insert(0, "0");
feature.setAttributeMap(attributeMap);

categorizedSymbolRendererV2->renderFeature(feature, QgsRenderContext(), symbolsLayer->id().toInt(), false, false);

QgsFeatureList qgsfeaturesList = QgsFeatureList();
qgsfeaturesList.append(feature);
provider->addFeatures(qgsfeaturesList);

symbolsLayer->updateExtents();

// Add the Vector Layer to the Layer Registry
QgsMapLayerRegistry::instance()->addMapLayer(symbolsLayer, false);

myLayerSet.prepend(QgsMapCanvasLayer(symbolsLayer, true));

// Set the Map Canvas Layer Set
ui.qgsMapCanvas->setLayerSet(myLayerSet);
share|improve this question

closed as too localized by underdark Aug 24 '12 at 19:13

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.