Search in sources :

Example 61 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sis by apache.

the class DefaultConcatenatedOperation method initialize.

/**
 * Initializes the {@link #sourceCRS}, {@link #targetCRS} and {@link #operations} fields.
 * If the source or target CRS is already non-null (which may happen on JAXB unmarshalling),
 * leaves that CRS unchanged.
 *
 * @param  properties   the properties specified at construction time, or {@code null} if unknown.
 * @param  operations   the operations to concatenate.
 * @param  mtFactory    the math transform factory to use, or {@code null} for not performing concatenation.
 * @throws FactoryException if the factory can not concatenate the math transforms.
 */
private void initialize(final Map<String, ?> properties, final CoordinateOperation[] operations, final MathTransformFactory mtFactory) throws FactoryException {
    final List<CoordinateOperation> flattened = new ArrayList<>(operations.length);
    final CoordinateReferenceSystem crs = initialize(properties, operations, flattened, mtFactory, (sourceCRS == null), (coordinateOperationAccuracy == null), (domainOfValidity == null));
    if (targetCRS == null) {
        targetCRS = crs;
    }
    /*
         * At this point we should have flattened.size() >= 2, except if some operations
         * were omitted because their associated math transform were identity operation.
         */
    this.operations = UnmodifiableArrayList.wrap(flattened.toArray(new SingleOperation[flattened.size()]));
}
Also used : ArrayList(java.util.ArrayList) UnmodifiableArrayList(org.apache.sis.internal.util.UnmodifiableArrayList) CoordinateOperation(org.opengis.referencing.operation.CoordinateOperation) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 62 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project sis by apache.

the class DefaultPassThroughOperation method setIndices.

/**
 * Invoked by JAXB at unmarshalling time for setting the modified coordinates.
 */
private void setIndices(final int[] ordinates) {
    String missing = "sourceCRS";
    final CoordinateReferenceSystem sourceCRS = super.getSourceCRS();
    if (sourceCRS != null) {
        missing = "modifiedCoordinate";
        if (ordinates != null && ordinates.length != 0) {
            missing = "coordOperation";
            if (operation != null) {
                for (int i = 1; i < ordinates.length; i++) {
                    final int previous = ordinates[i - 1];
                    if (previous < 1 || ordinates[i] != previous + 1) {
                        throw new IllegalArgumentException(Errors.format(Errors.Keys.CanNotAssign_2, missing, Arrays.toString(ordinates)));
                    }
                }
                transform = PassThroughTransform.create(ordinates[0] - 1, operation.getMathTransform(), ReferencingUtilities.getDimension(sourceCRS) - ordinates[ordinates.length - 1]);
                return;
            }
        }
    }
    throw new IllegalStateException(Errors.format(Errors.Keys.MissingComponentInElement_2, missing, "PassThroughOperation"));
}
Also used : CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem)

Example 63 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project coastal-hazards by USGS-CIDA.

the class CRSUtils method getCRSFromFeatureCollection.

public static CoordinateReferenceSystem getCRSFromFeatureCollection(FeatureCollection<SimpleFeatureType, SimpleFeature> simpleFeatureCollection) {
    FeatureCollection<SimpleFeatureType, SimpleFeature> shorelineFeatureCollection = simpleFeatureCollection;
    SimpleFeatureType sft = shorelineFeatureCollection.getSchema();
    CoordinateReferenceSystem coordinateReferenceSystem = sft.getCoordinateReferenceSystem();
    return coordinateReferenceSystem;
}
Also used : SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 64 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project onebusaway-application-modules by camsys.

the class ShapefileLibrary method loadShapeFile.

