Skip to main content

Support for UTM in JXMapViewer

9 replies [Last post]
desibel
Offline
Joined: 2008-05-19

Hi,

I'm trying to use the JXMapViewer component with tilecache (tilecache.org). It's not an option using lat/long since my country would look like a flat banana :). So I'm calculating the bounds for the tiles in UTM using x, y and zoom by overriding the toWMSURL method in WMSService, this is where my problems begin.
I have a list with the resolutions of the zoomlevels created in tilecache, and I've mapped the resolutions to a zoomlevel in TileFactoryInfo. But i suspect that the zoomlevels in the mapviewer is calculated such that each zoomlevel contains four times the tile count than the previous zoomlevel and thereby keeping the coordinate system intact. However, the zoomlevels provided by tilecache are based on how many meters each pixel represent, so each time I zoom the coordinates gets barfed so when I try to get or set a GeoLocation from the JXMapViewer the location does'nt match the map.

I'm a bit lost as to what I can do to take advantage of the JXMapViewer component. It's perfect for my use, it has a small footprint and have exactly the features that I need, only problem is that I have to use UTM instead of lat/long.

Any help is appreciated! Thanks!.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joshua Marinacci

I found this Java code which will convert UTM to geocoords:

http://www.jstott.me.uk/jcoord/

You might be able to hook that up to do what you want.

I'm not sure I understand your problem. Are you having difficulties
getting the tilecache.org tiles to appear in the map viewer, or are
you having trouble getting your waypoints to show up at the right
location on screen?

- Josh

On May 22, 2008, at 10:04 AM, jdnc-interest@javadesktop.org wrote:

> Hi joshy
>
> UTM (Universal Transverse Mercator) is a projection of the earths
> surface against a cylinder where the equator touches the cylinder. A
> UTM-coordinate is a two-dimentional location descriptor equal to
> latitudes and longitudes, the only difference is that UTM uses the
> SI-system (Système International d'Unités) wich operates in meters
> instead of degrees, minutes and seconds.
>
> In UTM the surface of the earth is divided into a grid-system where
> the letters C through X (ignoring the letters L and O due to the
> simmilarity between 1 and l and 0 and O) represents the latitudes,
> and longitudes range from 1 to 60.
>
> My country lies in sone 32v to 35w, but in order to keep the
> calculations efficient the projection of the map is done using zone
> 33 (SRS=EPSG:32633). The maths needed to convert from UTM - lat/long
> is quite complex and I don't understand all of it, but if you look
> at the sourcecode for the conversion script here: http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html
> you can get a grasp of the complexity :). Also, if you check out
> PROJ4 you might find some docs on the conversion algorithm.
>
> I've tried to convert the lat/long coordinates into UTM in the
> toWMSURL method in the WMSService class but the tiles from tilecache
> did not match the coordinates. I'm not sure why this failed, I
> checked that the conversions was correct by using a reliable thrid-
> party software. But I think that this is a redundant step since the
> JXMapViewer should be able to do this for me :) There might be a
> quick fix to incorporate the UTM but I can't see it, you might since
> you wrote the code =)
>
> Thanks for taking an interest in my question!
> [Message sent by forum member 'desibel' (desibel)]
>
> http://forums.java.net/jive/thread.jspa?messageID=276064
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

desibel
Offline
Joined: 2008-05-19

Thanks a lot Joshua, it looks like Jcoord will do exactly what I need.

Sorry if I've been unclear as to what my problem is. It's not a problem to get and display the tiles from tilecache, it works like a charm :). But when i add a waypoint it's not even close to the geoposition I assigned it. When I change zoom level the point changes location, the GeoPosition object has not been changed, but it seems like the coordinate system on different zoom levels isn't synchronized with the map.

I think I know why, but I don't have a solution for it. :). My zoom levels increase differently in the amount of tiles. ie zoomlevel 9 has a 5x4 tiles, zoom level 8 has 17x14 tiles etc and they are eligable to change later on so I can't hardcode the zoomlevel calculations. So in order to calculate the waypoints position on the different zoomlevels I have to use the resolution for the current zoom level, somehow.. Not sure where to implement this logic, perhaps in geoToPixel and pixelToGeo anywhere else?

Thanks again.

desibel
Offline
Joined: 2008-05-19

