[geotk] Identifying projection types on CRS

Martin Desruisseaux martin.desruisseaux at geomatys.fr
Tue Apr 26 05:54:37 EDT 2011


Hello Aaron

The best way to identify the projection type would be to check the name (as 
returned by the getName() method) of the OperationMethod. The operation names 
are also implementation independant, as opposed to instanceof checks. The 
operation method names are somewhat standardized in various ways. The most 
reliable names are the "/OGC WKT Name/" available from this page:

    * http://www.remotesensing.org/geotiff/proj_list/


Click on any projection in the above page, then look for "/OGC WKT Name/" in the 
table.

The EPSG database also defines its own set of projection names, but they may 
vary in different version of the EPSG database. For example the operation method 
name for the Mercator projection changed between EPSG 7.5 and EPSG 7.6, which 
required some adaptation in the Geotoolkit.org code. GeoTIFF also have its own 
operation method names.

For each projection supported by Geotk, the various operation method names are 
available (indirectly) in the PARAMETERS constant defined in each class of the 
following package:

    * http://www.geotoolkit.org/apidocs/org/geotoolkit/referencing/operation/provider/package-summary.html


Using this approach, the following code should work no matter if the 
OperationMethod uses the OGC or EPSG name, because the 
AlbersEqualArea.PARAMETERS know both of them and the nameMatches convenience 
method checks all of them.

ProjectedCRS crs = ...;
OperationMethod method = crs.getConversionFromBase().getMethod();
if (AbstractIdentifiedObject.nameMatches(method, AlbersEqualArea.PARAMETERS)) {
     // Do some stuff here...
}


I will add this topic in the Referencing FAQ, since it is non-obvious :).

Regards,

     Martin




Le 26/04/11 04:42, Aaron Braeckel a écrit :
> Hello,
>
> I'd like to be able to programmatically detect certain ProjectedCRS types, 
> such as LambertConformal and Mercator.  Here is the code I was hoping to use:
>
> CoordinateReferenceSystem crs = ...;
> CoordinateReferenceSystem horizCrs = CRS.getHorizontalCRS( crs );
> //magic occurs
> if( myOperationMethod instanceof AlbersEqualArea ){
>    //do something extraordinarily amazing
> }
>
> I have yet to find a clear way to do something like this.  When I receive 
> ProjectedCRSs I have yet to find any classes from the 
> org.geotoolkit.referencing.operation.projection package anywhere, just 
> general-purpose instances.  In digging around it seems as if there are 
> multiple paths that could be taken to try to identify the 
> operationMethod/mathTransform/etc.
>
>    1. Use identifiers (EPSG:9807, for example).  Not sure where in the Geotk
>       hierarchy of instances would be best to do so
>    2. Instantiate an instance of a projected type (AlbersEqualArea.class) and
>       use one of the weak .equals() calls
>    3. Get an instance of a projected type (AlbersEqualArea.class) from the
>       horizontal CRS somehow
>
> Any thoughts?
>
> Thanks,
> Aaron



More information about the Geotoolkit mailing list