Advertisement
Guest User

Untitled

a guest
Mar 7th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Groovy 1.11 KB | None | 0 0
  1. import com.vividsolutions.jts.geom.Coordinate;
  2. import com.vividsolutions.jts.geom.CoordinateArrays;
  3. import com.vividsolutions.jts.geom.GeometryFactory;
  4. import com.vividsolutions.jts.math.Vector2D;
  5. import com.vividsolutions.jts.geom.*;
  6.  
  7. //Start point
  8. double x1 = 0
  9. double y1 = 0
  10.  
  11. //Distance of the last point
  12. double x2 = 100
  13. double y2 = 100
  14.  
  15. //Max distance
  16. double distance =  100
  17.  
  18. Coordinate ptStart = new Coordinate(x1, y1);
  19. Coordinate ptEnd = new Coordinate(x2, y2);
  20. Vector2D vStart = new Vector2D(ptStart);
  21. GeometryFactory gf = new GeometryFactory();
  22. Vector2D v = Vector2D.create(ptStart, ptEnd);
  23. // Normalize the vector (length=1), we keep only the direction
  24. v.normalize();
  25. double stepLength = 10; //length m
  26. stepLength>distance?distance:stepLength
  27. int stepCount = Math.round(distance/stepLength);
  28. // This is the translation vector
  29. v = v.multiply(stepLength);
  30.  
  31. for(int i=0; i < stepCount; i ++) {
  32.  LineSegment stepLine= new LineSegment(vStart.add(v.multiply(i)).toCoordinate(), vStart.add(v.multiply(i + 1)).toCoordinate());
  33.  LineString geom =   stepLine.toGeometry(gf);
  34.  println(geom.toString())
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement