[geotk] Concerting Coordinates between custom Transverse Mercator and WGS84 Lon-Lat

dan twining dantwining at googlemail.com
Thu Mar 4 04:08:56 EST 2010


Hi Martin,

Thanks for your reply. It turns out that the exception is caused by a weird
interaction between GTK and the GWT (Google Web Toolkit) "devmode" (the
coordinate conversion is happening in the back-end of a GWT/Java web app).
For the record, this is the exception:

Caused by: java.lang.RuntimeException: java.lang.ClassCastException: class
org.geotoolkit.referencing.operation.DefaultMathTransformFactory
     at com.example.LonLatConverter.toLonLat(LonLatConverter.java:47)
...

Caused by: java.lang.ClassCastException: class
org.geotoolkit.referencing.operation.DefaultMathTransformFactory
     at java.lang.Class.asSubclass(Class.java:3018)
     at
org.geotoolkit.factory.FactoryRegistry.register(FactoryRegistry.java:921)
    at
org.geotoolkit.factory.FactoryRegistry.scanForPlugins(FactoryRegistry.java:793)

    at
org.geotoolkit.factory.FactoryRegistry.scanForPluginsIfNeeded(FactoryRegistry.java:843)

    at
org.geotoolkit.factory.FactoryRegistry.getServiceProviders(FactoryRegistry.java:236)

    at
com.example.LonLatConverter.getMathTransformFactory(LonLatConverter.java:71)

    at com.example.LonLatConverter.toLonLat(LonLatConverter.java:35)
...

My current work-around is to use the GWT Eclipse Plug-in. That doesn't throw
the exception, nor does building the war and deploying the web-app to either
Tomcat or Jetty. All very strange, but I'm happy to ignore it for now.

Thanks again for your help,

dan


On 3 March 2010 12:35, Martin Desruisseaux
<martin.desruisseaux at geomatys.fr>wrote:

> Hello Dan
>
> I just tried to executed the code snippet that you sent, replacing
> "GeoLocation" and "Vector2D" by Point2D.Double since I do not have those
> classes. I did not get any exception. However there is some tips that may
> make things easier (I will add them to the referencing FAQ later).
>
>
> Le 03/03/10 12:15, dan twining a écrit :
>
>> public GeoLocation toLonLat(Vector2D location) {
>>  (...snip...)
>>
>>  MathTransform tr = getMathTransform(factory);
>>  DirectPosition sourcePt = new GeneralDirectPosition(location.getX(),
>> location.getY());
>>  DirectPosition targetPt = tr.transform(sourcePt, null);
>>  (...snip...)
>> }
>>
>
> It is worth to point out that this method is called "toLonLat" but is
> actually projecting from "geographic" to UTM, since the map projection
> created in the "getMathTransform()" method. Not sure if it is relevant...
>
>
>  private MathTransformFactory getMathTransformFactory() {
>>  if (factory == null) {
>>    FactoryRegistry registry = new
>> FactoryRegistry(MathTransformFactory.class);
>>    factory = registry.getServiceProvider(MathTransformFactory.class, ...);
>>  }
>>  return factory;
>> }
>>
>
> Mentioning just in case, you can also just invoke the
> FactoryFinder.getMathTransformFactory(null) static method.
>
>
> http://www.geotoolkit.org/apidocs/org/geotoolkit/factory/FactoryFinder.html#getMathTransformFactory%28org.geotoolkit.factory.Hints%29
>
> A note about the getMathTransform(...) method. The code snippet that you
> send it correct (if you still have the ClassCastException, maybe posting the
> stack trace would help?) Just mentioning in case, an alternative is also to
> apply the usual 2 step approach:
>
> 1) Define your source and target CRS where:
>  - The source is DefaultGeographicCRS.WGS84
>  - The target can be created with either of the following:
>    * CRS.decode("EPSG:" + (32600 + zone)) where 'zone' is
>      the UTM zone (this require the EPSG database - use
>      32700 instead of 32600 if you want South hemisphere);
>    * CRS.decode("AUTO:42002,long,lat") where 'long' and 'lat'
>      are your central latitude and meridian.
>
> 2) Get your MathTransform with CRS.findMathTransform(sourceCRS,
>   targetCRS);
>
> This is more heavy than your approach (use it only if performance is not
> critical in this area of your code), but using CoordinateReferenceSystem
> objects that you can associate with your coordinates is often a recommanded
> approach, a little bit like associating Unit with measurement values.
>
>        Regards,
>
>                Martin
> _______________________________________________
> Geotoolkit mailing list
> Geotoolkit at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/geotoolkit
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osgeo.org/pipermail/geotoolkit/attachments/20100304/bee21191/attachment.html


More information about the Geotoolkit mailing list