Added by jgarnett, last edited by jgarnett on Jul 26, 2007  (view change)

Labels

 
(None)

Deep behind that CRS utility class is an amazing constellation of "factories" used to define what a CoordinateReferenceSystem is, actually create the parts and stitch them all together in a unified whole.

Please note:

Meet Referencing Factory Classes

The Authorities

These things are factories in name only; their real job is to supply the definitions (in pattern speak they are considered builders).

Class Description
DatumAuthorityFactory Defines a Datum using a code provided by a authority such as EPSG
CSAuthorityFactory Defines a CoordinateSystem using a code provided by an authority such as EPSG
CRSAuthorityFactory Defines a CoordinateReferenceSystem for a give authority (such as EPSG)
CoordinateOperationAuthorityFactory Defines coordinate operations from codes, backed by math transforms

To actually create stuff these authorities acquire a definition and then call a "real" factory class as described in the next section.

Getting the EPSG AuthorityFactory

You can make direct use of the CRSAuthorityFactory configured to handle "EPSG" codes:

CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", null);
CoordinateReferenceSystem crs = factory.createCoordinateReferenceSystem("4326");

You will need to make sure that one of the epsg plugins is on your CLASSPATH (such as epsg-hsql).

Finding the available EPSG Codes

CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", null);
Set<String> authorityCodes = factory.getAuthorityCodes(CoordinateReferenceSystem.class);

Getting Other AuthorityFactory Instances

Here are several more examples that are understood by GeoTools:

Hints hints = null; // Put optional hints here.
CRSAuthorityFactory crsAuthority  = ReferencingFactoryFinder.getCRSAuthorityFactory("CRS",   hints);
CRSAuthorityFactory wms2Authority = ReferencingFactoryFinder.getCRSAuthorityFactory("AUTO",  hints);
CRSAuthorityFactory wms3Authority = ReferencingFactoryFinder.getCRSAuthorityFactory("AUTO2", hints);

IdentifiedObject Finder for Controlled Searching

One bit of functionality that is not available via the CRSAuthority interfaces directly is the ability to carefully search through all the available definitions.

CRSAuthorityFactory factory = ReferencingFactoryFinder.getCRSAuthorityFactory("EPSG", null);
AbstractAuthorityFactory custom = (AbstractAuthorityFactory) factory;

IdentifiedObjectFinder finder = custom.getIdentifiedObjectFinder(CoordinateReferenceSystem.class);

finder.setFullScanAllowed(true); // will search everything ever defined (may be slow)
IdentifiedObject find = finder.find(crs);

finder.setFullScanAllowed(false); // will limit search to what has been cached in memory
IdentifiedObject find = finder.find(crs);

As shown above this is additional functionality made avaialble through AbstractAuthorityFactory - it is not part of the normal GeoAPI interfaces.

You can construct finders to search through other categories of referencing Objects (like Datum and ReferencingSystem).