Steve,
This is a huge help. The only thing I had not figured out was the
'toleranceunits' and 'tolerance' fields. I appreciate your help!
I intend to add many, possible hundreds, lines to a layer. Then query
it with a given reference point. How do I get the number of results and
then loop through each one?
Best Regards,
Mark
Steve Lime wrote:
How do I query a layer with one or more line features to find all
features with X miles of a given point?
Your line layer should like so:
LAYER
NAME 'lines'
TYPE LINE
...other junk...
TEMPLATE 'dummy' # to be queryable
TOLERANCEUNITS MILES
TOLERANCE X
END
Then in mapscript you'd do a
$my_layer->queryByPoint($my_point, MS_MULTIPLE, -1);
The buffer parameter is used to override a layer tolerance so setting to -1
tells
the method to ignore it. If you do use it then it's given in the units of the
layer
being searched (before any projection).
Does that help?
Steve
Mark Brooks <[email protected]> 07/24/09 3:26 PM >>>
I'm trying to create several new line objects and then find the lines
that are within x miles of a given point. (i.e., how far away a given
point is from the track of a hurricane or the path of a ship). I'm
having some difficulties and I hope someone can help.
How do I query a layer with one or more line features to find all
features with X miles of a given point?
Here is how I'm approaching the problem in PHP:
// Test array of points. This is used to make a line.
$points[0]['lat'] = 35.5;
$points[0]['lon'] = -78.8;
$points[1]['lat'] = 36.5;
$points[1]['lon'] = -79.8;
$points[2]['lat'] = 37.5;
$points[2]['lon'] = -80.1;
// make new map object.
$map = ms_newMapObj('mapdata/mymap.map');
// Create new line
$my_line = ms_newLineObj();
// Loop through points, and add to the line
while (list(,$coordinate)=each($points)){
// Create new point object
$my_point = ms_newpointObj();
$my_point->setXY($coordinate['lon'],$coordinate['lat']);
// Add point to line object
$my_line->add($my_point);
}
// Now create a new shape
$my_shape = ms_newShapeObj(MS_SHAPE_LINE);
$my_shape->add($my_line);
// create new layer
$my_layer = ms_newLayerObj($map);
// set some fields for this new layer
//$my_layer->set("units","miles"); // does not seem to work as expected
// Create new class and add TEMPLATE. This is required for queries on
the layer to work?
$my_class = ms_newClassObj($my_layer);
$my_class->set("template",'/home/www/html/query_template.html');
// Add feature to the layer
$my_layer->addFeature($my_shape);
// Draw map. Query doesn't work if I don't do this now.
$map->draw();
// Make a new point object that will be our ref point
// to check how far away the line is from this point.
$my_point = ms_newpointObj();
$my_point->setXY(-82,36); // lon, lat
// Run a point query on the line object layer; layer must have a class
with a LAYER TEMPLATE value
// The third argument is the buffer tolerance. Default unit is pixels?
Must figure out how to make miles or km.
if ($my_layer->queryByPoint($my_point,MS_SINGLE,1)==MS_SUCCESS){
$my_result = $my_layer->getResult(0); // Get the result
$my_layer =
$my_layer->getShape($my_result->tileindex,$my_result->shapeindex); //
Get the shape
}
_______________________________________________
mapserver-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapserver-users
--
Mark Brooks
State Climate Office of North Carolina
Box 7236, NC State University
Raleigh, NC 27695-7236
Phone: 919.515.1446
Fax: 919.515.1441
_______________________________________________
mapserver-users mailing list
[email protected]
http://lists.osgeo.org/mailman/listinfo/mapserver-users