Re: [OpenMap Users] check if a point is inside the terrain

From: Don Dietrick <dfdietrick_at_gmail.com>
Date: Wed, 29 Sep 2010 11:10:02 -0400

Hi Luca,

The contains(x,y) method on an OMGraphic (EsriGraphic) is used to tell
if a pixel location (from a MouseEvent, for example) lies within the
projected location of the OMGraphic. The OMGraphic being read from
the ShpInputStream isn't projected yet, it's just defined as a set of
coordinates, so there is no shape that can be retrieved from it. The
java.awt.Shape object you get from an OMGraphic is what gets drawn on
the map, after the OMGraphic has been 'generated' from the current
projection.

There are two ways to fix your problem.

1. You can create a Projection object (say
com.bbn.openmap.proj.Mercator) to use. The smaller scale you choose
for this projection, the more detail will be considered for the
contains test. I'd start with a scale of 10000000 to start to see how
that works for you. Before you ask the EsriGraphic for it's shape
objects, call generate(projection).

If you want to test for different lat/lon, use the
projection.forward(lat, lon) method to get a Point2D object that is at
that pixel location for the projection for the given lat/lon.

So, this would be kind of slow, but would work OK for a one-shot test.
 You can also use the EsriGraphicList class to read and hold the
OMGraphics from a shape file (getEsriGraphicList()), give your
projection to it with the generate() method, and then call
findClosest(x, y, distance), with distance being zero. That would
return any OMGraphic that contains that point.

2. The other way to do this, without projections, is to use the
com.bbn.openmap.geo package. You would create GeoExtents from the
shape coordinates read from the shape file, and then use the
Intersection class to test for lat/lon points. This package works in
lat/lon space, so nothing needs to be projected for this analysis.

Hope this helps,

Don


On Sun, Sep 26, 2010 at 10:41 AM, Pierluca Sangiorgi
<pierluca.sangiorgi_at_gmail.com> wrote:
> Hi, i need to determine if a point(lat/long) is inside the terrain or
> not (in the sea).
> I used the "vmap_area.shp" file as map file and reading the API doc i
> think i must do something like this:
>
>       Point2D pointToCheck = new Point2D.Double(0,0);
>       try {
>           ShpInputStream shpStream = new ShpInputStream(
>                   new FileInputStream("data/shape/vmap_area.shp"));
>           EsriGraphicList list = shpStream.getGeometry();
>           Iterator i = list.iterator();
>           while (i.hasNext()) {
>               EsriPolygon p = (EsriPolygon) i.next();
>               GeneralPath path = p.getShape();
>               path.contains(pointToCheck);
>           }
>       } catch (Exception e) {
>           System.out.println(e.getMessage());
>       }
>
> but it doesn't work.
> Could anyone help me?
>
> Thanks in advance and best regards
> Luca
>
> --
> [To unsubscribe to this list send an email to "majdart_at_bbn.com"
> with the following text in the BODY of the message "unsubscribe openmap-users"]
>

--
[To unsubscribe to this list send an email to "majdart_at_bbn.com"
with the following text in the BODY of the message "unsubscribe openmap-users"]
Received on Wed Sep 29 2010 - 11:12:01 EDT

This archive was generated by hypermail 2.3.0 : Tue Mar 28 2017 - 23:25:09 EDT