Hi Duane,

I'm copying your message and code (below) to the list. Your fear of
Jody was obviously too inhibiting...

Andrea, what would be an appropriate way to package Duane's ENU
coordinate code for the referencing module ?

Michael


On 16 June 2010 23:52, Duane Zamrok <[email protected]> wrote:
> Quite right about that whole Australia thing making it hard to link up. I 
> enjoy a proper (GMT-5) here on the US East coast, and am likely logging on as 
> you get ready to call it a night.
>
> Since you don't seem to think Jody will execute me for posting on the wrong 
> userlist, here goes!
>
> The code I've attached at the bottom will convert from WGS84 to ENU. It 
> requires an origin for your ENU plane, and a coordinate that you want 
> transformed. That said, I can't help but think that the PROPER way to do this 
> would be to create a new CoordinateReferenceSystem and then define the 
> transforms from WGS84 and ECEF to that system. I'm not very good with 
> GIS/OGC/Geotools so I'm not sure if that would be a DerivedCRS or a 
> ProjectedCRS. For that matter, there are a lot of abstract CRS 
> implementations and interfaces, but I'm nowhere near good enough with them to 
> choose correctly.
>
> Hopefully the code will be enough for now. However, if you guys want to point 
> me in the right direction, then it's possible to convince me to expand upon 
> this.
>
> Cheers!
> -Duane
>
>
> /***
>  * Converts a {...@link DefaultGeographicCRS#WGS84} longitude latitude 
> position into an ENU position whose origin is provided
>  *
>  * @param origin
>  *            the origin of your ENU plane. This is a {...@link 
> DirectPosition} object whose {...@link CoordinateReferenceSystem} is
>  *           �...@link DefaultGeographicCRS#WGS84}
>  * @param latLong
>  *            this is the point whose ENU position you want to compute. This 
> should be a {...@link DirectPosition} object whose
>  *           �...@link CoordinateReferenceSystem} is {...@link 
> DefaultGeographicCRS#WGS84}
>  *
>  * @return a {...@link DirectPosition} whose {...@link 
> CoordinateReferenceSystem} is null (since I can't find a good ENU CRS)
>  * @throws FactoryException
>  *             This should not happen, but is warranted by
>  *             {...@link CRS#findMathTransform(CoordinateReferenceSystem, 
> CoordinateReferenceSystem)}
>  * @throws TransformException
>  *             This should not happen but is warranted by {...@link 
> MathTransform#transform(DirectPosition, DirectPosition)}.
>  *             Note, the reason it should not happen is because there is 
> already a predefined path between WGS84 and ECEF
>  * @throws MismatchedDimensionException
>  *             This should not happen but is warranted by {...@link 
> MathTransform#transform(DirectPosition, DirectPosition)}.
>  *             Note: It should not happen because if your parameters are 
> actually WGS84 then the dimensions will all be
>  *             proper.
>  */
> public DirectPosition toENU(DirectPosition origin, DirectPosition latLong) 
> throws FactoryException, MismatchedDimensionException, TransformException
> {
>        // This has the potential to throw an exception, but never should.
>        // By default there is a predefined transform path between WGS84 and 
> ECEF
>        MathTransform ecefTransform = 
> CRS.findMathTransform(DefaultGeographicCRS.WGS84, 
> DefaultGeocentricCRS.CARTESIAN);
>
>        DirectPosition ecefOrigin = ecefTransform.transform(origin, null);
>        DirectPosition ecefLatLong = ecefTransform.transform(latLong, null);
>
>        double deltaX = ecefLatLong.getOrdinate(0) - ecefOrigin.getOrdinate(0);
>        double deltaY = ecefLatLong.getOrdinate(1) - ecefOrigin.getOrdinate(1);
>        double deltaZ = ecefLatLong.getOrdinate(2) - ecefOrigin.getOrdinate(2);
>
>        // Get the sin/cos information for the origin
>        double sinLat = Math.sin(origin.getOrdinate(1)); // sin(latitude)
>        double cosLat = Math.cos(origin.getOrdinate(1)); // cos(latitude)
>
>        double sinLong = Math.sin(origin.getOrdinate(0)); // sin(longitude)
>        double cosLong = Math.cos(origin.getOrdinate(0)); // cos(longitude)
>
>        // Transform the ECEF
>        double x = (deltaY * cosLong) - (deltaX * sinLong);
>        double y = (deltaZ * cosLat) - (deltaX * sinLat * cosLong) - (deltaY * 
> sinLat * sinLong);
>        double z = (deltaX * cosLat * cosLong) + (deltaY * cosLat * sinLong) + 
> (deltaZ * sinLat);
>
>        // Return a result
>        return new GeneralDirectPosition(x, y, z);
> }
>
>

------------------------------------------------------------------------------
ThinkGeek and WIRED's GeekDad team up for the Ultimate 
GeekDad Father's Day Giveaway. ONE MASSIVE PRIZE to the 
lucky parental unit.  See the prize list and enter to win: 
http://p.sf.net/sfu/thinkgeek-promo
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to