Hi Michael
Thanks for your response.
>> My first question is why do I not need to apply a transformation from
>> lat/long
>> (EPSG:4326?) to UTM in order for the points to show up on the map?
>
> A bit of GeoTools magic :) Data are reprojected 'on the fly' into the
> projection set for the MapContext. This is explained a bit further in
> this example app:
I guessed that something like this must be happening in the background just
wasn't able to determine where it was being done.
>> When I have the points on the map I need to be able to select one using
>> the
>> mouse to display the associated feature information. When I step though
>> the
>> code (org.geotools.swing.tool.InfoTool) it appears that the mouse click
>> position is generated using UTM coordinates so they will never equal the
>> coordinates of the lat/long points. How can I get the InfoTool to work
>> with
>> lat/long coordinates?
>
> Sigh... the best thing about working on an open source project is
> that your code is open to inspection, warts and all. And the worst
> thing about working on an open source project is that your code is
> open to inspection...
I managed to work around the issue by creating my own button on the toolbar
(in a similar way to the 'Selection Lab'), transforming the map position to
EPSG:4326 and then create a dwithin filter to check if the mouse click was
near a feature:
private void selectFeatures(MapMouseEvent ev) {
DirectPosition2D mousePosition = ev.getMapPosition();
try {
/*
* Construct a transformation to convert the mouse click (world)
coordinates
* to the Latitude/Longitude coordinates
*/
CoordinateReferenceSystem sourceCRS =
mousePosition.getCoordinateReferenceSystem();
CoordinateReferenceSystem targetCRS = CRS.decode("EPSG:4326");
MathTransform transform = CRS.findMathTransform(sourceCRS,
targetCRS, true);
Coordinate targetCoord = JTS.transform(new
Coordinate(mousePosition.getX(), mousePosition.getY()), null, transform);
/*
* Create and apply a filter to retrieve features within a specified
distance
* of the mouse click
*/
Point jtsPoint = geometryFactory.createPoint(targetCoord);
Filter filter =
filterFactory.dwithin(filterFactory.property(FeatureUtils.GEOMETRY_ATTR_LOCATION),
filterFactory.literal(jtsPoint), 0.001, null);
FeatureCollection<SimpleFeatureType, SimpleFeature> selectedFeatures
= (FeatureCollection<SimpleFeatureType, SimpleFeature>)
collection.subCollection(filter);
....
}
It seems to work, does that look correct to you?
Thanks,
Richard
--
View this message in context:
http://n2.nabble.com/Unable-to-view-lat-long-coordinate-layer-tp4550186p4587659.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.
------------------------------------------------------------------------------
SOLARIS 10 is the OS for Data Centers - provides features such as DTrace,
Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW
http://p.sf.net/sfu/solaris-dev2dev
_______________________________________________
Geotools-gt2-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users