/** * Retrieves an equivalent {@link ICRS} with authoritative axis ordering. * * NOTE: Due to the current state of the CRS database, this method is a hack. As soon as the CRS-DB has been * sanitized by removing the custom XY-variants of EPSG-CRS, it is not required anymore and should be removed. * * @param crs * CRS with authoritative or non-authoritative (forced XY) axis-ordering, must not be <code>null</code> * @return equivalent CRS with authoritative axis ordering, never <code>null</code> * @throws UnknownCRSException */ public static ICRS getAxisAwareCrs( final ICRS crs ) throws UnknownCRSException { if ( isAxisAware( crs ) ) { return crs; } for ( final String crsString : crs.getOrignalCodeStrings() ) { final String lowerCrsString = crsString.toLowerCase(); if ( lowerCrsString.startsWith( "epsg:" ) ) { final String epsgCode = lowerCrsString.substring( 5 ); return getAxisAwareCrs( epsgCode ); } } throw new RuntimeException( "Unable to determine axis-aware CRS variant for " + crs.getAlias() ); }
/** * Calculates the resolution (world units / pixel) for the given scale denominator (1 / map scale) and coordinate * reference system (determines the world units). * * @param scaleDenominator * scale denominator (1 / map scale) * @param crs * coordinate reference system, must not be <code>null</code> * @return resolution in world units per pixel */ public static double calcResolution( double scaleDenominator, ICRS crs ) { IUnit units = crs.getAxis()[0].getUnits(); return calcResolution( scaleDenominator, units ); }
throws UnknownCRSException { final String alias = crs.getAlias().toLowerCase(); if (isUrnEpsgIdentifier( alias ) || isOgcCrsIdentifier( alias )) { LOG.debug( alias + " is considered axis aware" ); return true; if ( isUrnEpsgIdentifier( lowerCrsString ) ) { LOG.debug( crs.getAlias() + " is considered axis aware" ); return true; if ( isOgcCrsIdentifier( lowerCrsString ) ) { LOG.debug( crs.getAlias() + " is considered axis aware" ); return true;
/** * @param crs * @param bbox * @return a new CRS */ public static Envelope getCRSAndEnvelope130( String crs, double[] bbox ) { if ( crs.startsWith( "AUTO2:" ) ) { String[] cs = crs.split( ":" )[1].split( "," ); int id = Integer.parseInt( cs[0] ); // this is not supported double factor = Double.parseDouble( cs[1] ); double lon0 = Double.parseDouble( cs[2] ); double lat0 = Double.parseDouble( cs[3] ); return new GeometryFactory().createEnvelope( factor * bbox[0], factor * bbox[1], factor * bbox[2], factor * bbox[3], Utils.getAutoCRS( id, lon0, lat0 ) ); } ICRS crsRef = CRSManager.getCRSRef( crs ); try { crsRef = CRSUtils.getAxisAwareCrs( crsRef ); } catch ( Exception e ) { LOG.warn( "Unable to determine axis-aware variant of '" + crs + "'. Continuing." ); } return new GeometryFactory().createEnvelope( bbox[0], bbox[1], bbox[2], bbox[3], crsRef ); }
private BufferedImage extractAndReprojectRegion( ICRS nativeCrs ) { int requestEpsgCode = CRSUtils.getEpsgCode( bbox.getCoordinateSystem() ); int nativeEpsgCode = CRSUtils.getEpsgCode( nativeCrs ); SpatialReference requestSr = gdalSettings.getCrsAsWkt( requestEpsgCode ); SpatialReference nativeSr = gdalSettings.getCrsAsWkt( nativeEpsgCode ); Envelope nativeBbox = transform( bbox, requestSr, nativeSr ); List<byte[][]> nativeRegions = getIntersectingRegionsFromAllDatasets( nativeBbox ); if ( nativeRegions.isEmpty() ) { return null; } Dataset nativeRegion = composeMemDataset( nativeBbox, nativeSr.ExportToWkt(), nativeRegions ); Dataset reprojectedRegion = reproject( nativeRegion, requestSr.ExportToWkt() ); byte[][] rawImage = readBands( reprojectedRegion ); nativeRegion.delete(); reprojectedRegion.delete(); return toImage( rawImage, width, height, true ); }
private static Envelope getTransformedEnvelopeWithAuthoritativeAxisOrdering( final Envelope nativeBbox, final ICRS targetCrs, final ICRS latlon ) { ICRS targetCrsWithOfficialAxisOrder = targetCrs; try { targetCrsWithOfficialAxisOrder = getAxisAwareCrs( targetCrs ); } catch ( UnknownCRSException e ) { LOG.warn( "Cannot determine axis-aware CRS: {}", e.getLocalizedMessage() ); LOG.trace( "Stack trace:", e ); } try { GeometryTransformer transformer = new GeometryTransformer( targetCrsWithOfficialAxisOrder ); if ( nativeBbox.getCoordinateSystem() == null ) { return transformer.transform( nativeBbox, latlon ); } else { return transformer.transform( nativeBbox ); } } catch ( Throwable e ) { LOG.warn( "Cannot transform: {}", e.getLocalizedMessage() ); LOG.trace( "Stack trace:", e ); } return null; }
nextElement( xmlStream ); double resolution = calcResolution( scaleDenominator, crs ); SpatialMetadata spatialMetadata = createSpatialMetadata( crs, resolution, topLeftCorner, tileSizeX, tileSizeY, numTilesX, numTilesY );