Hopefully this is a simple question. Assuming that I've built a LineString
like this:

final GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();

final LineString lineString = geometryFactory.createLineString(coordinateArray);

And now I want to generate mile or kilometer markers along that
LineString. Is there a way to get lineString.getLength() to return,
say miles, instead of degrees? I want to avoid having to loop through
and use the GeodeticCalculator for every pair of points if there is a
smarter way to do that with a LineString.

I've stubbed out what I want to do:

public Coordinate[] generateLapMarkers(final LineString lineString) {
    final SpatialIndex index = new STRtree();
    final LocationIndexedLine indexedPolyline = new
LocationIndexedLine(lineString);
    final LinearLocation startLocation = indexedPolyline.getStartIndex();
    final Envelope search = lineString.getEnvelopeInternal();
    search.expandBy(1);
    index.insert(search, indexedPolyline);
    final double totalMiles = lineString.getLength(); // Some trick
for getLength to return meters or miles.

    final List<Coordinate> laps = new
ArrayList<Coordinate>((int)Math.floor(totalMiles)-1);

    // Didn't know how else to get LocationIndexedLine other than to
search for itself.
    final List<LocationIndexedLine> locationIndexedLines = index.query(search);
    final LocationIndexedLine locationIndexedLine = locationIndexedLines.get(0);
    for (int d = 1; d < totalMiles; d++) {
        // Extract point by miles. Do we have to convert d back into
degrees (d * magicToConvertDegreesIntoMetersRelativeToStartLocation)
        // or can the index be set-up to use meters instead of degrees.
        laps.add(locationIndexedLine.extractPoint(startLocation, d));
    }
    return laps.toArray(new Coordinate[laps.size()]);
}
------------------------------------------------------------------------------
Dive into the World of Parallel Programming! The Go Parallel Website,
sponsored by Intel and developed in partnership with Slashdot Media, is your
hub for all things parallel software development, from weekly thought
leadership blogs to news, videos, case studies, tutorials and more. Take a
look and join the conversation now. http://goparallel.sourceforge.net
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users

Reply via email to