Hmm.. I'm still having some trouble with the mapping from coordinates to pixel. does anyone know of a library somewhere that can take a bounding box and resolution + UTM coordinates and return the pixel XY?

In order to add waypoints in the correct pixel space I have to implement geoToPixel in my tilefactory, this method takes a GeoPosition and a zoomlevel as parameters.

My bounding box (the area that contains the entire map) is :
lower left(X,Y): -640000, 6278000,
upper right(X,Y): 1652500, 8152000

A Waypoints location(X,Y): 937100, 505800 (approximately center of map)
Current resolution : 1980

UTM coordinates are in meters, so by dividing a location by the resolution (meters pr pixel) I get a pixel coordinate. So In order to find the correct pixel I have to find how many meters it is from lowerleftX (llx) to locationX:

[code]
double metersFromEdgeOfMap = Math.abs(llx)+locationX;
pixelX = metersFromEdgeOfMap/resolution
[/code]

But the pixel coordinates doesn't match the map and when I change resolution(zoomlevel) the waypoint is in a different location, what am I missing here?

gumit
Offline
Joined: 2005-11-30

Hi desibel,

Did you found a solution for this problem? I am also having problems using openlayers tiles with jxmapviewer and positioning waypoints correctly on it.

Thanks....

Joshua Marinacci

Hi desibel. Can you explain to me what UTM is? Is this a different
projection scheme from cylindrical and mercator? Or is this a
different coordinate scheme? Do you have any docs on it or code to
convert from UTM to lat/long?

Thanks,
Josh

On May 21, 2008, at 5:41 AM, jdnc-interest@javadesktop.org wrote:

> Hi,
>
> I'm trying to use the JXMapViewer component with tilecache
> (tilecache.org). It's not an option using lat/long since my country
> would look like a flat banana :). So I'm calculating the bounds for
> the tiles in UTM using x, y and zoom by overriding the toWMSURL
> method in WMSService, this is where my problems begin.
> I have a list with the resolutions of the zoomlevels created in
> tilecache, and I've mapped the resolutions to a zoomlevel in
> TileFactoryInfo. But i suspect that the zoomlevels in the mapviewer
> is calculated such that each zoomlevel contains four times the tile
> count than the previous zoomlevel and thereby keeping the coordinate
> system intact. However, the zoomlevels provided by tilecache are
> based on how many meters each pixel represent, so each time I zoom
> the coordinates gets barfed so when I try to get or set a
> GeoLocation from the JXMapViewer the location does'nt match the map.
>
> I'm a bit lost as to what I can do to take advantage of the
> JXMapViewer component. It's perfect for my use, it has a small
> footprint and have exactly the features that I need, only problem is
> that I have to use UTM instead of lat/long.
>
> Any help is appreciated! Thanks!.
> [Message sent by forum member 'desibel' (desibel)]
>
> http://forums.java.net/jive/thread.jspa?messageID=275710
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

desibel
Offline
Joined: 2008-05-19

Hi joshy

UTM (Universal Transverse Mercator) is a projection of the earths surface against a cylinder where the equator touches the cylinder. A UTM-coordinate is a two-dimentional location descriptor equal to latitudes and longitudes, the only difference is that UTM uses the SI-system (Système International d'Unités) wich operates in meters instead of degrees, minutes and seconds.

In UTM the surface of the earth is divided into a grid-system where the letters C through X (ignoring the letters L and O due to the simmilarity between 1 and l and 0 and O) represents the latitudes, and longitudes range from 1 to 60.

My country lies in sone 32v to 35w, but in order to keep the calculations efficient the projection of the map is done using zone 33 (SRS=EPSG:32633). The maths needed to convert from UTM - lat/long is quite complex and I don't understand all of it, but if you look at the sourcecode for the conversion script here: http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html you can get a grasp of the complexity :). Also, if you check out PROJ4 you might find some docs on the conversion algorithm.

I've tried to convert the lat/long coordinates into UTM in the toWMSURL method in the WMSService class but the tiles from tilecache did not match the coordinates. I'm not sure why this failed, I checked that the conversions was correct by using a reliable thrid-party software. But I think that this is a redundant step since the JXMapViewer should be able to do this for me :) There might be a quick fix to incorporate the UTM but I can't see it, you might since you wrote the code =)

