Search in sources :

Example 1 with AuthorityFactory

use of org.opengis.referencing.AuthorityFactory in project sis by apache.

the class AuthorityFactories method fallback.

/**
 * Returns the fallback to use if the authority factory is not available. Unless the problem may be temporary,
 * this method replaces the {@link EPSGFactory} instance by {@link EPSGFactoryFallback} in order to prevent
 * the same exception to be thrown and logged on every calls to {@link CRS#forCode(String)}.
 */
static GeodeticAuthorityFactory fallback(final UnavailableFactoryException e) throws UnavailableFactoryException {
    final boolean isTransient = (e.getCause() instanceof SQLTransientException);
    final AuthorityFactory unavailable = e.getUnavailableFactory();
    GeodeticAuthorityFactory factory;
    final boolean alreadyDone;
    synchronized (EPSG) {
        factory = EPSG[0];
        alreadyDone = (factory == EPSGFactoryFallback.INSTANCE);
        if (!alreadyDone) {
            // May have been set in another thread (race condition).
            if (unavailable != factory) {
                // Exception did not come from a factory that we control.
                throw e;
            }
            factory = EPSGFactoryFallback.INSTANCE;
            if (!isTransient) {
                ALL.reload();
                EPSG[0] = factory;
            }
        }
    }
    if (!alreadyDone) {
        log(e, true);
    }
    return factory;
}
Also used : SQLTransientException(java.sql.SQLTransientException) AuthorityFactory(org.opengis.referencing.AuthorityFactory) CoordinateOperationAuthorityFactory(org.opengis.referencing.operation.CoordinateOperationAuthorityFactory) GeodeticAuthorityFactory(org.apache.sis.referencing.factory.GeodeticAuthorityFactory) CSAuthorityFactory(org.opengis.referencing.cs.CSAuthorityFactory) DatumAuthorityFactory(org.opengis.referencing.datum.DatumAuthorityFactory) CRSAuthorityFactory(org.opengis.referencing.crs.CRSAuthorityFactory) GeodeticAuthorityFactory(org.apache.sis.referencing.factory.GeodeticAuthorityFactory)

Example 2 with AuthorityFactory

use of org.opengis.referencing.AuthorityFactory in project sldeditor by robward-scisys.

the class CoordManager method populateCRSList.

/**
 * Populate crs list.
 */
public void populateCRSList() {
    if (isPopulated()) {
        Runnable runnable = () -> {
            VendorOptionVersion vendorOptionVersion = VendorOptionManager.getInstance().getDefaultVendorOptionVersion();
            ValueComboBoxData notSetValue = new ValueComboBoxData(NOT_SET_CRS, Localisation.getString(CoordManager.class, "common.notSet"), vendorOptionVersion);
            crsDataList.add(notSetValue);
            Hints hints = null;
            for (AuthorityFactory factory : ReferencingFactoryFinder.getCRSAuthorityFactories(hints)) {
                String authorityCode = NOT_SET_CRS;
                Citation citation = factory.getAuthority();
                if (citation != null) {
                    @SuppressWarnings("unchecked") Collection<Identifier> identifierList = (Collection<Identifier>) citation.getIdentifiers();
                    authorityCode = identifierList.iterator().next().getCode();
                }
                Set<String> codeList;
                try {
                    codeList = factory.getAuthorityCodes(CoordinateReferenceSystem.class);
                    for (String code : codeList) {
                        String fullCode = String.format("%s:%s", authorityCode, code);
                        String descriptionText = factory.getDescriptionText(code).toString();
                        String text = String.format("%s - %s", fullCode, descriptionText);
                        ValueComboBoxData value = new ValueComboBoxData(fullCode, text, vendorOptionVersion);
                        crsDataList.add(value);
                        crsMap.put(fullCode, value);
                    }
                } catch (NoSuchAuthorityCodeException e) {
                // ConsoleManager.getInstance().exception(this, e);
                } catch (FactoryException e) {
                    ConsoleManager.getInstance().exception(this, e);
                }
            }
        };
        Thread thread = new Thread(runnable);
        thread.start();
    }
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) Set(java.util.Set) Hints(org.geotools.factory.Hints) FactoryException(org.opengis.referencing.FactoryException) ValueComboBoxData(com.sldeditor.ui.widgets.ValueComboBoxData) Identifier(org.opengis.metadata.Identifier) ReferenceIdentifier(org.opengis.referencing.ReferenceIdentifier) VendorOptionVersion(com.sldeditor.common.vendoroption.VendorOptionVersion) Collection(java.util.Collection) AuthorityFactory(org.opengis.referencing.AuthorityFactory) Citation(org.opengis.metadata.citation.Citation)

Example 3 with AuthorityFactory

use of org.opengis.referencing.AuthorityFactory in project sis by apache.

the class AuthorityFactories method failure.

/**
 * Notifies that a factory is unavailable, but without giving a fallback and without logging.
 * The caller is responsible for throwing an exception, or for logging a warning and provide its own fallback.
 *
 * @return {@code false} if the caller can try again, or {@code true} if the failure can be considered final.
 */
