[Qgis-developer] Displaying map with QgsUniqueValueRenderer

satya satya satya341 at gmail.com
Wed Mar 7 11:17:20 EST 2007


Hi Marco,
I uncommented //mypRenderer->insertValue("point",symbol); , I changed
"POINT" to "Dmg_zip" which is one of the attributes of my shape file.
Unfortunately it displayed nothing. Do i need to iterate all the points in
the shaped file??
Thaking you
regards
satya


On 3/7/07, Marco Hugentobler <marco.hugentobler at karto.baug.ethz.ch> wrote:
>
> Hi Satya,
>
> Just use the Method QgsUniqueValueRenderer::insertValue(QString name,
> QgsSymbol* symbol). The first parameter is the attribute value for which
> the
> symbol is valid, the second a pointer to your symbol (ok, 'name' is a
> misleading name for the parameter...)
>
> In the code below, there is the outcommented line
> //mypRenderer->insertValue("point",symbol);
> I suppose "point" is not the attribute value for which you want the symbol
> to
> be applied? Try to replace it with the attribute value and see if it
> works.
>
> If you want the symbol to be valid for all features, then you can use
> QgsSingleSymbolRenderer, method
> QgsSingleSymbolRenderer::addSymbol(QgsSymbol*)
>
> Best regards,
> Marco
>
> Am Mittwoch, 7. März 2007 15:38 schrieb satya satya:
> > Hi tim,
> > Here is the code
> >
> > // QGIS Includes
> > // Qt Includes
> > // Std Includes
> >
> > int main(int argc, char ** argv)
> > {
> >   // Start the Application
> >   QgsApplication app(argc, argv, true);
> >
> >   QString myPluginsDir        = "...../lib/qgis";
> >   QString myLayerPath1         = ".............................
> > .......shp"; QString myLayerBaseName1     = "....................shp";
> >   QString myProviderName      = "ogr";
> >   QgsSymbol* symbol;
> >   QColor* color;
> >
> >
> >     color = new QColor(255,0,0,255);
> >
> >         symbol = new QgsSymbol(color->rgb());
> >
> >   // Instantiate Provider Registry
> >   QgsProviderRegistry::instance(myPluginsDir);
> >   QgsVectorLayer * mypLayer = new QgsVectorLayer(myLayerPath1,
> > myLayerBaseName1, myProviderName);
> >
> >    //get the field list associated with the layer
> > std::vector<QgsField> myFields=mypLayer->fields();
> >   QgsUniqueValueRenderer *mypRenderer=new
> > QgsUniqueValueRenderer(mypLayer->vectorType());
> >
> >   mypRenderer->setClassificationField(5);
> >
> > symbol->setColor(Qt::red);
> >   symbol->setFillColor(QColor(255,0,0));
> >   symbol->setLabel("HELLO");
> >   symbol->setPointSize (5);
> >
> >
> >   std::deque<QString> myLayerSet;
> >   mypLayer->setRenderer(mypRenderer);
> > //mypRenderer->insertValue("point",symbol);
> > if (mypLayer->isValid())
> >   {
> >     qDebug("Layer is valid");
> >   }
> >   else
> >   {
> >     qDebug("Layer is NOT valid");
> >   }
> >
> >   // Add the Vector Layer to the Layer Registry
> >
> >   QgsMapLayerRegistry::instance()->addMapLayer(mypLayer, TRUE);
> >     // Add the Layer to the Layer Set
> >
> >
> >
> >   myLayerSet.push_back(mypLayer->getLayerID());
> >   mypLayer->setVisible(TRUE);
> >
> >
> >
> >   // Create the Map Canvas
> >   QgsMapCanvas * mypMapCanvas = new QgsMapCanvas(0, 0);
> >   mypMapCanvas->setExtent(mypLayer->extent());
> >   // cbit qDebug(mypMapCanvas->extent().stringRep(2));
> >
> >   mypMapCanvas->enableAntiAliasing(true);
> >   mypMapCanvas->setCanvasColor(QColor(255, 255, 255));
> >   mypMapCanvas->freeze(false);
> >   // Set the Map Canvas Layer Set
> >   mypMapCanvas->setLayerSet(myLayerSet);
> >   mypMapCanvas->setVisible(true);
> >   mypMapCanvas->refresh();
> >  // Start the Application Event Loop
> > //cout<<marker_symbol->picture().toStdString()<<endl;
> > app.exec();
> >  //QgsMapCanvas myMapCanvas(0, 0);
> >  QgsMapLayerRegistry::instance()->removeAllMapLayers();
> > return 0;
> > }
> >
> > I created symbol, but don't know how to add that to the unique value
> > renderer.
> >
> > Thanking you
> > cheers
> > satya
> >
> > > On 3/5/07, Tim Sutton <tim at linfiniti.com> wrote:
> > > > Hi
> > > >
> > > > How about posting code examples of what you have tried and we can
> try
> > > > to help you from there....
> > > >
> > > > Regards
> > > >
> > > > Tim
> > > >
> > > > 2007/3/5, satya satya <satya341 at gmail.com >:
> > > > > Hello all,
> > > > >               I am trying to develop a simple application using
> QGis
> > > >
> > > > API.
> > > >
> > > > >  I have read all tutorials on QGis blog. I would like to use
> > > > > "QgsUniqueValueRenderer" in my application to display features in
> > > > > diff
> > > > >
> > > > > colors. I tried that  "QgsUniqueValueRenderer" , but no luck.
> > > > >  could some body help me .
> > > > >  cheers
> > > > >  satya
> > > > >
> > > > > _______________________________________________
> > > > > Qgis-developer mailing list
> > > > > Qgis-developer at lists.qgis.org
> > > > > http://lists.qgis.org/cgi-bin/mailman/listinfo/qgis-developer
> > > >
> > > > --
> > > > --
> > > > Tim Sutton
> > > >
> > > > Visit http://qgis.org for a great Open Source GIS
> > > > Home Page: http://linfiniti.com
> > > > Skype: timlinux
> > > > MSN: tim_bdworld at msn.com
> > > > Yahoo: tim_bdworld at yahoo.com
> > > > Jabber: timlinux
> > > > Irc: timlinux on #qgis at freenode.net
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/qgis-developer/attachments/20070307/627ae26b/attachment.html


More information about the Qgis-developer mailing list