classifying with an external datasource

Sandeep sandeep.bashyal at GMAIL.COM
Wed Mar 2 22:10:19 PST 2005


On Wed, 2 Mar 2005 14:32:28 +0100, Richard Jansen <richardjansen at tmop.nl>
wrote:

Richard,

The only problem I've had with this method is - if there are a large
number of polygons having the same value I get classes like:    0-5, 5-5,
5-9, 9-10. Everything else seems to be working perfectly. Do you have
classes set up in your mapfile for that layer? My mapfile for layer i'm
using the external database looks something like this:

# districts
        LAYER
                NAME "districts"
                TYPE POLYGON
                STATUS OFF
                DATA "districts"
                TEMPLATE "somefile.txt"
                PROJECTION
                        "proj=tmerc"
                        "lat_0=0"
                        "lon_0=87e"
                        "x_0=50000"
                        "y_0=0"
                        "k=0.9996"
                        "units=m"
                END # end projection
                LABELITEM "DIST_NAM"
                LABELCACHE TRUE
                LABELMAXSCALE 2300000
                LABELMINSCALE 150001
        END #end Layer districts

Regards,
--Sandeep


> Hi Sandeep,
>
> I've used your code snippet to classify my polygon shapefile. This is
> working almost correct. But there is a problem with some of the
> polygons. Mapserver creates an image with some polygons that are
> coloured, but should not being coloured. The other polygons seems to be
> coloured the right way. The mapfile that has been created does not
> contain those wrong values in the expressions, so the mapfile is
> correct. The problem occurs after reading the mapfile and draw the map.
>
> Is this problem familiar to you?
>
> Thanks again,
> Richard
>
> -----Oorspronkelijk bericht-----
> Van: UMN MapServer Users List [mailto:MAPSERVER-USERS at LISTS.UMN.EDU]
> Namens Sandeep
> Verzonden: vrijdag 25 februari 2005 12:49
> Aan: MAPSERVER-USERS at LISTS.UMN.EDU
> Onderwerp: Re: [UMN_MAPSERVER-USERS] classifying with an external
> datasource
>
> On Fri, 25 Feb 2005 02:30:39 -0600, Richard Jansen
> <richardjansen at TMOP.NL>
> wrote:
>
>> Hi List,
>>
>> I want to classify and color a poly shape. The values for classifying
> are
>> stored in a SQL Server database. When I read the List I understand
> that
>> this is not possible. I'm trying to join a template dbf file with the
>> needed values. I also tried to add new field to the dbf, that's not
>> simple.
>> I'm using PHP/Mapscript. Is there a way to do this?
>>
>> Thanks for your comments,
>> Richard Jansen
>
> Richard,
>
> If you don't have a very large number of polygons to classify, here's a
> snip from one of my earlier posts:
>
> ... you can generate classes and expressions dynamically with mapscript.
> Here is the php mapscript code I use to classify districts into
> "$no_classes" number of classes (using arcview-style quantile method)
> using data from an external mysql database (the external database has a
> field called DIST_ID that associates with the shapefile):
>
> //run sql query
> $sql = "SELECT DIST_ID, DIST_NAME, ".$databasefield." FROM
> DISTRICTS_".$databasetable.$filter_where;
> $result = mysql_query($sql, $connection);
>
> // assign sql results into arrays
> while ($row = mysql_fetch_assoc($result)){
>         $ID[]=$row["DIST_ID"];
>         $DIST_NAME[]=$row["DIST_NAME"];
>         ${$databasefield}[]=$row[$databasefield];
> } //end while
>
> //sort the query results
> if (${$databasefield}){array_multisort(${$databasefield}, SORT_ASC,
> SORT_NUMERIC, $DIST_NAME, SORT_STRING, $ID, SORT_STRING);}
> mysql_free_result($result);
> mysql_close($connection);
>
> //count the number of records in the array
> $no_records=count($ID);
> if ($no_classes > $no_records){$no_classes = $no_records;}
> if ($no_classes > 0){
>         //number of class items
>         $no_classitems = ceil($no_records / $no_classes);
>         //split the arrays into chunks
>         $class_ID=array_chunk($ID,$no_classitems,true);
>         $class_value=array_chunk(${$databasefield},$no_classitems,true);
> } // end if $no_classes > 0
>
> //set classitem
> $layer_districts->set("classitem","OBJID");
>
> //draw classes
> $i=0;
> while ($i < $no_classes){
>         $i++;
>         //class expressions
>         $class_array = $class_ID[$i-1];
>         if ($class_array){
>                 $expression[$i]="/".implode("|",$class_array)."/";
>                 //legend key labels
> $class_legend_key1=$class_value[$i-1][($i-1)*$no_classitems];
> $class_legend_key2=$class_value[$i-1][($i-1)*$no_classitems
> + $no_classitems -1];
>                 if ($class_legend_key2 == NULL){$class_legend_key2 =
> $class_value[$i-1][$no_records-1];}
>                 $class_legend_key[$i]=$class_legend_key1." to
> ".$class_legend_key2;
>                 //draw layers
>                 $class[$i] = ms_newClassObj($layer_districts);
>                 $class[$i]->set("name",$class_legend_key[$i]);
>                 $class[$i]->setexpression($expression[$i]);
>                 $class_style[$i] = ms_newStyleObj ($class[$i]);
>                 $class_style[$i]->outlinecolor->setRGB(-1,-1,-1);
> $class_style[$i]->color->setRGB($color_r[$i-1],$color_g[$i-1],$color_b[$
> i-1]);
>         } // end if $class_array
> }//end while
>
> --
> Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
>



--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/



More information about the MapServer-users mailing list