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

From: Don Dietrick <dfdietrick_at_gmail.com>
Date: Mon, 4 Oct 2010 19:42:17 -0400

Hi Luca,

You can't cast to GeoExtents, you have to get the coordinates from
them and construct GeoExtent objects. For instance, you call
OMPoly.getLatLonArray() to get double[] of lat/lon for polygon, and
then you can create a GeoRegion.Impl(double[] latlons, boolean
isDegrees) object out of that. BTW, when you call getLatLonArray on
an OMPoly, they are in radians so isDegrees is false.

Check out the com.bbn.openmap.layer.test.GeoIntersectionLayer for an
example of using intersection. You can also see how it converts shape
file objects to GeoExtents.

Hope this helps,

Don

On Mon, Oct 4, 2010 at 8:22 AM, Pierluca Sangiorgi
<pierluca.sangiorgi_at_gmail.com> wrote:
> Hi Don,
> thanks for the answer.
> I think that the second solution is the most suitable for my scope,
> but i don't understand how to create the GeoExtents from the
> shapefile.
> I tried to cast the OMGraphic.getShape to various GeoExtents
> implementation with no result, could you explain me more in detail?
>
> BR
> Luca
>
>
> 2010/9/29 Don Dietrick <dfdietrick_at_gmail.com>:
>> 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 Mon Oct 04 2010 - 19:43:25 EDT

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