From: Michael B. <mic...@gm...> - 2011-11-17 23:32:01
|
Hello Danilo, It seems to be related to the definition of the Google projection. The snippet below uses EPSG:4326 instead and the results are fine. However, I've no idea exactly what the problem is. Perhaps Andrea (referencing module maintainer) can comment. Coordinate[] coordinates = new Coordinate[]{ new Coordinate(-49.00, -16.683), new Coordinate(-49.300, -16.675)}; Geometry geom = new GeometryFactory().createLineString(coordinates); CoordinateReferenceSystem geo = CRS.decode("EPSG:4326", true); CoordinateReferenceSystem utm = CRS.decode("EPSG:31982", true); MathTransform trForward = CRS.findMathTransform(geo, utm); Geometry geomForward = JTS.transform(geom, trForward); MathTransform trBack = CRS.findMathTransform(utm, geo); Geometry geomBack = JTS.transform(geomForward, trBack); System.out.println(geom); System.out.println(geomForward); System.out.println(geomBack); Michael On 18 November 2011 00:21, Danilo Marques de Rezende <dan...@gm...> wrote: > Hello, > I am trying to make some coordinates converstion from mercator to utm, and > it seens > that I make something wrong. > To make sure the convertion is correct, I tryed to convert back to mercator. > Here is the code that I used: > ... > //tryed using coordinates lat,lon as x,y; and lat,lon as y,x > Coordinate[] coordinates = new Coordinate[] { > new Coordinate(-49.00, -16.683), > new Coordinate(-49.300, -16.675)}; > Geometry g3 = new GeometryFactory().createLineString(coordinates); > sourceCRS = CRS.decode("EPSG:3785"); // Mercator/google maps code > targetCRS = CRS.decode("EPSG:31982"); // UTM 22s code > from http://www.epsg-registry.org/ > MathTransform tx = CRS.findMathTransform(CRSFrom, CRSTo, true); > Geometry transformed = JTS.transform(geom, transform) > The result is this: > first convertion to utm coodinates: > [(6120584.969417981, 1.0000023079023875E7, NaN), > (6120584.546247176, 1.0000023090352934E7, NaN)] > convertion back to Mercator: > [(-8997.836054457479, -17.077226626756676, NaN), > (-8998.130646014215, -17.069201880507137, NaN)] > Am I doing something wrong? > Thanks, > -- > Danilo Marques > > ------------------------------------------------------------------------------ > All the data continuously generated in your IT infrastructure > contains a definitive record of customers, application performance, > security threats, fraudulent activity, and more. Splunk takes this > data and makes sense of it. IT sense. And common sense. > http://p.sf.net/sfu/splunk-novd2d > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > > |