Changeset 8584 in josm for trunk/src/org/openstreetmap/josm


Ignore:
Timestamp:
2015-07-08T20:59:09+02:00 (9 years ago)
Author:
wiktorn
Message:
  • added axis definition to ESPG projections definition, where it's not default (i.e. North/East)
  • added switchXY boolean in Projection interface
  • WMTS and WMS (1.3.0) uses now switchXY when doing requests against servers
  • better error reporting when there are problems with parsing the WMTS TileSource

Addresses: #10623

Now http://webgis.linz.at/WMTS/1.0.0/getCapabilities.xml should work.

Wallonie services still being debugged.

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java

    r8540 r8584  
    139139        if (baseUrl.toLowerCase().contains("crs=epsg:4326")) {
    140140            switchLatLon = true;
    141         } else if (baseUrl.toLowerCase().contains("crs=") && "EPSG:4326".equals(myProjCode)) {
    142             switchLatLon = true;
     141        } else if (baseUrl.toLowerCase().contains("crs=")) {
     142            // assume WMS 1.3.0
     143            switchLatLon = Main.getProjection().switchXY();
    143144        }
    144145        String bbox;
  • trunk/src/org/openstreetmap/josm/data/imagery/WMTSTileSource.java

    r8571 r8584  
    4747import org.openstreetmap.josm.data.coor.LatLon;
    4848import org.openstreetmap.josm.data.projection.Projection;
     49import org.openstreetmap.josm.data.projection.Projections;
    4950import org.openstreetmap.josm.gui.ExtendedDialog;
    5051import org.openstreetmap.josm.io.CachedFile;
     
    6667    private static final String PATTERN_HEADER  = "\\{header\\(([^,]+),([^}]+)\\)\\}";
    6768
    68     private static final String URL_GET_ENCODING_PARAMS = "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER={layer}&STYLE={style}&"
     69    private static final String URL_GET_ENCODING_PARAMS = "SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER={layer}&STYLE={Style}&"
    6970            + "FORMAT={format}&tileMatrixSet={TileMatrixSet}&tileMatrix={TileMatrix}&tileRow={TileRow}&tileCol={TileCol}";
    7071
     
    229230
    230231        } catch (Exception e) {
    231             Main.error(e);
    232         }
    233         return null;
     232            throw new IllegalArgumentException(e);
     233        }
    234234    }
    235235
     
    268268            matrixSet.crs = crsToCode(getStringByXpath(matrixSetNode, "SupportedCRS"));
    269269            NodeList tileMatrixList = getByXpath(matrixSetNode, "TileMatrix");
     270            Projection matrixProj = Projections.getProjectionByCode(matrixSet.crs);
     271            if (matrixProj == null) {
     272                // use current projection if none found. Maybe user is using custom string
     273                matrixProj = Main.getProjection();
     274            }
    270275            for (int matrixId = 0; matrixId < tileMatrixList.getLength(); matrixId++) {
    271276                Node tileMatrixNode = tileMatrixList.item(matrixId);
     
    274279                tileMatrix.scaleDenominator = Double.parseDouble(getStringByXpath(tileMatrixNode, "ScaleDenominator"));
    275280                String[] topLeftCorner = getStringByXpath(tileMatrixNode, "TopLeftCorner").split(" ");
    276                 tileMatrix.topLeftCorner = new EastNorth(Double.parseDouble(topLeftCorner[1]), Double.parseDouble(topLeftCorner[0]));
     281
     282                if(matrixProj.switchXY()) {
     283                    tileMatrix.topLeftCorner = new EastNorth(Double.parseDouble(topLeftCorner[1]), Double.parseDouble(topLeftCorner[0]));
     284                } else {
     285                    tileMatrix.topLeftCorner = new EastNorth(Double.parseDouble(topLeftCorner[0]), Double.parseDouble(topLeftCorner[1]));
     286                }
    277287                tileMatrix.tileHeight = Integer.parseInt(getStringByXpath(tileMatrixNode, "TileHeight"));
    278288                tileMatrix.tileWidth = Integer.parseInt(getStringByXpath(tileMatrixNode, "TileHeight"));
     
    291301    private static String crsToCode(String crsIdentifier) {
    292302        if (crsIdentifier.startsWith("urn:ogc:def:crs:")) {
    293             return crsIdentifier.replaceFirst("urn:ogc:def:crs:([^:]*):[^:]*:(.*)$", "$1:$2");
     303            return crsIdentifier.replaceFirst("urn:ogc:def:crs:([^:]*):.*:(.*)$", "$1:$2");
    294304        }
    295305        return crsIdentifier;
     
    439449        }
    440450        double scale = matrix.scaleDenominator * this.crsScale;
    441         EastNorth ret = new EastNorth(matrix.topLeftCorner.getX() + x * scale, matrix.topLeftCorner.getY() - y * scale);
     451        EastNorth ret = new EastNorth(matrix.topLeftCorner.east() + x * scale, matrix.topLeftCorner.north() - y * scale);
    442452        return Main.getProjection().eastNorth2latlon(ret).toCoordinate();
    443453    }
     
    589599        EastNorth min = proj.latlon2eastNorth(bounds.getMin());
    590600        EastNorth max = proj.latlon2eastNorth(bounds.getMax());
    591         return (int) Math.ceil(Math.abs(max.getY() - min.getY()) / scale);
     601        return (int) Math.ceil(Math.abs(max.north() - min.north()) / scale);
    592602    }
    593603
     
    601611        EastNorth min = proj.latlon2eastNorth(bounds.getMin());
    602612        EastNorth max = proj.latlon2eastNorth(bounds.getMax());
    603         return (int) Math.ceil(Math.abs(max.getX() - min.getX()) / scale);
     613        return (int) Math.ceil(Math.abs(max.east() - min.east()) / scale);
    604614    }
    605615}
  • trunk/src/org/openstreetmap/josm/data/projection/CustomProjection.java

    r8570 r8584  
    5050    protected Bounds bounds;
    5151    private double metersPerUnit = METER_PER_UNIT_DEGREE; // default to degrees
     52    private String axis = "enu"; // default axis orientation is East, North, Up
    5253
    5354    /**
     
    9899        no_defs("no_defs", false),
    99100        init("init", true),
     101        /** crs units to meter multiplier */
    100102        to_meter("to_meter", true),
     103        /** definition of axis for projection */
     104        axis("axis", true),
    101105        // JOSM extensions, not present in PROJ.4
    102106        wmssrs("wmssrs", true),
     
    212216            if (s != null) {
    213217                this.metersPerUnit = parseDouble(s, Param.to_meter.key);
     218            }
     219            s = parameters.get(Param.axis.key);
     220            if (s != null) {
     221                this.axis  = s;
    214222            }
    215223        }
     
    548556    }
    549557
     558    @Override
     559    public boolean switchXY() {
     560        // TODO: support for other axis orientation such as West South, and Up Down
     561        return this.axis.startsWith("ne");
     562    }
     563
    550564    private static Map<String, Double> getUnitsToMeters() {
    551565        Map<String, Double> ret = new ConcurrentHashMap<>();
  • trunk/src/org/openstreetmap/josm/data/projection/Projection.java

    r8568 r8584  
    7979     */
    8080    double getMetersPerUnit();
     81
     82    /**
     83     * Does this projection natural order of coordinates is North East,
     84     * instead of East North
     85     *
     86     * @return true if natural order of coordinates is North East, false if East North
     87     */
     88    boolean switchXY();
    8189}
  • trunk/src/org/openstreetmap/josm/gui/layer/WMTSLayer.java

    r8570 r8584  
    6969                return tileSource;
    7070            }
    71         } catch (Exception e) {
    72             Main.warn("Could not create imagery layer:");
     71            return null;
     72        } catch (IOException e) {
    7373            Main.warn(e);
     74            throw new IllegalArgumentException(e);
    7475        }
    75         return null;
    7676    }
    7777
Note: See TracChangeset for help on using the changeset viewer.