static boolean failure(final UnavailableFactoryException e) {
    if (!(e.getCause() instanceof SQLTransientException)) {
        final AuthorityFactory unavailable = e.getUnavailableFactory();
        synchronized (EPSG) {
            final GeodeticAuthorityFactory factory = EPSG[0];
            if (factory == EPSGFactoryFallback.INSTANCE) {
                // May have been set in another thread.
                return false;
            }
            if (unavailable == factory) {
                ALL.reload();
                EPSG[0] = EPSGFactoryFallback.INSTANCE;
                return false;
            }
        }
    }
    return true;
}
Also used : SQLTransientException(java.sql.SQLTransientException) AuthorityFactory(org.opengis.referencing.AuthorityFactory) CoordinateOperationAuthorityFactory(org.opengis.referencing.operation.CoordinateOperationAuthorityFactory) GeodeticAuthorityFactory(org.apache.sis.referencing.factory.GeodeticAuthorityFactory) CSAuthorityFactory(org.opengis.referencing.cs.CSAuthorityFactory) DatumAuthorityFactory(org.opengis.referencing.datum.DatumAuthorityFactory) CRSAuthorityFactory(org.opengis.referencing.crs.CRSAuthorityFactory) GeodeticAuthorityFactory(org.apache.sis.referencing.factory.GeodeticAuthorityFactory)

Example 4 with AuthorityFactory

use of org.opengis.referencing.AuthorityFactory in project sis by apache.

the class DefaultCoordinateOperationFactory method createOperation.

/**
 * Finds or creates an operation for conversion or transformation between two coordinate reference systems.
 * If an operation exists, it is returned. If more than one operation exists, then the operation having the
 * widest intersection between its {@linkplain AbstractCoordinateOperation#getDomainOfValidity() domain of
 * validity} and the {@linkplain CoordinateOperationContext#getAreaOfInterest() area of interest} is returned.
 *
 * <p>The default implementation performs the following steps:</p>
 * <ul>
 *   <li>If a coordinate operation has been previously cached for the given CRS and context, return it.</li>
 *   <li>Otherwise:
 *     <ol>
 *       <li>Invoke {@link #createOperationFinder(CoordinateOperationAuthorityFactory, CoordinateOperationContext)}.</li>
 *       <li>Invoke {@link CoordinateOperationFinder#createOperation(CoordinateReferenceSystem, CoordinateReferenceSystem)}
 *           on the object returned by the previous step.</li>
 *       <li>Cache the result, then return it.</li>
 *     </ol>
 *   </li>
 * </ul>
 *
 * Subclasses can override {@link #createOperationFinder createOperationFinder(…)} if they need more control on
 * the way coordinate operations are inferred.
 *
 * @param  sourceCRS  input coordinate reference system.
 * @param  targetCRS  output coordinate reference system.
 * @param  context    area of interest and desired accuracy, or {@code null}.
 * @return a coordinate operation from {@code sourceCRS} to {@code targetCRS}.
 * @throws OperationNotFoundException if no operation path was found from {@code sourceCRS} to {@code targetCRS}.
 * @throws FactoryException if the operation creation failed for some other reason.
 *
 * @see CoordinateOperationFinder
 *
 * @since 0.7
 */
public CoordinateOperation createOperation(final CoordinateReferenceSystem sourceCRS, final CoordinateReferenceSystem targetCRS, final CoordinateOperationContext context) throws OperationNotFoundException, FactoryException {
    final Cache.Handler<CoordinateOperation> handler;
    CoordinateOperation op;
    if (context == null) {
        final CRSPair key = new CRSPair(sourceCRS, targetCRS);
        op = cache.peek(key);
        if (op != null) {
            return op;
        }
        handler = cache.lock(key);
    } else {
        // We currently do not cache the operation when the result may depend on the context (see 'this.cache' javadoc).
        handler = null;
        op = null;
    }
    try {
        if (handler == null || (op = handler.peek()) == null) {
            final AuthorityFactory registry = USE_EPSG_FACTORY ? CRS.getAuthorityFactory(Constants.EPSG) : null;
            op = createOperationFinder((registry instanceof CoordinateOperationAuthorityFactory) ? (CoordinateOperationAuthorityFactory) registry : null, context).createOperation(sourceCRS, targetCRS);
        }
    } finally {
        if (handler != null) {
            handler.putAndUnlock(op);
        }
    }
    return op;
}
Also used : AuthorityFactory(org.opengis.referencing.AuthorityFactory) Cache(org.apache.sis.util.collection.Cache)

Aggregations

AuthorityFactory (org.opengis.referencing.AuthorityFactory)4 SQLTransientException (java.sql.SQLTransientException)2 GeodeticAuthorityFactory (org.apache.sis.referencing.factory.GeodeticAuthorityFactory)2 CRSAuthorityFactory (org.opengis.referencing.crs.CRSAuthorityFactory)2 CSAuthorityFactory (org.opengis.referencing.cs.CSAuthorityFactory)2 DatumAuthorityFactory (org.opengis.referencing.datum.DatumAuthorityFactory)2 CoordinateOperationAuthorityFactory (org.opengis.referencing.operation.CoordinateOperationAuthorityFactory)2 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)1 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)1 Collection (java.util.Collection)1 Set (java.util.Set)1 Cache (org.apache.sis.util.collection.Cache)1 Hints (org.geotools.factory.Hints)1 Identifier (org.opengis.metadata.Identifier)1 Citation (org.opengis.metadata.citation.Citation)1 FactoryException (org.opengis.referencing.FactoryException)1 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)1 ReferenceIdentifier (org.opengis.referencing.ReferenceIdentifier)1