Changeset 14399 in josm


Ignore:
Timestamp:
2018-11-02T00:07:28+01:00 (6 years ago)
Author:
wiktorn
Message:

GetTileUrl performance improvements for WMS

See: #16769

Location:
trunk
Files:
4 edited

Legend:

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

    r13733 r14399  
    226226        double e = se.getX();
    227227
    228         return (
    229                 switchLatLon ?
    230                         String.format("%s,%s,%s,%s",
    231                                 LATLON_FORMAT.format(s), LATLON_FORMAT.format(w), LATLON_FORMAT.format(n), LATLON_FORMAT.format(e))
    232                         :
    233                         String.format("%s,%s,%s,%s",
    234                                 LATLON_FORMAT.format(w), LATLON_FORMAT.format(s), LATLON_FORMAT.format(e), LATLON_FORMAT.format(n))
    235 
    236                 );
     228        return switchLatLon ?
     229                getBboxstr(s, w, n, e)
     230                : getBboxstr(w, s, e, n);
     231    }
     232
     233    private final String getBboxstr(double x1, double x2, double x3, double x4) {
     234        return new StringBuilder(64)
     235                .append(LATLON_FORMAT.format(x1))
     236                .append(',')
     237                .append(LATLON_FORMAT.format(x2))
     238                .append(',')
     239                .append(LATLON_FORMAT.format(x3))
     240                .append(',')
     241                .append(LATLON_FORMAT.format(x4))
     242                .toString();
    237243    }
    238244}
  • trunk/src/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSource.java

    r14120 r14399  
    5151    };
    5252
     53    private final boolean switchLatLon;
    5354    /**
    5455     * Creates a tile source based on imagery info
     
    6263        handleTemplate();
    6364        initProjection();
     65        // Bounding box coordinates have to be switched for WMS 1.3.0 EPSG:4326.
     66        //
     67        // Background:
     68        //
     69        // bbox=x_min,y_min,x_max,y_max
     70        //
     71        //      SRS=... is WMS 1.1.1
     72        //      CRS=... is WMS 1.3.0
     73        //
     74        // The difference:
     75        //      For SRS x is east-west and y is north-south
     76        //      For CRS x and y are as specified by the EPSG
     77        //          E.g. [1] lists lat as first coordinate axis and lot as second, so it is switched for EPSG:4326.
     78        //          For most other EPSG code there seems to be no difference.
     79        // CHECKSTYLE.OFF: LineLength
     80        // [1] https://www.epsg-registry.org/report.htm?type=selection&entity=urn:ogc:def:crs:EPSG::4326&reportDetail=short&style=urn:uuid:report-style:default-with-code&style_name=OGP%20Default%20With%20Code&title=EPSG:4326
     81        // CHECKSTYLE.ON: LineLength
     82        if (baseUrl.toLowerCase(Locale.US).contains("crs=epsg:4326")) {
     83            switchLatLon = true;
     84        } else if (baseUrl.toLowerCase(Locale.US).contains("crs=")) {
     85            // assume WMS 1.3.0
     86            switchLatLon = ProjectionRegistry.getProjection().switchXY();
     87        } else {
     88            switchLatLon = false;
     89        }
    6490    }
    6591
     
    86112        }
    87113
    88         // Bounding box coordinates have to be switched for WMS 1.3.0 EPSG:4326.
    89         //
    90         // Background:
    91         //
    92         // bbox=x_min,y_min,x_max,y_max
    93         //
    94         //      SRS=... is WMS 1.1.1
    95         //      CRS=... is WMS 1.3.0
    96         //
    97         // The difference:
    98         //      For SRS x is east-west and y is north-south
    99         //      For CRS x and y are as specified by the EPSG
    100         //          E.g. [1] lists lat as first coordinate axis and lot as second, so it is switched for EPSG:4326.
    101         //          For most other EPSG code there seems to be no difference.
    102         // CHECKSTYLE.OFF: LineLength
    103         // [1] https://www.epsg-registry.org/report.htm?type=selection&entity=urn:ogc:def:crs:EPSG::4326&reportDetail=short&style=urn:uuid:report-style:default-with-code&style_name=OGP%20Default%20With%20Code&title=EPSG:4326
    104         // CHECKSTYLE.ON: LineLength
    105         boolean switchLatLon = false;
    106         if (baseUrl.toLowerCase(Locale.US).contains("crs=epsg:4326")) {
    107             switchLatLon = true;
    108         } else if (baseUrl.toLowerCase(Locale.US).contains("crs=")) {
    109             // assume WMS 1.3.0
    110             switchLatLon = ProjectionRegistry.getProjection().switchXY();
    111         }
    112         String bbox = getBbox(zoom, tilex, tiley, switchLatLon);
    113 
    114114        // Using StringBuffer and generic PATTERN_PARAM matcher gives 2x performance improvement over replaceAll
    115115        StringBuffer url = new StringBuffer(baseUrl.length());
     
    125125                break;
    126126            case "bbox":
    127                 replacement = bbox;
     127                replacement = getBbox(zoom, tilex, tiley, switchLatLon);
    128128                break;
    129129            case "w":
  • trunk/src/org/openstreetmap/josm/data/imagery/WMSEndpointTileSource.java

    r14214 r14399  
    6060    @Override
    6161    public String getTileUrl(int zoom, int tilex, int tiley) {
    62         String bbox = getBbox(zoom, tilex, tiley, !wmsi.belowWMS130() && getTileProjection().switchXY());
    63 
    6462        // Using StringBuffer and generic PATTERN_PARAM matcher gives 2x performance improvement over replaceAll
    6563        StringBuffer url = new StringBuffer(urlPattern.length());
     
    7270                break;
    7371            case "bbox":
    74                 replacement = bbox;
     72                replacement = getBbox(zoom, tilex, tiley, !wmsi.belowWMS130() && getTileProjection().switchXY());
    7573                break;
    7674            case "width":
  • trunk/test/unit/org/openstreetmap/josm/data/imagery/TemplatedWMSTileSourceTest.java

    r14120 r14399  
    152152    }
    153153
     154    /**
     155     * Test getTileUrl
     156     */
     157    @Test
     158    public void testGetTileUrl() {
     159        // "https://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery_Dates/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=0&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE",
     160        Projection projection = Projections.getProjectionByCode("EPSG:4326");
     161        ProjectionRegistry.setProjection(projection);
     162        ImageryInfo testImageryWMS = new ImageryInfo("test imagery",
     163                "https://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery_Dates/MapServer/WMSServer?SERVICE=WMS&VERSION=1.3.0&"
     164                + "REQUEST=GetMap&CRS={proj}&BBOX={bbox}&WIDTH={width}&HEIGHT={height}&LAYERS=0&STYLES=&FORMAT=image/png32&DPI=96&"
     165                + "MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE",
     166                "wms",
     167                null,
     168                null);
     169        TemplatedWMSTileSource ts = new TemplatedWMSTileSource(testImageryWMS, projection);
     170        assertEquals("https://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery_Dates/MapServer/WMSServer?SERVICE=WMS&"
     171                + "VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&BBOX=-1349.9999381,539.9999691,-989.9999536,899.9999536&WIDTH=512&"
     172                + "HEIGHT=512&LAYERS=0&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE",
     173                ts.getTileUrl(1, 2, 3));
     174        assertEquals("https://maps.six.nsw.gov.au/arcgis/services/public/NSW_Imagery_Dates/MapServer/WMSServer?SERVICE=WMS&"
     175                + "VERSION=1.3.0&REQUEST=GetMap&CRS=EPSG:4326&BBOX=-89.9999923,-0.0000077,0.0000039,89.9999884&WIDTH=512&HEIGHT=512&"
     176                + "LAYERS=0&STYLES=&FORMAT=image/png32&DPI=96&MAP_RESOLUTION=96&FORMAT_OPTIONS=dpi:96&TRANSPARENT=TRUE",
     177                ts.getTileUrl(3, 2, 1));
     178        testImageryWMS = new ImageryInfo("test imagery",
     179                "https://services.slip.wa.gov.au/public/services/SLIP_Public_Services/Transport/MapServer/WMSServer?LAYERS=8&"
     180                + "TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS={proj}&BBOX={bbox}&"
     181                + "WIDTH={width}&HEIGHT={height}",
     182                "wms",
     183                null,
     184                null);
     185        ts = new TemplatedWMSTileSource(testImageryWMS, projection);
     186        assertEquals("https://services.slip.wa.gov.au/public/services/SLIP_Public_Services/Transport/MapServer/WMSServer?LAYERS=8&"
     187                + "TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS=EPSG:4326&"
     188                + "BBOX=539.9999691,-1349.9999381,899.9999536,-989.9999536&WIDTH=512&HEIGHT=512",
     189                ts.getTileUrl(1, 2, 3));
     190        assertEquals("https://services.slip.wa.gov.au/public/services/SLIP_Public_Services/Transport/MapServer/WMSServer?LAYERS=8&"
     191                + "TRANSPARENT=TRUE&SERVICE=WMS&VERSION=1.1.1&REQUEST=GetMap&STYLES=&FORMAT=image%2Fpng&SRS=EPSG:4326&"
     192                + "BBOX=-0.0000077,-89.9999923,89.9999884,0.0000039&WIDTH=512&HEIGHT=512", ts.getTileUrl(3, 2, 1));
     193    }
     194
    154195    private void verifyMercatorTile(TemplatedWMSTileSource source, int x, int y, int z) {
    155196        TemplatedTMSTileSource verifier = new TemplatedTMSTileSource(testImageryTMS);
Note: See TracChangeset for help on using the changeset viewer.