/** * Constructs a parser for the specified set of symbols using default factories. * * @param symbols The symbols for parsing and formatting numbers. * @todo Pass hints in argument. */ public Parser(final Symbols symbols) { this( symbols, ReferencingFactoryFinder.getDatumFactory(null), ReferencingFactoryFinder.getCSFactory(null), ReferencingFactoryFinder.getCRSFactory(null), ReferencingFactoryFinder.getMathTransformFactory(null)); }
CoordinateReferenceSystem sourceCRS = featureSource.getInfo().getCRS(); Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); CoordinateReferenceSystem worldCRS = factory .createCoordinateReferenceSystem("EPSG:4326");
public ReprojectingFeatureCollection( SimpleFeatureCollection delegate, CoordinateReferenceSystem target) throws SchemaException, OperationNotFoundException, FactoryRegistryException, FactoryException { super(delegate); this.target = target; this.schema = FeatureTypes.transform(delegate.getSchema(), target); // create transform cache transformers = new HashMap(); // cache "default" transform CoordinateReferenceSystem source = delegate.getSchema().getCoordinateReferenceSystem(); if (source != null) { MathTransform tx = ReferencingFactoryFinder.getCoordinateOperationFactory(hints) .createOperation(source, target) .getMathTransform(); GeometryCoordinateSequenceTransformer transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); transformers.put(source, transformer); } else { throw new RuntimeException( "Source was null in trying to create a reprojected feature collection!"); } }
ReferencingFactoryFinder.getCoordinateOperationAuthorityFactories(null)); } catch (Throwable e) { LOGGER.log( disposeAuthorityFactories(ReferencingFactoryFinder.getCRSAuthorityFactories(null)); } catch (Throwable e) { LOGGER.log( disposeAuthorityFactories(ReferencingFactoryFinder.getCSAuthorityFactories(null)); } catch (Throwable e) { LOGGER.log( CRS.reset("all"); LOGGER.info("Shut down GT referencing threads "); ReferencingFactoryFinder.reset(); CommonFactoryFinder.reset(); DataStoreFinder.reset();
/** Creates a builder from the specified hints. */ public MathTransformBuilder(final Hints hints) { mtFactory = ReferencingFactoryFinder.getMathTransformFactory(hints); crsFactory = ReferencingFactoryFinder.getCRSFactory(hints); datumFactory = ReferencingFactoryFinder.getDatumFactory(hints); }
/** Returns a backing factory from the specified hints. */ private static CoordinateOperationFactory getBackingFactory(final Hints hints) { for (final CoordinateOperationFactory candidate : ReferencingFactoryFinder.getCoordinateOperationFactories(hints)) { if (!(candidate instanceof BufferedCoordinateOperationFactory)) { return candidate; } } // The following is likely to thrown a FactoryNotFoundException, // which is the intended behavior. return ReferencingFactoryFinder.getCoordinateOperationFactory(hints); }
/** * Transform a geometry to EPSG:4326 format with lon/lat coordinate ordering. NOTE: This method * will perform the transform swapping coordinates even if the sourceCrsName is EPSG:4326 * * @param geometry - Geometry to transform * @param sourceCrsName - Source geometry's coordinate reference system * @return Geometry - Transformed geometry into EPSG:4326 lon/lat coordinate system */ public static Geometry transformToEPSG4326LonLatFormat(Geometry geometry, String sourceCrsName) throws GeoFormatException { if (geometry == null) { throw new GeoFormatException("Unable to convert null geometry"); } // If we don't have source CRS just return geometry as we can't transform without that // information if (sourceCrsName == null) { return geometry; } try { CoordinateReferenceSystem sourceCrs = CRS.decode(sourceCrsName); Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); CoordinateReferenceSystem targetCRS = factory.createCoordinateReferenceSystem(EPSG_4326); MathTransform transform = CRS.findMathTransform(sourceCrs, targetCRS); return JTS.transform(geometry, transform); } catch (FactoryException | TransformException e) { throw new GeoFormatException("Unable to convert coordinate to " + EPSG_4326, e); } }
/** Tests the CRS factory. */ @Test public void testCRS() throws FactoryException { CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("http://www.opengis.net/gml", null); GeographicCRS crs; try { crs = factory.createGeographicCRS("CRS:84"); fail(); } catch (NoSuchAuthorityCodeException exception) { // This is the expected exception. assertEquals("CRS:84", exception.getAuthorityCode()); } crs = factory.createGeographicCRS("http://www.opengis.net/gml/srs/crs.xml#84"); assertSame(crs, CRS.decode("http://www.opengis.net/gml/srs/crs.xml#84")); assertSame(crs, CRS.decode("CRS:84")); assertNotSame(crs, DefaultGeographicCRS.WGS84); assertFalse(DefaultGeographicCRS.WGS84.equals(crs)); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); // Test CRS:83 crs = factory.createGeographicCRS("http://www.opengis.net/gml/srs/crs.xml#83"); assertSame(crs, CRS.decode("CRS:83")); assertFalse(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); } }
if(!CRS.equalsIgnoreMetadata(targetCRS, targetGGCRS)&&!CRS.findMathTransform(targetCRS, targetGGCRS).isIdentity()){ throw new IllegalArgumentException(Errors.format(ErrorKeys.ILLEGAL_ARGUMENT_$1,"TargetCRS must be compatible with TargetGG CRS")); if(hints.containsKey(JAI.KEY_INTERPOLATION)) interpolation=(Interpolation) hints.get(JAI.KEY_INTERPOLATION); hints.put(JAI.KEY_INTERPOLATION,interpolation); if (!hints.containsKey(JAI.KEY_BORDER_EXTENDER)) { ReferencingFactoryFinder.getCoordinateOperationFactory(hints); final MathTransformFactory mtFactory; if (factory instanceof AbstractCoordinateOperationFactory) { mtFactory = ((AbstractCoordinateOperationFactory) factory).getMathTransformFactory(); } else { mtFactory = ReferencingFactoryFinder.getMathTransformFactory(hints); if (CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { final CoordinateOperation operation = factory.createOperation(sourceCRS, targetCRS); final boolean force2D = (sourceCRS != compatibleSourceCRS); step2 = factory.createOperation(targetCRS, compatibleSourceCRS).getMathTransform(); step3 = (force2D ? sourceGG.getGridToCRS2D(CORNER) : sourceGG.getGridToCRS(CORNER)).inverse(); sourceEnvelope = sourceCoverage.getEnvelope(); // Don't force this one to 2D.
/** Tests fetching the URN authority when the "longitude first axis order" hint is set. */ @Test public void testWhenForceXY() throws FactoryException { try { Hints.putSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING, "http"); Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); try { ReferencingFactoryFinder.getCRSAuthorityFactory("URN:OGC:DEF", null); fail("URN factory should not accept FORCE_LONGITUDE_FIRST_AXIS_ORDER = TRUE"); } catch (FactoryNotFoundException e) { // This is the expected exception. } CoordinateReferenceSystem crs = CRS.decode("URN:OGC:DEF:CRS:CRS:84", true); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); crs = CRS.decode("URN:OGC:DEF:CRS:CRS:84"); assertTrue(CRS.equalsIgnoreMetadata(DefaultGeographicCRS.WGS84, crs)); } finally { Hints.removeSystemDefault(Hints.FORCE_AXIS_ORDER_HONORING); Hints.removeSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER); } } }
protected void setUp() throws Exception { super.setUp(); target = CRS.decode("EPSG:3005"); MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(crs, target) .getMathTransform(); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); }
sameCRS = CRS.equalsIgnoreMetadata(targetCRS, sourceCRS); if (sameGG && sameCRS) { return sourceCoverage; final Object property = (hints != null) ? hints.get(Hints.JAI_INSTANCE) : null; if (property instanceof JAI) { processor = (JAI) property; ReferencingFactoryFinder.getCoordinateOperationFactory(hints); final MathTransformFactory mtFactory = ReferencingFactoryFinder.getMathTransformFactory(hints); gridRange = CRS.transform(allSteps.inverse(), gridRange); targetGG = new GridGeometry2D(new GeneralGridRange(gridRange), step1, targetCRS); step2 = factory.createOperation(targetCRS, sourceCRS).getMathTransform(); step3 = sourceGG.getGridToCRS().inverse(); sourceEnvelope = sourceCoverage.getEnvelope(); targetEnvelope = CRS.transform(step2.inverse(), sourceEnvelope); targetEnvelope.setCoordinateReferenceSystem(targetCRS);
@BeforeClass public static void setupCRS() throws FactoryException { CRS.reset("all"); Hints.putSystemDefault(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); // the following is only to make the test work in Eclipse, where the test // classpath is tainted by the test classpath of dependent modules (whilst in Maven it's // not) Set<CRSAuthorityFactory> factories = ReferencingFactoryFinder.getCRSAuthorityFactories(null); for (CRSAuthorityFactory factory : factories) { if (factory.getClass().getSimpleName().equals("EPSGCRSAuthorityFactory")) { ReferencingFactoryFinder.removeAuthorityFactory(factory); } } assertEquals( AxisOrder.NORTH_EAST, CRS.getAxisOrder(CRS.decode("urn:ogc:def:crs:EPSG::4326"))); }
/** Tests a transformation on a {@link DirectPosition} object. */ @Test public void testDirectPositionTransform() throws FactoryException, TransformException { CoordinateReferenceSystem crs = ReferencingFactoryFinder.getCRSFactory(null).createFromWKT(WKT.UTM_10N); MathTransform t = ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(DefaultGeographicCRS.WGS84, crs) .getMathTransform(); DirectPosition position = new GeneralDirectPosition(-123, 55); position = t.transform(position, position); position = t.inverse().transform(position, position); assertEquals(-123, position.getOrdinate(0), 1E-6); assertEquals(55, position.getOrdinate(1), 1E-6); }
@BeforeClass public static void setup() throws NoSuchAuthorityCodeException, FactoryException { Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, Boolean.TRUE); CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", hints); PROJ_EPSG4326_CRS = (AbstractReferenceSystem) factory .createCoordinateReferenceSystem(PROJ_EPSG4326); PROJ_EQUIV_EPSG4326_CRS = (AbstractReferenceSystem) CRS.parseWKT(PROJ_EQUIV_EPSG4326); }
this.imageToMap = imageToMap; setMapCRS(mapCRS); org.opengis.referencing.datum.Ellipsoid gtEllipsoid = CRS.getEllipsoid(mapCRS); String ellipsoidName = gtEllipsoid.getName().getCode(); Ellipsoid ellipsoid = new Ellipsoid(ellipsoidName, MathTransform map2Geo = CRS.findMathTransform(mapCRS, getGeoCRS(), true); Hints hints = new Hints(Hints.LENIENT_DATUM_SHIFT, Boolean.TRUE); final CoordinateOperationFactory factory = ReferencingFactoryFinder.getCoordinateOperationFactory(hints); final MathTransformFactory mtFactory; if (factory instanceof AbstractCoordinateOperationFactory) { mtFactory = ((AbstractCoordinateOperationFactory) factory).getMathTransformFactory(); } else { mtFactory = ReferencingFactoryFinder.getMathTransformFactory(hints);
final CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84; final CoordinateReferenceSystem targetCRS = crsFactory.createFromWKT(WKT.UTM_58S); CoordinateOperation operation = opFactory.createOperation(sourceCRS, targetCRS); if (usingDefaultFactory) { assertSame(sourceCRS, operation.getSourceCRS()); assertSame(targetCRS, operation.getTargetCRS()); assertTrue( operation .getCoordinateOperationAccuracy() .contains(PositionalAccuracyImpl.DATUM_SHIFT_APPLIED)); assertFalse( ReferencingFactoryFinder.getCoordinateOperationFactory(hints); assertNotSame(opFactory, lenientFactory); operation = lenientFactory.createOperation(sourceCRS, targetCRS); if (usingDefaultFactory) { assertSame(sourceCRS, operation.getSourceCRS());
protected void setUp() throws Exception { super.setUp(); target = CRS.parseWKT( "PROJCS[\"BC_Albers\",GEOGCS[\"GCS_North_American_1983\",DATUM[\"North_American_Datum_1983\",SPHEROID[\"GRS_1980\",6378137,298.257222101],TOWGS84[0,0,0]],PRIMEM[\"Greenwich\",0],UNIT[\"Degree\",0.017453292519943295]],PROJECTION[\"Albers_Conic_Equal_Area\"],PARAMETER[\"False_Easting\",1000000],PARAMETER[\"False_Northing\",0],PARAMETER[\"Central_Meridian\",-126],PARAMETER[\"Standard_Parallel_1\",50],PARAMETER[\"Standard_Parallel_2\",58.5],PARAMETER[\"Latitude_Of_Origin\",45],UNIT[\"Meter\",1],AUTHORITY[\"EPSG\",\"42102\"]]"); MathTransform2D tx = (MathTransform2D) ReferencingFactoryFinder.getCoordinateOperationFactory(null) .createOperation(crs, target) .getMathTransform(); transformer = new GeometryCoordinateSequenceTransformer(); transformer.setMathTransform(tx); transformer.setCoordinateReferenceSystem(target); }
/** * Creates a new instance of GeoTiffMetadata2CRSAdapter * * @param hints * a map of hints to locate the authority and object factories. * (can be null) */ public GeoTiffMetadata2CRSAdapter(Hints hints) { final Hints tempHints = hints != null ? new Hints(hints) : DEFAULT_HINTS; this.hints = (Hints) tempHints.clone(); allAuthoritiesFactory = hints != null ? new AllAuthoritiesFactory(this.hints): DEFAULT_ALLAUTHORITIES_FACTORY; // factory = new ThreadedEpsgFactory(hints); datumObjFactory = ReferencingFactoryFinder.getDatumFactory(this.hints); crsFactory = ReferencingFactoryFinder.getCRSFactory(this.hints); csFactory = ReferencingFactoryFinder.getCSFactory(this.hints); tempHints.put(Hints.DATUM_AUTHORITY_FACTORY, allAuthoritiesFactory); tempHints.put(Hints.CS_FACTORY, csFactory); tempHints.put(Hints.CRS_FACTORY, crsFactory); tempHints.put(Hints.MATH_TRANSFORM_FACTORY, mtFactory); factories = ReferencingFactoryContainer.instance(tempHints); }
static List<CrsInfo> generateCRSList() { // todo - (mp/mz) this method takes time (2 sec.) try to speed up Hints hints = new Hints(Hints.FORCE_LONGITUDE_FIRST_AXIS_ORDER, true); Set<CRSAuthorityFactory> factories = ReferencingFactoryFinder.getCRSAuthorityFactories(hints); final List<CRSAuthorityFactory> filtered = new ArrayList<CRSAuthorityFactory>(); for (final CRSAuthorityFactory factory : factories) { if (Citations.identifierMatches(factory.getAuthority(), AUTHORITY)) { filtered.add(factory); } } CRSAuthorityFactory crsAuthorityFactory = FallbackAuthorityFactory.create(CRSAuthorityFactory.class, filtered); Set<String> codes = new HashSet<String>(); List<CrsInfo> crsList = new ArrayList<CrsInfo>(1024); retrieveCodes(codes, GeodeticCRS.class, crsAuthorityFactory); retrieveCodes(codes, ProjectedCRS.class, crsAuthorityFactory); for (String code : codes) { final String authCode = String.format("%s:%s", AUTHORITY, code); crsList.add(new CrsInfo(authCode, crsAuthorityFactory)); } codes.clear(); AutoCRSFactory autoCRSFactory = new AutoCRSFactory(); retrieveCodes(codes, ProjectedCRS.class, autoCRSFactory); for (String code : codes) { final String authCode = String.format("AUTO:%s", code); crsList.add(new AutoCrsInfo(authCode, autoCRSFactory)); } Collections.sort(crsList); return crsList; }