/** * Calculates the resolution (world units / pixel) for the given scale denominator (1 / map scale) and unit system. * * @param scaleDenominator * scale denominator (1 / map scale) * @param units * units, must not be <code>null</code> * @return resolution in world units per pixel */ public static double calcResolution( double scaleDenominator, IUnit units ) { if ( units.equals( METRE ) ) { return calcMetricResFromScale( scaleDenominator ); } else if ( units.equals( DEGREE ) ) { return calcDegreeResFromScale( scaleDenominator ); } String msg = "Unhandled unit type: " + units + ". Conversion from scale denominator to resolution not implemented"; throw new IllegalArgumentException( msg ); }
@Override public TileMatrixSet build() { try { ICRS crs = CRSManager.getCRSRef( cfg.getCRS() ); List<TileMatrix> matrices = new ArrayList<TileMatrix>(); for ( TileMatrixSetConfig.TileMatrix tm : cfg.getTileMatrix() ) { double res; if ( crs.getUnits()[0].equals( Unit.DEGREE ) ) { res = MapUtils.calcDegreeResFromScale( tm.getScaleDenominator() ); } else { res = tm.getScaleDenominator() * DEFAULT_PIXEL_SIZE; } double minx = tm.getTopLeftCorner().get( 0 ); double maxy = tm.getTopLeftCorner().get( 1 ); double maxx = tm.getTileWidth().longValue() * tm.getMatrixWidth().longValue() * res + minx; double miny = maxy - tm.getTileHeight().longValue() * tm.getMatrixHeight().longValue() * res; Envelope env = new GeometryFactory().createEnvelope( minx, miny, maxx, maxy, crs ); SpatialMetadata smd = new SpatialMetadata( env, Collections.singletonList( crs ) ); TileMatrix md = new TileMatrix( tm.getIdentifier(), smd, tm.getTileWidth(), tm.getTileHeight(), res, tm.getMatrixWidth(), tm.getMatrixHeight() ); matrices.add( md ); } String identifier = metadata.getIdentifier().getId(); String wknScaleSet = cfg.getWellKnownScaleSet(); return new TileMatrixSet( identifier, wknScaleSet, matrices, matrices.get( 0 ).getSpatialMetadata(), metadata ); } catch ( Exception e ) { throw new ResourceInitException( "Could not create tile matrix set. Reason: " + e.getLocalizedMessage(), e ); } }