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

E Perik erwin at perik.nu
Sun Mar 3 05:14:47 PST 2002


Hi Dan,

Could you not create a new-shapefile of your points and then add this
'name' in the Map-layer. Then add the new-shapefile to the map through a
dummy-layer.

I used similar to retrieve a shape-object from an existing shapefile and
then:

1) Get shapeobject from existing-shapefile (through its index)
2) Put it in new-shapefile
3) Create dbf-file with name of new-shapefile
4) Clear new-shapefile
5) Add new-layer to map-object (default of this layer is set to OFF)
6) Show new-layer
7) Draw the map (now includes newly created shapefile ;-) )

In part 1) yours would differ. Her you create the shape-object (points)
from the SQL-database. Part 3) is needed, because mapscript does not
make a dbf-file.


Erwin


-----Original Message-----
From: owner-mapserver-users at lists.gis.umn.edu
[mailto:owner-mapserver-users at lists.gis.umn.edu] On Behalf Of Dan Barron
Sent: Friday, March 01, 2002 11:59 PM
To: Stephen Woodbridge
Cc: mapserver-users at lists.gis.umn.edu
Subject: Re: [mapserver-users] Create Dynamic Pt Layer, then
queryByPoint()

 >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