|
From: Martin D. <mar...@te...> - 2004-06-20 19:08:06
|
Casson Stallings a =E9crit :
> public void mouseClicked(MouseEvent event) {
> java.awt.geom.Point2D pnt =3D null;
> java.awt.geom.Point2D pnt2 =3D null;
> GeoMouseEvent e =3D (GeoMouseEvent) event;
> if (pnt !=3D null) {
> try {
> pnt2 =3D e.getMapCoordinate(mapcs,pnt);
> jb.setText(pnt2.toString());
> }
> catch(TransformException te) {
> jb.setText("CS Transform Exception");
> System.err.println(te.getMessage());
> }
> repaint();
> }
> }
I guess than in the above, 'getMapCoordinate' was really 'getCoordinate'=20
since the 'getMapCoordinate' method doesn't expect a CS argument.
'getCoordinate' is for getting the mouse location in some arbitrary CS,=20
which may or may not be the CS of yours data. The transformation will be=20
applied automatically as needed.
'getMapCoordinate' is for getting the mouse location in the CS used by=20
the renderer. In my understanding of what you are tring to do, all you=20
need to write is:
> public void mouseClicked(MouseEvent event) {
> GeoMouseEvent e =3D (GeoMouseEvent) event;
> Point2D pnt =3D null;
> pnt =3D e.getMapCoordinate(pnt);
> jb.setText(pnt2.toString());
> }
As a side note, if you want a nicer formatting of yours coordinate,=20
looks at the MouseCoordinateFormat class :).
However, the above will work only if the renderer is set to the proper=20
CS. I suggest that you try the following:
System.out.println(renderer.getCoordinateSystem());
and verify if the renderer's CS is really the one you intented to be.
By default, the renderer is initialized with the same CS than the=20
underlying data. The problem is that current implementation of DataStore=20
in Geotools has no notion of CS, so the renderer is unable to guess what=20
the CS is and will often default to some cartesian CS, which are=20
probably not the one you wanted. The real fix is to set the DataStore's=20
CS to the one of yours data, but I don't know how to do this part (we=20
need to ask to DataStore specialists).
> 1. Should I be setting the coordinate system to StatePlane using=20
> org.geotools.j2d.Renderer.setCoordinateSystem. If I do this just it jus=
t=20
> say what the coordinates are, or does it try to transform things?
We may try that, but I'm not sure how the renderer will react if it=20
believe that this CS is not the same one than the data CS. Is said=20
previously, the real fix is to specify the data CS, which should=20
probably be done at the DataStore level.
> 2. If I have the renderer set to a specific coordinate system, will dat=
a=20
> in other coordinate systems be automatically transformed, or do I=20
> need to build the transformation mannually?
All transformations are handled automatically, providing that the CS as=20
been set in the data of course.
> 3. If data is automatically transformed, how to I associate a coordinat=
e=20
> system with a dataset or datastore?
Thats the question! We need DataStore specialist advise here.
> 4. If I use GeoMouseEvent.getMapCoordinate(coordinate system, point) (I=
=20
> am not sure on the exact syntax.) Does this convert the coordinate from=
=20
> the Renderer map coordinates to the specified coordinate system coordin=
ates?
Yes. Note that the real syntax is:
getCoordinate(CoordinateSystem, Point2D);
If you know that you want the data in the renderer's CS rather than an=20
arbitrary one, the following method is more convenient:
getMapCoordinate(Point2D);
Hope its help :)
Martin.
|