Thanks a lot for your answers !

This helped me to solve the problem in the following way:
    /**
     * Discretize a 2D line with a minimal distance. Start and end
points are part of the returned points.
     * @param line                2DLine
     * @param minimalDistance    Minimal distance between two points   
     * @return                    Array of 2D points, with start and end
point of the line
     */
    public static Point2D[] Discretize2DLine(Line2D line, double
minimalDistance) {
        // Compute the number of steps in order have a minimal distance
        int nNumberStep = (int)
Math.ceil(GeometryUtil.Length(line)/minimalDistance);
        // Compute the step
        double dStep = GeometryUtil.Length(line) / nNumberStep;
        // Initialize the returned array
        Point2D[] my2DPoint = new Point2D[nNumberStep+1];
        // Compute the coordinate with ShapeUtilities module
        for (int i = 0; i<= nNumberStep; i++) {
            Point2D myPoint = ShapeUtilities.colinearPoint(line,
line.getP1(), dStep*i);
            my2DPoint[i] = myPoint;
        }
        return my2DPoint;
    }

Cédric

Martin Desruisseaux wrote:
> Andrea Aime a écrit :
>   
>>> I'd like to compute the coordinates of one point every x meters along a
>>> 2D line (example: for a 200m line with a point every 50m, the function
>>> will return the start coordinate,  one coordinate after 50 m, on
>>> coordinate after 100m, one coordinate after 150m and one coordinate
>>> after 200m). Is there any appropriate function to do that ?
>>>       
>> Sextante has such a process, I guess you can use it in conjuction
>> with GeoTools 2.5.x bindings to read the lines and write out the
>> results.
>>     
>
>
> You can do that in GeoTools too, by invoking the following function in a loop:
>
> http://geotidy.geomatys.fr/apidocs/org/geotools/display/shape/ShapeUtilities.html#colinearPoint(java.awt.geom.Line2D,%20java.awt.geom.Point2D,%20double)
>
> (I believe that in GeoTools 2.x, this method was in an internal package, so it
> didn't appear in the javadoc).
>
>       Martin
>
>   

-- 
Camptocamp SA
Cédric Moullet
PSE A
CH-1015 Lausanne
www.camptocamp.com  / www.mapfish.org

+41 79 759 69 83 (mobile)
+41 21 619 10 21 (direct)
+41 21 619 10 10 (centrale)
+41 21 619 10 00 (fax)


-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to