Controlling classitems through PHP? (Tanzanian protected areas)
Kristjan Annus
kristjan at TARKVARASTUUDIO.EE
Thu Mar 17 05:42:44 PST 2005
Hi,
I am a little bit confused what you actually want to do? If you have the
data witch you want to publish in database, then
you could for example loop through the records and draw each one of them
to the map with PHP functions and change the
color or appearance of the current shape before you draw this particular
shape. In this case you could use different pre-made
classes in your map file and change the classitem of the shape.
How the actual code should look like depends witch database you are
using and how the datastructure is organized.
I can make you a better example if I could have more information.
But generally it could be something like this:
do (with every shape on the database) {
// gather the points to the shape from your database (some loop required
I assume):
$line = ms_newLineObj();
do ( ... ) {
$point = ms_newPointObj();
$point->setXY( $myrow["koord1"], $myrow["koord2"]);
$line->add( $point);
}
// draw the shape to the map ( the $classitem variable could be set
before by some information from your database)
$pind=ms_newShapeObj( 2);
$pind->add($line);
$lshape->draw( $map, $layer, $image, $classitem, $tekst);
}
Kristjan
> I have a layer of Tanzanian protected areas (National parks, Game
> Reserves, Conservation areas, etc). My goal is to be able to control
> the visual appearances of the separate parks based on numerical data
> in an animal survey database using PHP.
>
> I am really struggling with this and have not been able to figure it
> out. I have done several searches, and to be honest working with
> classes through PHP is a bit new to me. If I manage to do this it will
> be VERY helpful for us here at TAWIRI.
>
> The planned script should generate different maps for different
> estimated species concentrations in these protected areas. The first
> step is to be able to control the different parks appearances by
> referring to their names. (Currently the developed solution will only
> be for testing purposes and internal use at my department.)
>
> This is what I can do by using a simple map-file:
>
> http://www.mindland.com/test/tanzania_parks_pres_1.gif
>
> The code for the “Parks” layer is like this:
>
> LAYER
>
> NAME "Parks"
>
> TYPE POLYGON
>
> STATUS ON
>
> DATA "TZ_PAs_2002_Poly"
>
> PROJECTION
>
> "proj=latlong"
>
> "ellps=GRS80"
>
> "datum=NAD83"
>
> END
>
> CLASSITEM 'NAME'
>
> CLASS
>
> COLOR 190 190 190
>
> SYMBOL 0
>
> EXPRESSION "Serengeti"
>
> NAME "Serengeti"
>
> END
>
> CLASS
>
> COLOR 210 210 210
>
> SYMBOL 0
>
> EXPRESSION "Ikorongo"
>
> NAME "Ikorongo"
>
> END
>
> CLASS
>
> COLOR 220 220 220
>
> SYMBOL 0
>
> EXPRESSION "Grumeti"
>
> NAME "Grumeti"
>
> END
>
> CLASS
>
> COLOR 220 220 220
>
> SYMBOL 0
>
> EXPRESSION "Masawa"
>
> NAME "Masawa"
>
> END
>
> CLASS
>
> COLOR 220 220 220
>
> SYMBOL 0
>
> EXPRESSION "Ngorongoro"
>
> NAME "Ngorogoro"
>
> END
>
> END
>
> END
>
> The question is then how to control the CLASSITEM color appearance and
> also selection of which classitems to show - through PHP. In the end I
> will use database queries, but for now I will be happy to do this by
> hard coding it in PHP. I am able to do changes on the other parks (not
> displayed as classitems). This code is added before the map is drawn:
>
> $layerObj = $map->getlayerbyname("Parks");
>
> $class = ms_newClassObj($layerObj);
>
> $style = ms_newStyleObj($class);
>
> $style->color->setRGB(200,200,0);
>
> Resulting image is then:
>
> http://www.mindland.com/test/tanzania_parks_pres_2.gif
>
> Suggestions and references to relevant postings would be fine. I re
>
> Ragnvald Larsen
>
> Geographer / data systems developer
>
> Conservation Information and Monitoring Unit,
>
> Tanzania Wildlife Researc Institute,
>
> Tanzania
>
More information about the MapServer-users
mailing list