[Mapserver-users] PHP: was dynamic point drawn?

Eric Bridger eric at gomoos.org
Fri Jun 18 20:39:01 EDT 2004


At 03:58 PM 06/18/2004 -0700, Hal Mueller wrote:
>I'm generating a set of dynamic points from a mySQL database, based on attributes of the points.  Then I plot that set of points.
>
>If I'm plotting on a regional map, I'd like to know which of the (worldwide) points were actually drawn.  Is there a function to do that?   Something like
>
>$map->testInExtent($layer, $point)
>
>To be more specific, my question in the code is "which of these moving objects are in the map that I just drew?".
>
>I could look at the extent of the map manually, project the point, and test that--but it seems like there must be a canned way to do this already.

Not really a "canned" way but a brute force way. (Mapserver will take care of projection stuff for you)

I have done something similiar by using the $shape->contains($point) method. I did this with polygon shapes not rectangles but it should work the same.
1) create a shape by  from you $map current extent:  $rect = $map->{extent}
2) Create a shape from that $rect, Perhaps with $shape->{bounds} = $rect;  Or create the proper lines and use $shape->add($line). (This is what I did). see create_rect() perl code below.
3) loop thru your points and call $shape->contains($shape).
foreach my $point ( @points) {
            # Does the shape contain the point?
            my $ret = $shape->contains($point);
            if($ret == 1){ # yes
                push @points_found, $point;
}
=======================
This perl routine creates 10minute squares based on a passed in centroid.
sub create_rect{
    my($lat, $lon) = @_;
    my $point = new mapscript::pointObj();
    my $line = new mapscript::lineObj();
    # max xy point
    $point->{x} = $lon + .0833;
    $point->{y} = $lat + .0833;
    $line->add($point);
    # max x min y
    $point->{x} = $lon + .0833;
    $point->{y} = $lat - .0833;
    $line->add($point);
    # min xy
    $point->{x} = $lon - .0833;
    $point->{y} = $lat - .0833;
    $line->add($point);
    # min x max y
    $point->{x} = $lon - .0833;
    $point->{y} = $lat + .0833;
    $line->add($point);

    # max xy point again to close polygon
    $point->{x} = $lon + .0833;
    $point->{y} = $lat + .0833;
    $line->add($point);

    my $shp = new mapscript::shapeObj($mapscript::MS_SHAPE_POLYGON);
    $shp->add($line);
    $shp->setBounds();

    return $shp;
}

Eric Bridger










More information about the mapserver-users mailing list