One more thing: In order to get an efficient tilecache I have to cache all the images from the WMS server on the servers hard drive so when I perform a WMS request to the tilecache the server returns the generated image instead of having to create the image. In order to calculate the bounds of the cached images I have to base my calculations on the lower left corner of the entire map and by using the cached resolution of the tiles (resolution=meters pr pixel in the current zoomlevel)

Heres the math:

lower left (llx,lly) = -640841.1776,6278226.2107
predefined resolutions[] = 1984.3739, (entire country)
529.1663,
132.2915,
26.4583,
5.2916,
1.3229 (smallest piece)

//create a boundingbox
double res = resolutions[zoom];
minx = llx + (res * tilex * tilesize)
miny = lly + (res * tiley * tilesize)
maxx = llx + (res * (tilex + 1) * tilesize)
maxy = lly + (res * (tiley + 1) * tilesize)

This code is now in my TileCacheWMSService class and works great (at least it paints the entire map in every zoom level :P) , but if I add a WayPoint the location of the waypoint on the map is incorrect, and when I change the zoom level the center of the map has moved. This doesn't happen when I use lat/long so the coordinate system and the map is not synchronized in my current configuration. Do you have a clue as to what I'm doing wrong here?

Thanks for taking an interest in my question!

Message was edited by: desibel

Joshua Marinacci

Well, this sounds more like the bluemarble projection we get from
NASA. There is a blue marble tile factory implementation in SwingX-WS
in addition to the WMS one.

- Josh

On May 22, 2008, at 10:04 AM, jdnc-interest@javadesktop.org wrote:

> Hi joshy
>
> UTM (Universal Transverse Mercator) is a projection of the earths
> surface against a cylinder where the equator touches the cylinder. A
> UTM-coordinate is a two-dimentional location descriptor equal to
> latitudes and longitudes, the only difference is that UTM uses the
> SI-system (Système International d'Unités) wich operates in meters
> instead of degrees, minutes and seconds.
>
> In UTM the surface of the earth is divided into a grid-system where
> the letters C through X (ignoring the letters L and O due to the
> simmilarity between 1 and l and 0 and O) represents the latitudes,
> and longitudes range from 1 to 60.
>
> My country lies in sone 32v to 35w, but in order to keep the
> calculations efficient the projection of the map is done using zone
> 33 (SRS=EPSG:32633). The maths needed to convert from UTM - lat/long
> is quite complex and I don't understand all of it, but if you look
> at the sourcecode for the conversion script here: http://home.hiwaay.net/~taylorc/toolbox/geography/geoutm.html
> you can get a grasp of the complexity :). Also, if you check out
> PROJ4 you might find some docs on the conversion algorithm.
>
> I've tried to convert the lat/long coordinates into UTM in the
> toWMSURL method in the WMSService class but the tiles from tilecache
> did not match the coordinates. I'm not sure why this failed, I
> checked that the conversions was correct by using a reliable thrid-
> party software. But I think that this is a redundant step since the
> JXMapViewer should be able to do this for me :) There might be a
> quick fix to incorporate the UTM but I can't see it, you might since
> you wrote the code =)
>
> Thanks for taking an interest in my question!
> [Message sent by forum member 'desibel' (desibel)]
>
> http://forums.java.net/jive/thread.jspa?messageID=276064
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
> For additional commands, e-mail: jdnc-help@jdnc.dev.java.net
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jdnc-unsubscribe@jdnc.dev.java.net
For additional commands, e-mail: jdnc-help@jdnc.dev.java.net

desibel
Offline
Joined: 2008-05-19

Perhaps it would help if I subclassed TileFactoryInfo and took the resolution array (wich contains information about meters pr pixel) as parameters and then calculate mapWidthInTilesAtZoom, mapCenterInPixelsAtZoom, longitudeDegreeWidthInPixels and longitudeRadianWidthInPixels based on the resolution for each zoomlevel?. As far as I can see the only references to lat/long is in TileFactoryInfo and MercatorUtils, I think I might be on to something here :). Feel free to jump in..

dsreddy
Offline
Joined: 2012-04-27

Hi Joshy,

I have downloaded bunch of tiles and displayed a map with JXMapViewer. But I'm faching issues in displaying waypoints on the map. First of all , is it possible to show up waypoints on local tiles? or Is this possible to display waypoints only on single image where I can convert lat/long to x/y coordinates.