Justin: Thank you very much for your support. It was very helpful.
Here I put the answer you gave me and my code so other users may understand
the solution.
The summary of the things I had to do to achieve getting the distance in
meters from one point to another of the city of Cordoba, Argentina:
1. Use the epsg-hsql plugin by modifying the POM.xml file that maven uses
adding the following in the dependencies section:
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt2-epsg-hsql</artifactId>
            <version>2.4-SNAPSHOT</version>
        </dependency>
2. Transform the projected coordinates that were in my graph of the city by
searching a correct EPSG code for my data. I found the corresponding epsg
code to my city in this page: http://spatialreference.org/ref/epsg/ and
Justin gave me the right hint on how to transform the coordinates:
/-------------------------------------------- written by Justin
--------------------------------------------------------
Point p = ...;

//create the transformation
CoordinateReferenceSystem crs1 = CRS.decode( "EPSG:4694" );
CoordinateReferenceSystem crs2 = CRS.decode( "EPSG:4326" );

MathTransform tx = CRS.findMathTransform( crs1, crs2, true );

//transform the point
double[] projected = new double[]{ p.getX(), p.getY() };
double[] longlat = new double[2];
tx.transform( projected, 0, longlat, 0, 1 );

After this routine, longlat will contain the longitude and latitude of
the coordinate.
/----------------------------------------------------------------------------------------------------------------------------------
3. Use a GeodeticCalculator to get the distance between the points.

Below I put a very initial version of my code (now working!). Thank you very
much again and hope this helps someone else.
Best regards!

Fran

import org.geotools.graph.structure.Node;
import org.geotools.referencing.CRS;
import org.opengis.referencing.crs.CoordinateReferenceSystem;
import org.opengis.referencing.operation.MathTransform;
import org.geotools.graph.structure.*;
import org.geotools.referencing.GeodeticCalculator;
import com.vividsolutions.jts.geom.Point;

        public static double distance(Node orig, Node dest){
                double dist;
                double[] longlat1, longlat2, projected1, projected2;
                Point p1,p2;
                CoordinateReferenceSystem crs1, crs2;
                MathTransform converter;
                dist = -1;
                p1 = ((Point) orig.getObject());
                p2 = ((Point) dest.getObject());
                longlat1 = new double[2];
                longlat2 = new double[2];
                
                try{
                        // Original coordinates, as you can get them from your 
graph
                        proyectadas1 = new double[]{p1.getY(),p1.getX()};
                        proyectadas2 = new double[]{p2.getY(),p2.getX()};
                        // POSGAR 94 / Argentina 4: 
http://spatialreference.org/ref/epsg/22184/
                        crs1 = CRS.decode( "EPSG:22184" );
                        crs2 = CRS.decode( "EPSG:4326" );
                        converter = CRS.findMathTransform( crs1, crs2, true );
                        converter.transform( projected1, 0, longlat1, 0, 1 );
                        converter.transform( projected2, 0, longlat2, 0, 1 );
                        // geodetic distance calculator
                        GeodeticCalculator gc = new 
GeodeticCalculator(CRS.decode("EPSG:22184"));       
                        gc.setStartingGeographicPoint(longlat1[1],longlat1[0]);
                        
gc.setDestinationGeographicPoint(longlat2[1],longlat2[0]);
                        dist = gc.getOrthodromicDistance();
                        System.out.println("Distance: "+ dist);
                }catch(Exception e){
                                e.printStackTrace();
                }
                return dist;
        }
-- 
View this message in context: 
http://www.nabble.com/Graphs%2C-Nodes-and-Points.-Argentinian-Coordinates-tp14517968p14604338.html
Sent from the geotools-gt2-users mailing list archive at Nabble.com.


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2005.
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

Reply via email to