Hi Cintia
> I apologize about my bet trouble with the translation.
> I hope you would be better.
No worries :)
> That's right, I've a map in lat-lon and I want to go by clicking on
> different points of the map and getting to go the distance in meters.I need
> too that the lines be drawn between these points.I've done it for web (as in
> the example image I'm sending) to the desktop now, I'm without idea of how
> to do this.
OK. There are different ways of doing it so you'll need to choose the
one that is best for you.
If the distances are small (local area or small region) then you might
want to just reproject your map context into a CRS that has metres as
the distance unit. You can see this in the CRS Lab example:
http://geotools.org/examples/crslab.htmlFor example, if I wanted to do this for my local area (Sydney) I could
use UTM Zone 56S (EPSG:32756). Now my map display is in metres so I
can retrieve the location of mouse clicks and calculate the distance.
You can get the mouse click coordinates by using MapMouseAdapter..
http://geotools.org/javadocs/org/geotools/swing/event/MapMouseAdapter.htmlor you could also use CursorTool...
http://geotools.org/javadocs/org/geotools/swing/tool/CursorTool.htmlIf you have a look at the Selection Lab example you will see how a
CursorTool is being used there and how the click coordinates are
retrieved...
http://geotools.org/javadocs/org/geotools/swing/tool/CursorTool.htmlNow, if you are working with a large area (very large region,
continental scale) then just reprojecting into UTM won't be accurate.
In this case you are better off keeping your map display in lat/long
WGS84 and using the GeodeticCalculator class to work out the distance
between points...
http://geotools.org/javadocs/index.html?org/geotools/referencing/GeodeticCalculator.htmlThis class can also generate a path between two points for you.
For drawing the lines, once again you have different options :-)
You could create a new FeatureCollection for your lines and add that
as a map layer, save it as a shapefile etc.
Another option is to just draw the lines on top of the map pane. For
that you will have to subclass JMapPane and override its
paintComponent method...
public class MyPane extends JMapPane {
@override
public paintComponent(Graphics gr) {
// first let the pane paint the map
super.paintComponent(gr);
// now draw your lines...
Graphics2D g2 = (Graphics2D) getGraphics();
... your line drawing code using Graphics2D methods
}
}
You can use the worldToScreen transform to calculate the screen
coordinates of the lines...
AffineTransform worldToScreen = mapPane.getWorldToScreenTransform();
Hope that all makes some kind of sense !!!
A distance cursor tool would be a good addition to the swing module
but I won't be able to work on that myself for a little while (too
many other things to do first !).
Michael
------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference_______________________________________________
Geotools-gt2-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users