[Qgis-developer] Displaying map with QgsUniqueValueRenderer

satya satya satya341 at gmail.com
Wed Mar 7 09:38:43 EST 2007


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/45296665/attachment.html


More information about the Qgis-developer mailing list