public static FeatureCollection<SimpleFeatureType, SimpleFeature> loadShapeFile(File path) throws Exception {
    _log.info("loading shapefile " + path.toURI());
    ShapefileDataStore dataStore = new ShapefileDataStore(path.toURI().toURL());
    _log.info("loaded!");
    String[] typeNames = dataStore.getTypeNames();
    String typeName = typeNames[0];
    FeatureSource<SimpleFeatureType, SimpleFeature> featureSource = dataStore.getFeatureSource(typeName);
    CoordinateReferenceSystem sourceCRS = featureSource.getInfo().getCRS();
    _log.info("using sourceCRS=" + sourceCRS + " for typeName=" + typeName);
    Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE);
    CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints);
    CoordinateReferenceSystem worldCRS = factory.createCoordinateReferenceSystem("EPSG:4326");
    DefaultQuery query = new DefaultQuery(typeName);
    query.setCoordinateSystem(sourceCRS);
    query.setCoordinateSystemReproject(worldCRS);
    query.setHints(hints);
    return featureSource.getFeatures(query);
}
Also used : ShapefileDataStore(org.geotools.data.shapefile.ShapefileDataStore) DefaultQuery(org.geotools.data.DefaultQuery) SimpleFeatureType(org.opengis.feature.simple.SimpleFeatureType) Hints(org.geotools.factory.Hints) CRSAuthorityFactory(org.opengis.referencing.crs.CRSAuthorityFactory) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) SimpleFeature(org.opengis.feature.simple.SimpleFeature)

Example 65 with CoordinateReferenceSystem

use of org.opengis.referencing.crs.CoordinateReferenceSystem in project collect by openforis.

the class GeoToolsCoordinateOperations method fetchSRS.

public SpatialReferenceSystem fetchSRS(String code, Set<String> labelLanguages) {
    try {
        CRSAuthorityFactory factory = CRS.getAuthorityFactory(true);
        CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem(code);
        SpatialReferenceSystem result = new SpatialReferenceSystem(code, crs.toWKT());
        String description = getDescription(crs);
        for (String lang : labelLanguages) {
            result.setLabel(lang, code);
            result.setDescription(lang, description);
        }
        return result;
    } catch (Exception e) {
        throw new RuntimeException("Error fetching SRS with code: " + code, e);
    }
}
Also used : SpatialReferenceSystem(org.openforis.idm.metamodel.SpatialReferenceSystem) CRSAuthorityFactory(org.opengis.referencing.crs.CRSAuthorityFactory) CoordinateReferenceSystem(org.opengis.referencing.crs.CoordinateReferenceSystem) InternationalString(org.opengis.util.InternationalString) FactoryException(org.opengis.referencing.FactoryException) CoordinateOperationException(org.openforis.idm.geospatial.CoordinateOperationException) TransformException(org.opengis.referencing.operation.TransformException)

Aggregations

CoordinateReferenceSystem (org.opengis.referencing.crs.CoordinateReferenceSystem)210 Test (org.junit.Test)80 MathTransform (org.opengis.referencing.operation.MathTransform)32 FactoryException (org.opengis.referencing.FactoryException)25 CoordinateOperation (org.opengis.referencing.operation.CoordinateOperation)24 ReferencedEnvelope (org.geotools.geometry.jts.ReferencedEnvelope)23 Geometry (com.vividsolutions.jts.geom.Geometry)21 TransformException (org.opengis.referencing.operation.TransformException)21 DependsOnMethod (org.apache.sis.test.DependsOnMethod)19 CoordinateSystem (org.opengis.referencing.cs.CoordinateSystem)13 Geometry (org.locationtech.jts.geom.Geometry)11 FactoryException (org.opengis.util.FactoryException)11 SimpleFeature (org.opengis.feature.simple.SimpleFeature)9 DirectPosition (org.opengis.geometry.DirectPosition)9 GeographicCRS (org.opengis.referencing.crs.GeographicCRS)9 VerticalCRS (org.opengis.referencing.crs.VerticalCRS)9 CoordinateSystemAxis (org.opengis.referencing.cs.CoordinateSystemAxis)9 ArrayList (java.util.ArrayList)8 GeometryType (org.opengis.feature.type.GeometryType)8 RevFeatureType (org.locationtech.geogig.api.RevFeatureType)7