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