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;
}
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();
}
}
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;
}
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;
}
Aggregations