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 :)
-- CODE
// Class vars
private AffineTransform world2screen;
private AffineTransform screen2world;
private panelMap // Extends from JPanel. The map is drawn over it
// overwriting paintComponent.
private void updateTransforms() {
try {
world2screen =
RendererUtilities.worldToScreenTransform(mapContext.getLayerBounds(),
new Rectangle(panelMap.getWidth(), panelMap.getHeight()));
screen2world = world2screen.createInverse();
} catch (IOException ex) {
} catch (NoninvertibleTransformException ex) {
}
}
/*
* "point" has the point coordinates in world UTM coordinate reference
* system.
*/
private void drawPoint(Graphics g, DirectPosition point) {
final int X = indexOfX(point.getCoordinateReferenceSystem());
final int Y = indexOfY(point.getCoordinateReferenceSystem());
Point pointWorld = new Point((int) point.getOrdinate(X), (int)
point.getOrdinate(Y));
Point2D pointScreen = world2screen.transform(pointWorld,
null);
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
}
private int indexOfX(CoordinateReferenceSystem crs) {
Set<AxisDirection> up = new HashSet<AxisDirection>();
up.add(AxisDirection.DISPLAY_LEFT);
up.add(AxisDirection.EAST);
up.add(AxisDirection.GEOCENTRIC_X);
up.add(AxisDirection.COLUMN_POSITIVE);
return indexOf(crs, up);
}
private int indexOfY(CoordinateReferenceSystem crs) {
Set<AxisDirection> up = new HashSet<AxisDirection>();
up.add(AxisDirection.DISPLAY_UP);
up.add(AxisDirection.NORTH);
up.add(AxisDirection.GEOCENTRIC_Y);
up.add(AxisDirection.ROW_POSITIVE);
return indexOf(crs, up);
}
private int indexOf(CoordinateReferenceSystem crs, Set<AxisDirection>
direction) {
CoordinateSystem cs = crs.getCoordinateSystem();
for (int index = 0; index < cs.getDimension(); index++) {
CoordinateSystemAxis axis = cs.getAxis(index);
if (direction.contains(axis.getDirection())) {
return index;
}
}
return -1;
}
-- END CODE
[1] http://docs.codehaus.org/display/GEOTDOC/04+What+Axis+is
+X#04WhatAxisisX-LookinguptherightAxis
--
Diego Fdez. Durán <[EMAIL PROTECTED]> | http://www.goedi.net
GPG : 925C 9A21 7A11 3B13 6E43 50DB F579 D119 90D2 66BB
signature.asc
Description: Esta parte del mensaje está firmada digitalmente
------------------------------------------------------------------------- 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
