Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import com.vividsolutions.jts.geom.Coordinate;
- import com.vividsolutions.jts.geom.CoordinateArrays;
- import com.vividsolutions.jts.geom.GeometryFactory;
- import com.vividsolutions.jts.math.Vector2D;
- import com.vividsolutions.jts.geom.*;
- //Start point
- double x1 = 0
- double y1 = 0
- //Distance of the last point
- double x2 = 100
- double y2 = 100
- //Max distance
- double distance = 100
- Coordinate ptStart = new Coordinate(x1, y1);
- Coordinate ptEnd = new Coordinate(x2, y2);
- Vector2D vStart = new Vector2D(ptStart);
- GeometryFactory gf = new GeometryFactory();
- Vector2D v = Vector2D.create(ptStart, ptEnd);
- // Normalize the vector (length=1), we keep only the direction
- v.normalize();
- double stepLength = 10; //length m
- stepLength>distance?distance:stepLength
- int stepCount = Math.round(distance/stepLength);
- // This is the translation vector
- v = v.multiply(stepLength);
- for(int i=0; i < stepCount; i ++) {
- LineSegment stepLine= new LineSegment(vStart.add(v.multiply(i)).toCoordinate(), vStart.add(v.multiply(i + 1)).toCoordinate());
- LineString geom = stepLine.toGeometry(gf);
- println(geom.toString())
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement