Hi Jody: If I understand geotools, the transform among world coordinates and screen coordinates ought can be done using the world CRS, the screen CRS and a MathTransform. E.g (probably not working code):
-- MathTransform world2screen = CRS.findMathTransform(worldCRS, screenCRS); DirectPosition dpScreen = world2screen.transform(dpWorld, null); // Where dpScreen, dpWorld are DirectPosition objects. dpWorld in worldCRS coordinates and dpScreen will have screenCRS coordinates when created. -- The question here is: How can I get a screen CRS? In the UserGuide's example code this isn't done with a MathTransform (it user an AffineTransform an I think that this way isn't clear). I we could define a screen CRS the transform operations will be elegant and we could forget the axis selection thing. P.S. The RendererUtilities.worldToScreenTransform[1] is really obscure. If you want to understand it you must jump to one thousand diferent places :) [1] http://svn.geotools.org/geotools/branches/2.3.x/module/render/src/org/geotools/renderer/lite/RendererUtilities.java On Tue, January 22, 2008 03:44, Jody Garnett wrote: > Diego Fdez. Durán wrote: >> If rewrite the example code so I can transform among screen and world >> coordinates and back in a cleaner way, and fix many syntax errors in the >> example. >> >> I'm waiting for your comments :) >> > Cool! > > So what I would need to do; is break down what world2screen is doing (it > is doing something!). And show people how to do it step by step .. in > the reverse order. I have not looked at the code yet so I am not sure. >> private void updateTransforms() { >> try { >> world2screen = >> RendererUtilities.worldToScreenTransform(mapContext.getLayerBounds(), >> new Rectangle(panelMap.getWidth(), panelMap.getHeight())); >> screen2world = world2screen.createInverse(); >> } catch (IOException ex) { >> } catch (NoninvertibleTransformException ex) { >> } >> } >> > There are several transform methods; I think there is a way to transform > the provided DirectPosition( ie point) in one step. If we can do that > we never have to look at what axis is X and what axis is Y; and we will > be doing this properly. > - > http://geoapi.sourceforge.net/snapshot/javadoc/org/opengis/referencing/operation/MathTransform.html >> /* >> * "point" has the point coordinates in world UTM coordinate reference >> * system. >> */ >> private void drawPoint(Graphics g, DirectPosition point) { >> > DirectPosition positionScreen = world2screen.transform( point, null ); > Point2D pointScreen = new Point( (int) point.getOrdinate(0), > point.getOrdinate(1) ); >> int ovalSize = 20; >> Color colorPrevious = g.getColor(); // Save previous color >> g.setColor(Color.BLACK); // "Point" color >> g.fillOval((int) (pointScreen.getX() - ovalSize / 2), >> (int) (pointScreen.getY() - ovalSize / 2), >> ovalSize, >> ovalSize); >> g.setColor(colorPrevious); // Restore color >> } >> > > -- Diego Fdez. Durán <[EMAIL PROTECTED]> | http://www.goedi.net GPG : 925C 9A21 7A11 3B13 6E43 50DB F579 D119 90D2 66BB ------------------------------------------------------------------------- This SF.net email is sponsored by: Microsoft Defy all challenges. Microsoft(R) Visual Studio 2008. http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ _______________________________________________ Geotools-gt2-users mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users
