From: Michael B. <mic...@gm...> - 2011-07-29 02:33:54
|
Hi Mike, Two issues here... Firstly, on the code not working, it looks like a bug in the JTS.transform method. It is allocating an array for the destination ordinates based on the number of sourceCRS dimensions (2 in this case) but it should be based on the number of target CRS dimensions instead. I'll create an issue for it. Meanwhile here is a work-around... private double[] latLongToCartesian(double longitude, double latitude) throws Exception { CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84; CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN; MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, false); double[] srcPt = {longitude, latitude}; double[] dstPt = new double[transform.getTargetDimensions()]; transform.transform(srcPt, 0, dstPt, 0, 1); return dstPt; } Secondly, and more importantly, I don't think you want to do this :) You could just plot them directly, especially if your points are close together, unless you are working close to a pole in which case you could choose an appropriate projected CRS to minimize distortion. If the points are dotted around the world you might want to choose something like the Robinson projection. Hope this helps, Michael On 29 July 2011 07:03, Mike O'Toole <mon...@gm...> wrote: > Hello All, > > I'm having an issue with a point transformation. > > I'm using 8.0-M1 to preform a transformation from WGS84 to a Cartesian system suitable for plotting points on a 2d graph. I know the DefaultGeocentricCRS.CARTESIAN uses a 3D system. What type of geometry should I be transforming this into? I will want to use this to plot on an x,y graph. Right now the last line of code produces the error. > > Thanks > Mike > > Code: > > Coordinate coord = new Coordinate(longitude, latitude ); > Point geoPoint = geometryFactory.createPoint( coord ); > > CoordinateReferenceSystem sourceCRS = DefaultGeographicCRS.WGS84; > CoordinateReferenceSystem targetCRS = DefaultGeocentricCRS.CARTESIAN; > > MathTransform transform = CRS.findMathTransform(sourceCRS, targetCRS, false); > Point targetGeometry = (Point) JTS.transform(geoPoint, transform); > > > Error: > > Exception: java.lang.IllegalArgumentException > Message: dimension must be <= 3 > Stack trace: > > com.vividsolutions.jts.geom.impl.CoordinateArraySequenceFactory.create(CoordinateArraySequenceFactory.java:90) > org.geotools.geometry.jts.DefaultCoordinateSequenceTransformer.transform(DefaultCoordinateSequenceTransformer.java:92) > org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.projectCoordinateSequence(GeometryCoordinateSequenceTransformer.java:185) > org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transformPoint(GeometryCoordinateSequenceTransformer.java:172) > org.geotools.geometry.jts.GeometryCoordinateSequenceTransformer.transform(GeometryCoordinateSequenceTransformer.java:87) > org.geotools.geometry.jts.JTS.transform(JTS.java:240) > edu.agrid.sensorbar.CalcSensorLatLonExtension.convertCRS(CalcSensorLatLonExtension.java:242) > edu.agrid.sensorbar.CalcSensorLatLonExtension.doWork(CalcSensorLatLonExtension.java:166) > com.rapidminer.operator.Operator.execute(Operator.java:829) > com.rapidminer.operator.execution.SimpleUnitExecutor.execute(SimpleUnitExecutor.java:51) > com.rapidminer.operator.ExecutionUnit.execute(ExecutionUnit.java:709) > com.rapidminer.operator.OperatorChain.doWork(OperatorChain.java:376) > com.rapidminer.operator.Operator.execute(Operator.java:829) > com.rapidminer.Process.run(Process.java:899) > com.rapidminer.Process.run(Process.java:795) > com.rapidminer.Process.run(Process.java:790) > com.rapidminer.Process.run(Process.java:780) > com.rapidminer.gui.ProcessThread.run(ProcessThread.java:75) > ------------------------------------------------------------------------------ > Got Input? Slashdot Needs You. > Take our quick survey online. Come on, we don't ask for help often. > Plus, you'll get a chance to win $100 to spend on ThinkGeek. > http://p.sf.net/sfu/slashdot-survey > _______________________________________________ > Geotools-gt2-users mailing list > Geo...@li... > https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users > |