/** * Add the id to the cache, by mapping it to all its identifiers. * * @param <V> * type of CRSIdentifiable * @param resource * to insert into cache * @param update * if true an existing identifiable in the cache will be overwritten. * @return the identifiable */ public synchronized <V extends CRSResource> V addIdToCache( V resource, boolean update ) { return addIdToCache( cachedIdentifiables, resource, update ); }
/** * Retrieves the {@link ICRS} from the set provider that is identified by the given {@link CRSCodeType} id. * * @param id * the {@link CRSCodeType} of the wanted crs * @return the {@link ICRS} that corresponds to the id * @throws CRSConfigurationException */ public ICRS getCRSByCode( CRSCodeType id ) throws CRSConfigurationException { return getCRSByCode( id, false ); }
if ( id != null ) { if ( forceXY ) { result = getCRSFromCache( cachedCRSXY, id, result ); result = getCRSFromCache( cachedIdentifiables, id, result ); if ( result == null ) { LOG.debug( "No crs with id: " + id + " found in cache." ); result = getCoordinateSystem( id.getOriginal() ); result = createXYCoordinateSystem( result ); addIdToCache( cachedCRSXY, result, false ); if ( result.getType() == COMPOUND ) { addIdToCache( cachedCRSXY, ( (ICompoundCRS) result ).getUnderlyingCRS(), false ); if ( ( (ICompoundCRS) result ).getUnderlyingCRS().getType() == PROJECTED ) { ICRS underlying = resolve( ( (ICompoundCRS) result ).getUnderlyingCRS() ); addIdToCache( cachedCRSXY, ( (ProjectedCRS) underlying ).getGeographicCRS(), false ); addIdToCache( ( (IProjectedCRS) result ).getGeographicCRS(), false ); addIdToCache( result, false ); if ( result.getType() == COMPOUND ) { addIdToCache( ( (ICompoundCRS) result ).getUnderlyingCRS(), false ); if ( ( (ICompoundCRS) result ).getUnderlyingCRS().getType() == PROJECTED ) { ICRS underlying = resolve( ( (ICompoundCRS) result ).getUnderlyingCRS() ); addIdToCache( ( (ProjectedCRS) underlying ).getGeographicCRS(), false ); addIdToCache( ( (IProjectedCRS) result ).getGeographicCRS(), false );
private ICRS createXYCoordinateSystem( ICRS result ) { switch ( result.getType() ) { case GEOGRAPHIC: return new GeographicCRS( ( (GeographicCRS) result ).getGeodeticDatum(), forceXYAxisOrder( result.getAxis() ), new CRSIdentifiable( result ) ); case COMPOUND: CompoundCRS comp = (CompoundCRS) result; return new CompoundCRS( comp.getHeightAxis(), createXYCoordinateSystem( comp.getUnderlyingCRS() ), comp.getDefaultHeight(), new CRSIdentifiable( comp ) ); } return result; }
/** * The id are what they are, not trimming 'upcasing' or other modifications will be done in this method. * * @param expectedType * The class of type T which is expected. * @param <V> * the type to cast to if the casting fails, null will be returned. * @param ids * to search the cache for * @return the {@link CRSIdentifiable} of the first matching id or <code>null</code> if it was not found. */ public <V extends CRSResource> V getCachedIdentifiable( Class<V> expectedType, CRSResource ids ) { if ( ids == null ) { return null; } return getCachedIdentifiable( expectedType, ids.getCodes() ); }
/** * The id are what they are, not trimming 'upcasing' or other modifications will be done in this method. * * @param expectedType * The class of type T which is expected. * @param <V> * the type to cast to if the casting fails, null will be returned. * @param ids * to search the cache for * @return the {@link CRSIdentifiable} of the first matching id or <code>null</code> if it was not found. */ public <V extends CRSResource> V getCachedIdentifiable( Class<V> expectedType, String[] ids ) { if ( ids == null || ids.length == 0 ) { return null; } V result = null; for ( int i = 0; i < ids.length && result == null; i++ ) { result = getCachedIdentifiable( expectedType, ids[i] ); if ( LOG.isDebugEnabled() ) { LOG.debug( "Searched for id: " + ids[i] + " resulted in: " + ( ( result == null ) ? "null" : result.getCode() ) ); } } return result; }
/** * Get a {@link CRSIdentifiable} (actually a type V that extends it) from the cache that corresponds to the a * {@link CRSCodeType}. An array of code types is given; the first identifiable that is found in (for a code, when * they are checked in order) is returned * * @param <V> * @param expectedType * the type of the sought object * @param ids * an array of {@link CRSCodeType}s * @return the identifiable found in the cache corresponding to the (first) id */ public <V extends CRSResource> V getCachedIdentifiable( Class<V> expectedType, CRSCodeType[] ids ) { if ( ids == null || ids.length == 0 ) { return null; } V result = null; for ( int i = 0; i < ids.length && result == null; i++ ) { result = getCachedIdentifiable( expectedType, ids[i] ); if ( LOG.isDebugEnabled() ) { LOG.debug( "Searched for id: " + ids[i] + " resulted in: " + ( ( result == null ) ? "null" : result.getCode() ) ); } } return result; }
@Override public List<ICRS> getAvailableCRSs() { List<CRSCodeType[]> availableCRSIds = getAvailableCRSIds(); List<ICRS> result = new ArrayList<ICRS>( availableCRSIds.size() ); for ( CRSCodeType[] s : availableCRSIds ) { ICRS crs = getProvider().getCRSByCode( s[0] ); if ( crs != null ) { result.add( crs ); } } return result; }