Internal¶
Please note that this page is optional and only for the curious. It covers some of the implementation classes.
A CoordinateReferenceSystem
is a gt-api
interface describing how a set of
ordinates is to be interpreted as a three dimensional point. This definition is standardized,
mathematical and generally not of interest unless something goes wrong.
CoordinateReferenceSystem
¶
For most cases you are only interested in using a CoordinateReferenceSystem
as a parameter to a
mathematical calculation (distance along the surface of the earth and “re-projection”
being the most common).
Creating a CoordinateReferenceSystem
:
CoordinateReferenceSystem crs = CRS.decode("EPSG:26910", false);
You will need to ensure GeoTools is configured with an appropriate plugin for this example to work.
This plugin will provide an CRSAuthorityFactory
registered for “EPSG” codes.
Referencing Factories¶
These are the “real” factories - interfaces that actually create stuff. All are gt-api
interfaces, so you will need
to use ReferencingFactoryFinder
to get started:
DatumFactory
: Makes datums!CSFactory
MakesCoordinateSystem
instances, and many moreCRSFactory
MakesCoordinateReferenceSystem
instances, and many moreMathTransformFactory
MakesMathTransform
instances, and many more
You can quickly grab all four factories at once using ReferencingFactoryContainer
:
Hints hints = null; // configure hints for the group of factories
ReferencingFactoryContainer group = new ReferencingFactoryContainer(hints);
CRSFactory crsFactory = group.getCRSFactory();
CSFactory csFactory = group.getCSFactory();
DatumFactory datumFactory = group.getDatumFactory();
ReferencingFactoryFinder
As is custom we have included a
FactoryFinder
so you can look up a good implementation on the CLASSPATH:DatumFactory datumFactory = ReferencingFactoryFinder.getDatumFactory(null);
The
ReferencingFactoryFinder
returns a couple of GeoTools implementations right now, in the future we hope to replace these defaults with an implementation fromJScience
.ReferencingFactoryContainer
You may have noticed that to actually do anything you need several factories. We have gathered these together into a “container” for you. The container also adds a few more methods which use a couple of factories to gang up on a problem
You can set up
ReferencingFactoryContainer
to use your own custom factory using hints as shown below:Map<Key, Object> map = new HashMap<>(); map.put(Hints.DATUM_FACTORY, datumFactory); map.put(Hints.CS_FACTORY, csFactory); map.put(Hints.CRS_FACTORY, crsFactory); map.put(Hints.MATH_TRANSFORM_FACTORY, mtFactory); Hints hints = new Hints(map); ReferencingFactoryContainer container = new ReferencingFactoryContainer(hints);
Please note that ReferencingFactoryContainer is not strictly needed, it just makes things easier. ReferencingFactoryFinder will be smart and recycle instances where possible:
Hints hints = GeoTools.getDefaultHints(); DatumFactory datumFactory = ReferencingFactoryFinder.getDatumFactory(hints); ReferencingFactoryContainer container = new ReferencingFactoryContainer(hints); if (datumFactory == container.getDatumFactory()) { System.out.println("Will be the same DatumFactory"); }