Controlling classitems through PHP? (Tanzanian protected areas)

Kristjan Annus kristjan at TARKVARASTUUDIO.EE
Fri Mar 18 03:35:45 EST 2005


You must use shapefile object and build some cycle i.e

for ($i=0,$i<$oShapefile->numshapes,$i++) {

   // and here use $oShapefile->getshape() method to get the shape
object and then change the color of the
  // one existing class of your layer and then draw the object

}

Kristjan

>After trying this, my experience is that I can control classes which already
>have been defined in the .map-file. Fair enough, but when operating with
>24*22 squares totalling 528 squares (from one shapefile) I have two
>problems:
>
>o Making the basic mapfile with 528 classes sounds like a lot of manual
>work. Perhaps I could do this through PHP. The procedure you illustrated
>involves changing an existing class. Adding classes with php?
>
>o But then, wouldn't 528 classes exceed the max nr of classes? (Think I read
>this somewhere on the list)
>
>On a later stage I will have to handle a grid with more squares (240*220
>totalling 52.800 squares). The plan is to make a system where animal
>sightings information is allocated to the squares (size 5*5 km). For example
>we could end up with a map of green squares where we have had observations
>of certain animals (presence maps). We could also invert the maps and use
>them for planning new surveys.
>
>One solution suggested below by Kristjan is to draw the objects within a
>shape-file individually. This sounds like a good idea since we would not
>have to operate with classes (which is not really necessary in this case).
>
>But how is this done - by using PHP?
>
>
>Ragnvald
>
>PS I guess the code I will develop based on this will be made available as
>an example with some dummy data, so the information will not be lost on me
>:-)
>
>-----Original Message-----
>From: Kristjan Annus [mailto:kristjan at tarkvarastuudio.ee]
>Sent: 18. mars 2005 00:02
>To: Ragnvald Larsen
>Subject: Re: [UMN_MAPSERVER-USERS] Controlling classitems through PHP?
>(Tanzanian protected areas)
>
>This is some fragment of the code witch I use to color the bus line
>depending of is it an express bus or not:
>
>$oCurrLayer = $map->getlayerbyname("Lines")
>
>$classObj = $oCurrLayer->getClass( 0);
>$styleobj = $classObj->getstyle(0);
>$styleobj->color->setRGB( 0, 0, 250);
>
>I assume that you could get the Parks layer and change all the classes
>in that layer according to the information in the database. getClass(0)
>gives you
>the first class in your map file (Serengeti), getClass(1) second one and
>so on.
>
>It is allso possible to use just one class and loop through the objects
>in the shapefile and color the class  by database information and then
>draw the particular shape.
>
>Kristjan
>
>
>
>>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