Search in sources :

Example 31 with FactoryException

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

the class CoordManager method processCRSEntry.

/**
 * Process CRS entry.
 */
private void processCRSEntry() {
    VendorOptionVersion vendorOptionVersion = VendorOptionManager.getInstance().getDefaultVendorOptionVersion();
    ValueComboBoxData notSetValue = new ValueComboBoxData(NOT_SET_CRS, Localisation.getString(CoordManager.class, Localisation.COMMON_NOT_SET), 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) {
        // Do nothing
        } catch (FactoryException e) {
            ConsoleManager.getInstance().exception(this, e);
        }
    }
}
Also used : NoSuchAuthorityCodeException(org.opengis.referencing.NoSuchAuthorityCodeException) 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) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 32 with FactoryException

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

the class MapRender method convertToWGS84.

/**
 * Convert referenced envelope to WGS 84.
 *
 * @param bounds the bounds
 * @return the referenced envelope
 */
private ReferencedEnvelope convertToWGS84(ReferencedEnvelope bounds) {
    if (bounds == null) {
        return null;
    }
    CoordinateReferenceSystem wgs84 = CoordManager.getInstance().getWGS84();
    if (wgs84.equals(bounds.getCoordinateReferenceSystem())) {
        return bounds;
    }
    if (bounds.getCoordinateReferenceSystem() == null) {
        return bounds;
    }
    MathTransform transform = null;
    try {
        transform = CRS.findMathTransform(bounds.getCoordinateReferenceSystem(), wgs84, true);
    } catch (FactoryException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    Envelope targetGeometry = null;
    try {
        targetGeometry = JTS.transform(bounds, transform);
    } catch (TransformException e) {
        ConsoleManager.getInstance().exception(this, e);
    }
    if (targetGeometry != null) {
        return new ReferencedEnvelope(targetGeometry.getMinY(), targetGeometry.getMaxY(), targetGeometry.getMinX(), targetGeometry.getMaxX(), wgs84);
    }
    return null;
}
Also used : ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) MathTransform(org.opengis.referencing.operation.MathTransform) FactoryException(org.opengis.referencing.FactoryException) TransformException(org.opengis.referencing.operation.TransformException) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) ReferencedEnvelope(org.geotools.geometry.jts.ReferencedEnvelope) Envelope(org.locationtech.jts.geom.Envelope)

Aggregations

FactoryException (org.opengis.referencing.FactoryException)32 CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)22 TransformException (org.opengis.referencing.operation.TransformException)11 NoSuchAuthorityCodeException (org.opengis.referencing.NoSuchAuthorityCodeException)8 MathTransform (org.opengis.referencing.operation.MathTransform)8 Collection (java.util.Collection)6 GeometryType (org.opengis.feature.type.GeometryType)5 Geometry (com.vividsolutions.jts.geom.Geometry)4 Hints (org.geotools.factory.Hints)4 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)4 PropertyDescriptor (org.opengis.feature.type.PropertyDescriptor)4 PropertyType (org.opengis.feature.type.PropertyType)4 ValueComboBoxData (com.sldeditor.ui.widgets.ValueComboBoxData)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)3 Geometry (org.locationtech.jts.geom.Geometry)3 InternationalString (org.opengis.util.InternationalString)3 Optional (com.google.common.base.Optional)2 VendorOptionVersion (com.sldeditor.common.vendoroption.VendorOptionVersion)2