[mapserver-users] Create Dynamic Pt Layer, thenqueryByPoint()

Stephen Woodbridge woodbri at swoodbridge.com
Fri Mar 1 19:08:05 EST 2002


Dan,

I haven't tried to do what you are doing yet, but I believe the problem
is that drawing a shape on a map just renders it using the layer's
attributes, it does not add it to the layer. Therefore it is not there
when you do your query! So I'm guessing, but try 

$mylayer->addFeature($myNewShape); 

before you do the query and see if that works better.

Anyone else care to jump in here!

-Steve

Dan Barron wrote:
> 
>  >At 05:33 PM 3/1/2002 -0500, Stephen Woodbridge wrote:
>  >The LAYER must have TEMPLATE defined or it will NOT be queried so make
>  >sure you have that set.
>  >
>  >-Steve
> 
> Thanks for the reply Steve.  Query still does not find any points.  I have
> modified my map file per your suggestion, see below.  Is there some special
> way I need to create the layer?  Or does the template need to call out
> anything specific or could is just print "Hello world" if you wanted? I
> have also included my php code that queries the database and builds the layer.
> 
> Dan
> 
> << map file snip >>
> ------------------
> 
> LAYER
>    NAME 'point-test'
>    TYPE POINT
>    STATUS OFF
> 
>    CLASS
>            name 'point-test'
>      SYMBOL 'c:\bin\mapserver\mapservertest\graphics\novice-icon.png'
>    #  template 'point-test-template.html'
>    END
>    template "point-test-template.html"
>    tolerance 10
> END
> 
> << php file snip >>
> --------------------
> 
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> // Connect to mySQL database, print a successful or unsuccessful message, then
> // select the database to use.
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> $link = mysql_connect($host, $user, $pwd) or die("Could not connect");
> print "Connected to mysql  successfully<br>";
> mysql_select_db($dbase) or die("Could not select database");
> 
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> // Set query strings, then perform query
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> $query_select = "SELECT * FROM ".$table;
> $query_where[0] = " WHERE latitude < ".$map->extent->maxy;
> $query_where[1] = " AND latitude > ".$map->extent->miny;
> $query_where[2] = " AND longitude < ".$map->extent->maxx;
> $query_where[3] = " AND longitude > ".$map->extent->minx;
> 
> $result =
> mysql_query($query_select.$query_where[0].$query_where[1].$query_where[2].$query_where[3])
>      or die("Query failed");
> 
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> // Loop through result of point query and:
> //   1) create pointObj's to hold results of mySQL query
> //   2) create lineObj's made of pointObj's values - use these for shapeObj's
> //   3) create shape objects to hold additional fields, specifically siteid
> //   4) draw the point and shape object on the map and layer
> //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> 
> $factor = 0.5;
> 
> while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
> 
>                  // create point objects
>             $pt = ms_newPointObj();
>                  $pt->setXY( $line["longitude"], $line["latitude"] );
> 
>             // create line objects
>                  $ln[0] = ms_newLineObj();
>                  $ln[1] = ms_newLineObj();
>                  $ln[2] = ms_newLineObj();
>                  $ln[3] = ms_newLineObj();
> 
>                  $ln[0]->addXY( ($pt->x - $factor), ($pt->y - $factor) );
>                  $ln[0]->addXY( ($pt->x + $factor), ($pt->y - $factor) );
>                  $ln[1]->addXY( ($pt->x + $factor), ($pt->y - $factor) );
>                  $ln[1]->addXY( ($pt->x + $factor), ($pt->y + $factor) );
>                  $ln[2]->addXY( ($pt->x + $factor), ($pt->y + $factor) );
>                  $ln[2]->addXY( ($pt->x - $factor), ($pt->y + $factor) );
>                  $ln[3]->addXY( ($pt->x - $factor), ($pt->y + $factor) );
>                  $ln[3]->addXY( ($pt->x - $factor), ($pt->y - $factor) );
> 
>             // create shape objects
>                  $shp = ms_newShapeObj(MS_SHAPE_POLYGON);
>                  $shp->add( $ln[0] );
>                  $shp->add( $ln[1] );
>                  $shp->add( $ln[2] );
>                  $shp->add( $ln[3] );
>                  $shp->set('text', $line['siteid']);
> 
>             // draw objects on layers
>                  $shp->draw($map, $shape_layer, $image, 0, "SHAEP");
>                  $pt->draw($map, $pt_layer, $image, 0, "TEST");
> 
> }
> 
> // Closing connection
> mysql_close($link);



More information about the mapserver-users mailing list