Skip to content

Using a WMS with other CRS/SRS (other then WGS84 EPSG:4326): #95

@Ulathar

Description

@Ulathar

Hello,

thanks for this great library. I was able to successfully use different OSM TileFactorys as well as placing Waypoints over the Map at the correct places (using the JXMapViewer).
I also was able to use other public (not OSM based) WMS that are using WGS84 with the same Code as well (just had to add a different TileFactoryInfo for that).

But now I am confronted with a WMS that is not capable of WGS84 and thus forcing me to use EPSG:4647 (UTM32N) for ... reasons ... and I struggle to get this working with JXMapViewer. I tried to implement another TileFactoryInfo Class based on the examples in the library but obviously just giving another crs/srs (depending on WMS spec) is not enough.

I have three main problems right now:

  1. the calculations of the tiles to request (URLs) is wrong (obviously because the WGS84 transformation between display coordinate and real world coordinate is different to UTM)
  2. same applys to Waypoint Overlays which are placed wrong in the JXMapViewer because of the same reasons (Waypoint Coodinates are UTM32N, too and i guess the transformation to display coordinates is based on WGS84 as well?)
  3. i noticed that the requested tiles (no matter if wrong or right) are stored in a strange cache structure like:
    .../.tile_cache/<url_of_wms>/<wms_name>/WMS/<long_list_of_url_parameters>/<very_long_file_name_with_even_more_url_parameters> without .png ending (this could be because of to long windows file paths) instead of the expected structure:
    .../.tile_cache/tile.openstreetmap.org/0/0/0.png, etc.

Is there any example on how to do this kind of things right that I can look at?

Already though about including GeoTools in order to transform the UTM coordinates to WGS84 on the fly before giving them to the JXMapViewer but that would bloat up the program quite a lot (in size). Is this really necessary or is there a better way?

Here is a snipped from my current Test TileFactoryInfo that is obviously still based upon WGS84 transformations:

// Testing...
@Override
public String getTileUrl(int x, int y, int zoom) {
    int tileSize = getTileSize(zoom);
    zoom = getTotalMapZoom() - zoom;
    int z = (int) Math.pow(2, (double) zoom - 1);

    int m = x - z;
    int n = z - 1 - y;
    
    int tilesPerDimension = (int) Math.pow(2, zoom);

    double radius = (tileSize * tilesPerDimension) / (2 * Math.PI);
    double xmin = MercatorUtils.xToLong(m * tileSize, radius);
    double ymin = MercatorUtils.yToLat(n * tileSize, radius);
    double xmax = MercatorUtils.xToLong((m + 1) * tileSize, radius);
    double ymax = MercatorUtils.yToLat((n + 1) * tileSize, radius);

    if (xmax < xmin) {
        xmax = -xmax;
    }

    String bbox =  "";

    if (flippedAxis && version.equals("1.3.0")) {
        bbox = ymin + "," + xmin + "," + ymax + "," + xmax;
    } else {
        bbox = xmin + "," + ymin + "," + xmax + "," + ymax;
    }

    String url = getBaseURL()
        + "?SERVICE=WMS"
	+ "&VERSION=" + version
	+ "&REQUEST=GetMap"
	+ "&LAYERS=" + this.getLayers()
	+ "&FORMAT=" + this.getTileFormat()
	+ "&BBOX=" + bbox
	+ "&WIDTH=" + tileSize
	+ "&HEIGHT=" + tileSize
	+ (version.equals("1.3.0") ? "&CRS=" + this.getSrs() : "&SRS=" + this.getSrs())
	+ "&STYLES=" + this.getStyles()
	+ (this.getTileBgColor() == null ? "" : "&BGCOLOR=" + this.getTileBgColor())
	+ (this.getTransparent() == null ? "" : "&TRANSPARENT=" + this.getTileBgColor())
	+ (customParameters == null ? "" : customParameters);

	return url;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions