Changeset 300 for trunk/zoo-kernel


Ignore:
Timestamp:
Aug 4, 2011, 9:47:03 PM (13 years ago)
Author:
djay
Message:

Make raster classification optional.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/zoo-kernel/service_internal_ms.c

    r298 r300  
    722722      msInsertHashTable(&(myLayer->metadata), tmpI, tmpMm);
    723723
    724       /**
    725        * Classify one band raster pixel value using regular interval
    726        */
    727       int _tmpColors[10][3]={
    728         {102,153,204},
    729         {51,102,153},
    730         {102,102,204},
    731         {51,204,0},
    732         {153,255,102},
    733         {204,255,102},
    734         {102,204,153},
    735         {255,69,64},
    736         {255,192,115},
    737         {255,201,115}
    738       };
    739 
    740       if(nBandsI==1){
    741         double delta=adfCMinMax[1]-adfCMinMax[0];
    742         double interval=delta/10;
    743         double cstep=adfCMinMax[0];
    744         for(i=0;i<10;i++){
    745           /**
    746            * Create a new class
    747            */
    748           if(msGrowLayerClasses(myLayer) == NULL)
    749             return;
    750           if(initClass((myLayer->class[myLayer->numclasses])) == -1)
    751             return;
    752           myLayer->class[myLayer->numclasses]->type = myLayer->type;
    753           if(msGrowClassStyles(myLayer->class[myLayer->numclasses]) == NULL)
    754             return ;
    755           if(initStyle(myLayer->class[myLayer->numclasses]->styles[myLayer->class[myLayer->numclasses]->numstyles]) == -1)
    756             return;
    757 
    758           /**
    759            * Set class name
    760            */
    761           char className[7];
    762           sprintf(className,"class%d",i);
    763           myLayer->class[myLayer->numclasses]->name=strdup(className);
    764 
    765           /**
    766            * Set expression
    767            */
    768           char expression[1024];
    769           if(i+1<10)
    770             sprintf(expression,"([pixel]>=%.3f AND [pixel]<%.3f)",cstep,cstep+interval);
    771           else
    772             sprintf(expression,"([pixel]>=%.3f AND [pixel]<=%.3f)",cstep,cstep+interval);
    773           msLoadExpressionString(&myLayer->class[myLayer->numclasses]->expression,expression);
    774 
    775           /**
    776            * Set color
    777            */
    778           myLayer->class[myLayer->numclasses]->styles[myLayer->class[myLayer->numclasses]->numstyles]->color.red=_tmpColors[i][0];
    779           myLayer->class[myLayer->numclasses]->styles[myLayer->class[myLayer->numclasses]->numstyles]->color.green=_tmpColors[i][1];
    780           myLayer->class[myLayer->numclasses]->styles[myLayer->class[myLayer->numclasses]->numstyles]->color.blue=_tmpColors[i][2];
    781           cstep+=interval;
    782           myLayer->class[myLayer->numclasses]->numstyles++;
    783           myLayer->numclasses++;
    784        
     724      map* test=getMap(output->content,"msClassify");
     725      if(test!=NULL && strncasecmp(test->value,"true",4)==0){
     726        /**
     727         * Classify one band raster pixel value using regular interval
     728         */
     729        int _tmpColors[10][3]={
     730          {102,153,204},
     731          {51,102,153},
     732          {102,102,204},
     733          {51,204,0},
     734          {153,255,102},
     735          {204,255,102},
     736          {102,204,153},
     737          {255,69,64},
     738          {255,192,115},
     739          {255,201,115}
     740        };
     741         
     742        if(nBandsI==1){
     743          double delta=adfCMinMax[1]-adfCMinMax[0];
     744          double interval=delta/10;
     745          double cstep=adfCMinMax[0];
     746          for(i=0;i<10;i++){
     747            /**
     748             * Create a new class
     749             */
     750            if(msGrowLayerClasses(myLayer) == NULL)
     751              return;
     752            if(initClass((myLayer->class[myLayer->numclasses])) == -1)
     753              return;
     754            myLayer->class[myLayer->numclasses]->type = myLayer->type;
     755            if(msGrowClassStyles(myLayer->class[myLayer->numclasses]) == NULL)
     756              return ;
     757            if(initStyle(myLayer->class[myLayer->numclasses]->styles[myLayer->class[myLayer->numclasses]->numstyles]) == -1)
     758              return;
     759           
     760            /**
     761             * Set class name
     762             */
     763            char className[7];
     764            sprintf(className,"class%d",i);
     765            myLayer->class[myLayer->numclasses]->name=strdup(className);
     766           
     767            /**
     768             * Set expression
     769             */
     770            char expression[1024];
     771            if(i+1<10)
     772              sprintf(expression,"([pixel]>=%.3f AND [pixel]<%.3f)",cstep,cstep+interval);
     773            else
     774              sprintf(expression,"([pixel]>=%.3f AND [pixel]<=%.3f)",cstep,cstep+interval);
     775            msLoadExpressionString(&myLayer->class[myLayer->numclasses]->expression,expression);
     776           
     777            /**
     778             * Set color
     779             */
     780            myLayer->class[myLayer->numclasses]->styles[myLayer->class[myLayer->numclasses]->numstyles]->color.red=_tmpColors[i][0];
     781            myLayer->class[myLayer->numclasses]->styles[myLayer->class[myLayer->numclasses]->numstyles]->color.green=_tmpColors[i][1];
     782            myLayer->class[myLayer->numclasses]->styles[myLayer->class[myLayer->numclasses]->numstyles]->color.blue=_tmpColors[i][2];
     783            cstep+=interval;
     784            myLayer->class[myLayer->numclasses]->numstyles++;
     785            myLayer->numclasses++;
     786           
     787          }
     788         
     789          char tmpMm[100];
     790          sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
     791         
    785792        }
    786      
    787         char tmpMm[100];
    788         sprintf(tmpMm,"%.3f %.3f",adfCMinMax[0],adfCMinMax[1]);
    789 
    790       }
    791 
     793      }
    792794    }
    793795    if( strlen(GDALGetRasterUnitType(hBand)) > 0 ){
Note: See TracChangeset for help on using the changeset viewer.

Search

Context Navigation

ZOO Sponsors

http://www.zoo-project.org/trac/chrome/site/img/geolabs-logo.pnghttp://www.zoo-project.org/trac/chrome/site/img/neogeo-logo.png http://www.zoo-project.org/trac/chrome/site/img/apptech-logo.png http://www.zoo-project.org/trac/chrome/site/img/3liz-logo.png http://www.zoo-project.org/trac/chrome/site/img/gateway-logo.png

Become a sponsor !

Knowledge partners

http://www.zoo-project.org/trac/chrome/site/img/ocu-logo.png http://www.zoo-project.org/trac/chrome/site/img/gucas-logo.png http://www.zoo-project.org/trac/chrome/site/img/polimi-logo.png http://www.zoo-project.org/trac/chrome/site/img/fem-logo.png http://www.zoo-project.org/trac/chrome/site/img/supsi-logo.png http://www.zoo-project.org/trac/chrome/site/img/cumtb-logo.png

Become a knowledge partner

Related links

http://zoo-project.org/img/ogclogo.png http://zoo-project.org/img/osgeologo.png