Hi

I have a couple of questions (as a newbie):

I am attempting to read a shape file (NAD_1983_UTM_Zone_20N) using a
FileDataStore and then create a separate map layer using points
(latitude/longitude) from a database.  When I display the map (using
JMapFrame) it shows the shape file and the points.  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?

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?  

        File file = new File("D:\\resources\\p00001gl\\p00001gl.shp");
        if (file == null) {
                return;
        }

        FileDataStore store = FileDataStoreFinder.getDataStore(file);
        FeatureSource<SimpleFeatureType, SimpleFeature> featureSource =
store.getFeatureSource();
        // Create a map context using the shapefile
        MapContext map = createMapContext(featureSource, inMemory);

        Connection conn = ConnectionUtils.getConnection("connection");
        Statement stmt = conn.createStatement();
        ResultSet rs = stmt.executeQuery("SELECT latitude, longitude,
location_name FROM point");
                
        FeatureCollection<SimpleFeatureType, SimpleFeature> collection =
FeatureCollections.newCollection();
        GeometryFactory geometryFactory =
JTSFactoryFinder.getGeometryFactory(null);
        final SimpleFeatureType FEATURE_LOCATION = createFeatureType();
        SimpleFeatureBuilder featureBuilder = new
SimpleFeatureBuilder(FEATURE_LOCATION);

        while (rs.next())
        {
                double latitude = rs.getDouble(1);
                double longitude = rs.getDouble(2);
                String name = rs.getString(3);

                Coordinate targetCoord = new Coordinate(longitude, latitude);
                Point point = geometryFactory.createPoint(targetCoord); 

                featureBuilder.add(point);
                featureBuilder.add(name);
                SimpleFeature feature = featureBuilder.buildFeature(null);
                collection.add(feature);
        }
        rs.close();

        // Now display the map
        JMapFrame frame = new JMapFrame(map);
        frame.enableStatusBar(true);
        frame.enableLayerTable(true);
        frame.enableToolBar(true);
        frame.setSize(500, 500);
        frame.setLocationRelativeTo(null); // center the window
        frame.setVisible(true);
        frame.initComponents();

        map.addLayer(collection, null);


I have tried to transform the lat/longs to UTM but if I do they don't seem
to appear on the map anymore.

        CoordinateReferenceSystem targetCRS =
map.getCoordinateReferenceSystem();
        CoordinateReferenceSystem sourceCRS = CRS.decode("EPSG:4326");
        MathTransform transform = CRS.findMathTransform(sourceCRS,
targetCRS, true);
        ....
        // Transform the long/lat coordinate to the target map CRS
        Coordinate targetCoord = JTS.transform(new Coordinate(longitude,
latitude), new Coordinate(), transform);

As a third question, if I transform the lat/long coordinates using the
transformation above, why do they not appear on the (UTM) map any more even
though the resultant coordinate values look OK?

Any help would be greatly appreciated since I have been reading through the
forum and the user guide for a couple of days now.

Richard
-- 
View this message in context: 
http://n2.nabble.com/Unable-to-view-lat-long-coordinate-layer-tp4550186p4550186.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

Reply via email to