Java question, but GIS related

Java question, but GIS related

Post by Paul Coope » Wed, 05 May 2004 02:10:26


Dear All,

This is a little OT, but I think people here are more likely to have
come across the problem!

I am writing a Java application to display map data. It is very
simple, written using 2D graphics, and I use the AffineTransform
object to translate the Graphics2D from world space to screen space.
This works fine except that I cannot find a way of plotting a constant
sized marker! Java doesn't have a "marker" type of graphical object -
only Shapes and Text. Now, at present I simply draw a constant sized
circle - but the size is constant in World space, not screen space. I
can't think of a way of having an object whose position is subject to
the AffineTransform but whose size is always in pixels. Can anyone
suggest a way of creating this cartographically obvious object? I am
using Java 2 version 1.4 something - the latest version, anyway.

Any ideas?

Thanks

Paul
 
 
 

Java question, but GIS related

Post by simon_chen » Wed, 05 May 2004 15:58:38

Paul,


I do exactly this in my Java-based project 'Mapyrus' (freely available from
http://www.yqcomputer.com/ ).

To achieve constant size markers I do not apply an AffineTransform
to my Graphics2D object. I use an AffineTransform independently
to transform the map data to pixel coordinates. Then I use pass the
pixel coordinate values I have calculated to Graphics2D drawLine()
and fillPolygon() methods.

Simon.

 
 
 

Java question, but GIS related

Post by Paul Coope » Wed, 05 May 2004 17:49:03


Thanks, Simon. Unfortunately the way I have done it is pretty deeply
embedded in my code, and re-writing it this way may be too hard. I did
it that way because I suspected it would be more efficient that way -
any opinion? I should say that this is a display sub-system for what
is primarily a database browsing tool, so the object model is based
around the database contents, which only incidentally extend the
relevant graphics types.

Why did Sun not appreciate that being able to render a point as a
marker was vital for some applications? It is all very well saying
that a Point is infinitesimally small and therefore cannot be rendered
- yes, mathematically correct, but very unhelpful for real world
applications!

Thanks again.

Paul
 
 
 

Java question, but GIS related

Post by simon_chen » Thu, 06 May 2004 20:25:21


A workaround may be to draw your fixed size marker symbols to a BufferedImage
and then use Graphics2D.drawImage() to blat the image containing the
correctly sized symbols into your map image.

Or, if you can use characters from a font as symbols then you may be
able to set a font with appropriate size and Graphics2D.drawString()
to draw each symbol with the correct size.

Simon.
 
 
 

Java question, but GIS related

Post by Paul Coope » Thu, 06 May 2004 21:16:02


Thanks, Simon - all good ideas! I'll have another go at it.

Paul
 
 
 

Java question, but GIS related

Post by Paul Coope » Wed, 12 May 2004 04:46:41


 
 
 

Java question, but GIS related

Post by Paul Coope » Wed, 12 May 2004 04:49:32


Dear Simon,

I have managed what I wanted to do, by getting the current
affineTransform XScale (= YScale for mapping!) and then changing the
size of the symbol to make it a fixed width. Thanks for all your
ideas, which contributed to the way I eventually did it.

Paul