Controlling classitems through PHP? (Tanzanian protected areas)

Ragnvald Larsen ragnvald at MINDLAND.COM
Thu Mar 17 23:56:30 EST 2005


Some emails did not reach the list, so I will try to post the followup
discussion here:

Answer to Kristjans first question:

>the control structure around is really not a problem.
>The problem is how to do with PHP what I manage to
>do with the code in my request.

Kristjan then wrote:

>Do you mean, how to create new layers and classes in PHP, so
>that you dont have the pre-defined classes in the map file?


My answer:

No, not new layers and classes. I would like to extend the ones I already
have. Eg change this one:

CLASS
  COLOR 210 210 210
  SYMBOL 0
  EXPRESSION "Ikorongo"
  NAME "Ikorongo"
END

Let's imagine I start with all the parks in a neutral grey like the one
above. Then the user wants to know how elephants are distributed in
between the parks by visual inspection. Here at TAWIRI we just happen to
have such numbers in a database, but we currently make the maps manually.
With numbers from several years and also for other species than the
elephant it will be a very big job to make all the maps - of which some
probably not will be interesting anyway.

So, I really would like to control the color of the specific classes by
using PHP.

Making new classes like the one above would also be very useful.

The next thing is that I also have a shapefile with 22x24 squares (half
degree sizes) with unique names. Used the fishnet functionality to make
the grid squares. It is similar to the ggrid currently used by the
Tanzania Bird Atlas project (http://tanzaniabirdatlas.com/). The Birdatlas
has been subject to Mapserver earlier:

http://www.gis.unbc.ca/courses/geog413/projects/2004/hoffman/

Based on our data I also hope to be able to make a presence/absence map by
highlighting the grid squares. This problem is a bit like the one above,
but the number of objects to be controlled is big.


Ragnvald


-----Original Message-----
From: Kristjan Annus [mailto:kristjan at tarkvarastuudio.ee]
Sent: 17. mars 2005 18:00
To: Ragnvald Larsen
Subject: Re: [UMN_MAPSERVER-USERS] Controlling classitems through PHP?
(Tanzanian protected areas)

Do you mean, how to create new layers and classes in PHP, so that you dont
have the pre-defined classes in the map file?

Kristjan

>Hello,
>     the control structure around is really not a problem. The problem
>is how to do with PHP what I manage to do with the code in my request.
>
>Ragnvald
>
>-----Original Message-----
>From: Kristjan Annus [mailto:kristjan at tarkvarastuudio.ee]
>Sent: 17. mars 2005 16:43
>To: Ragnvald; MAPSERVER-USERS at LISTS.UMN.EDU
>Subject: Re: [UMN_MAPSERVER-USERS] Controlling classitems through PHP?
>(Tanzanian protected areas)
>
>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