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

Dan Barron dbarron at ddive.com
Fri Mar 1 14:58:43 PST 2002


 >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