Re: [OpenMap Users] How to implement a particular graphic overlay?

From: Don Dietrick <dfdietrick_at_gmail.com>
Date: Sat, 28 Mar 2015 13:25:30 -0400

Hi Gary,

Great question, I had to think about this for a bit. I think you can get the effect you want, but you’ll have to do it in pieces. The idea is this: create an image where you are assuming the pixels represent an equidistance area, draw into the image directly using the java.awt.Graphics object for that image. Define a GeoCoordTransform that describes the location of the image pixels. Give the image and the GeoCoordTransform to an OMWarpingImage, and that will handle moving the image around on the map.

1. First off, you need to figure out a which UTM zone you’re in for the data space, if you know you’re lat/lon you can use the UTMPoint for that. You also need to figure out the pixel height and width for this image that gives you the resolution you need for your data, and tied into figuring that out is a meter/pixel factor. So you decide what your meter/pixel should be (relative to your data spacing), and then how big an image you need.

GeoCoordTransformation transform = new UTMGCT(new UTMPoint(centerLL));
Point2D utmCenter = transform.forward(centerLL.getY(), centerLL.getX());
double pixelSize = 1000; // whatever you decide, meters/pixel

double sourceImageWidth = 1000; // whatever you need, this value will make image 1000000 meters wide
double sourceImageHeight = 1000; // whatever you need, this value will make image 1000000 meters tall
double halfImageWidthMeters = sourceImageWidth / 2;
double halfImageHeightMeters = sourceImageHeight / 2;

DataBounds sourceImageBounds = new DataBounds();
sourceImageBounds.add(utmCenter.getX() + halfImageWidthMeters, utmCenter.getY() + halfImageHeightMeters);
sourceImageBounds.add(utmCenter.getX() + halfImageWidthMeters, utmCenter.getY() - halfImageHeightMeters);
sourceImageBounds.add(utmCenter.getX() - halfImageWidthMeters, utmCenter.getY() - halfImageHeightMeters);
sourceImageBounds.add(utmCenter.getX() - halfImageWidthMeters, utmCenter.getY() + halfImageHeightMeters);

2. Once you have your UTMGCT defined, you should create a BufferedImage that is the same size:

BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB)

3. Then, get the graphics object from it:

java.awt.Graphics2D g2 = (Graphics2D) bi.getGraphics();

4. Once you have that, use the methods on the g2 object to render. These methods are based on a coordinate system of 0,0 at the upper left of the image. So, you’re going to have to translate your data to match that coordinate system.

renderX = (utmCenter.getX() - dataX)/pixelSize;
renderY = (utmCenter.getY() - dataY)/pixelSize;

// Make similar adjustments for circle width/height

If you use transparent colors and circles of bigger radius, you should get the blending effect in the image.

5. Once you have that, you create an OMWarpingImage:

OMWarpingImage omwi = OMWarpingImage(bi, transform, sourceDataBounds);

Add it to an OMGraphicList on a layer.

CHECK THE MATH! I just kinda wrote this off the top of my head, but it’s the basic idea.

Hope this helps,

Don




> On Mar 28, 2015, at 12:19 PM, Gary Briggs <chunky_at_icculus.org> wrote:
>
> Yeah, that's almost exactly what I want my code to do.
>
> I see you note that you don't plan to release source. Can you at
> least give an overview of how you implemented it? Did you use a lot of
> OMPolys? Did you implement some new OMGraphic?
>
> Thanks,
> Gary
>
> On Sat, Mar 28, 2015 at 08:08:25AM +0100, "Carsten Ø. Madsen" wrote:
>> Hello
>>
>> Maybe this GRIB rendering can inspire
>>
>> http://carsten-oland.blogspot.dk/2010/10/prelimiary-grib-rendering-for-openmap.html
>>
>> Looking at the zygrib code helped a lot.
>>
>> BR
>> Carsten
>>
>>
>> On 03/27/2015 06:41 PM, Gary Briggs wrote:
>>> Morning,
>>>
>>> I have some input data. It's in the form of a regular-ish grid, where
>>> points are spaced mostly equally in distance instead of angle. The grid
>>> is defined by a large number of points [say, 50-500 along each side,
>>> covering 30-50 degrees of globe].
>>> Each point has a number associated with it [that I then use to pick
>>> a color for it]
>>>
>>> Currently I create an OMGraphicList and stuff a load of OMPoints into
>>> it, coloring each one according to the associated number [the color is
>>> partially transparent, also]. That works to some degree, but what
>>> I *really* want is an overlay that isn't a series of points, but a
>>> continuous/smooth thing.
>>>
>>> I looked at using OMGrid, but it looks like that assumes a grid that's
>>> regular in angle? Similarly, I think that OMScalingRaster looks *close*
>>> to what I want, but I can't figure out how to use it the way I desire.
>>>
>>> What's a guy to do?
>>>
>>> Cheers!
>>> Gary
>>>
>>> --
>>> [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"]
>
> --
>
> --
> [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 Sat Mar 28 2015 - 13:26:48 EDT

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