Changes between Version 4 and Version 5 of TutorialKMlCoordinates


Ignore:
Timestamp:
07/20/09 14:19:02 (4 years ago)
Author:
Wuaast
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • TutorialKMlCoordinates

    v4 v5  
    22 
    33I am going to explain (a) how to retrieve (and print) coordinates of all spatial features in a feature collection, and (b) how to find  
    4 the  nearest point compared to a given point. This tutorial presumes understanding of the Tutorial [wiki:TutorialKMlStreams Parsing KML into the Feature Model]. It also helps to have some basic knowledge about the [http://www.vividsolutions.com/jts/jtshome.htm Java Topology Suite (JTS)] and the concept of [http://en.wikipedia.org/wiki/Great-circle_distance Geodetic (Great Circle) Distances].  
     4the  nearest point out of a list of features compared to a given point. This tutorial presumes understanding of the Tutorial [wiki:TutorialKMlStreams Parsing KML into the Feature Model]. It also helps to have some basic knowledge about the [http://www.vividsolutions.com/jts/jtshome.htm Java Topology Suite (JTS)] and the concept of [http://en.wikipedia.org/wiki/Great-circle_distance Geodetic (Great Circle) Distances].  
    55 
    66=== Getting the coordinates === 
     
    2424{{{ 
    2525GeometryFactory geomFactory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING), 4326); 
     26 
     27//com.vividsolutions.jts.geom.Point givenPoint = geomFactory.createPoint(...) 
     28 
    2629double shortestDistance = Double.MAX_VALUE; 
     30Point nearestPoint = null; 
     31Point actualPoint = null; 
     32                 
    2733for(Feature f : features.listFeaturesRecursively()){ 
    2834        Geometry geom = f.getGeometry(); 
    29         Point givenPoint = ...; // comes from somewhere else 
    30  
    3135        Coordinate[] coordinates = geom.getCoordinates(); 
    3236        for (int i = 0; i < coordinates.length; i++) { 
    33                 System.out.println(coordinates[i].x+" "+coordinates[i].y); 
    34                 Coordinate[] current = {givenCoordinate, coordinates[i]}; // where does givenCoordinate come from  
    35                 if (new GeodeticDistance().length(geomFactory.createGeometry(current)) < shortestDistance) {  
    36 // changed to createGeometry, since we don't know what type we have here 
    37 // it should not be length, but a distance between two geometries 
    38                         shortestDistance = new GeodeticDistance().length(geomFactory.createLineString(actualLine)); // again, should be createGeometry 
    39                         nearestPoint = new Point(coordinates[i].x, coordinates[i].y); 
     37                actualPoint = geomFactory.createPoint(coordinates[i]); 
     38                if (new GeodeticDistance().betweenGeometries(givenPoint, actualPoint)<shortestDistance) { 
     39                        shortestDistance = new GeodeticDistance().betweenGeometries(givenPoint, actualPoint); 
     40                        nearestPoint = actualPoint; 
    4041                } 
    4142        }