Extracting data froma a shp

Lowell Filak lfilak at MEDINACO.ORG
Wed Sep 15 09:01:27 EDT 2004


The following message was sent by Thomas Shaw <thomas at REDMILENIO.COM> on
Tue, 14 Sep 2004 16:29:30 -0400.

> Hello, I hope that you can help me with this:
>
> Actually I have mapserver and I'm creating a map with 2 layers, and I'm
> generating another layer with mapscript. That layer is generated by
> reading a data base that has latitude and longitud fields. So I read a
> position (lat,lon) and generate the layer. Until here I have no problem,
> the generated layer is appearing correctly in the map as a 3rd layer, but
> the thing I'm trying to do is to extract from the shape file that is in
> the other 2 layers, information that can help me to know how far is the
> new point in the generated layer from the nearest information point in the
> shp that is in the other 2 layers. I'm using this map for car
> localization, so, in some way I have to make an information table with the
> telling where the unit is referencing it with the other 2 layers in the
> map. Is some solution for my problem?
>
> Greetings
>
> Thank you
> -----------
> Thomas Shaw

Thomas;

I'm a little unclear on the details.
What you have in the 3rd layer is a point but I'm not sure what is in
the first two layers.
If they are polygons you could use "layer->queryByPoint( mapObj map,
pointObj point, int mode, double buffer )" with no buffer or
"shape->contains( pointObj point )" to see if the point is within the
polygon. I'm not current on how the "shape->distanceToPoint( pointObj
point )" works for polygon shapes and you may want to view the source
code before assuming it works the way you anticipate.
If they are lines then you can use "layer->queryByPoint( mapObj map,
pointObj point, int mode, double buffer )" with incrementally larger
buffers to detect the closest line. Or an alternative method available
if your line data contains correct polygon topology you can query the
polygons for the one in which the point resides and then loop through
each of the lines that compose the polygon and calculate the distance
between each of the points that compose each of the lines and use the
shortest distance as the nearest line. Be aware that
"shape->distanceToPoint( pointObj point )" will extend the ends of a
line shape to find the shortest distance from a line to a point and that
is probably not what you need.
If they are points then you can use layer->queryByPoint( mapObj map,
pointObj point, int mode, double buffer )" with incrementally larger
buffers to detect the closest point.
Once the query is done and you have the resultcache you can pull
attributes based on the shape index of the resultcachemember.

My $0.02

Lowell



More information about the mapserver-users mailing list