Re: [OpenMap Users] Is OpenMap the right tool for my project?

From: Don Dietrick <dietrick_at_bbn.com>
Date: Tue, 22 May 2007 13:52:45 -0400

Hi Redd,

On May 18, 2007, at 3:15 PM, Redd Murphy wrote:

>
> Hi,
>
> I have a database that stores geographical areas as a set of lat/lon
> coordinates. I am trying to write a servlet that will create
> polygons out
> of the database records so that I can use a contains() method to
> see if
> passed-in coordinates fall within the defined areas. The reason I
> turned to
> Openmap with this problem is because I assumed that it can handle
> polygons
> that span the dateline. Is that a good assumption?

Yes, OMGraphics can handle the dateline.

>
> I have gone as far as creating OMPoly objects out of my lat/lon
> sets, and
> have tried something like this:
>
> ...
> Point2D.Float pt = new Point2D.Float(lat,lon);
> OMPoly omp = this.getPolygon();
> Shape s = omp.getShape();
> return s.contains(pt);
>
> I end up getting a null pointer exception, and based on another
> thread I'm
> guessing that it's because my polygon hasn't been projected. I
> don't have
> the first clue about how projection works, and since I have no gui
> I wonder
> if I am even going down the right path.

The Projection object translates decimal degree coordinates to screen
coordinates, and vice-versa. I'm not sure you are working within a
layer, or if need to know how to get the Projection from within a
Layer, but you can create your own Projection object to use for the
calculation. It doesn't really matter what values you choose, but
scale values will have an effect on accuracy since the contains()
calculation will be performed on the projected, pixel space (albeit
virtual pixel space in this case).

Mercator merc = new Mercator(new LatLonPoint(0f, 0f), 100000000f,
600, 600);

then, at some point call omp.generate(merc). You only have to call
generate after its location is set, or reset, or if your projection
changes.

Also, you have to handle your query point as well:

Point loc = merc.forward(pt);
return s.contains(loc);

where loc is the projected lat/lon point. If you are calling this
method in a loop, you can save memory by providing an allocated Point
object to the merc.forward(pt, loc), so that loc Point gets reset
with the coordinates of the next location. Saves memory and speeds
things up for a loop.

Hope this helps,

Don


=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Don Dietrick, dietrick_at_bbn.com
BBN Technologies, Cambridge, MA
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


--
[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 Tue May 22 2007 - 13:53:07 EDT

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