Как разделить LineString на три равные LineString в Java / JTS - PullRequest
0 голосов
/ 17 февраля 2020

Я полностью новичок в Java и JTS. У меня есть код, который, указав аргументы (набор из 9 координат) строит LineString. Дело в том, что я хочу взять эту LineString и «разделить ее» на три равные LineString с именами «LineA», «LineB» и «Line C». Это означает, что координаты x, y 1-3 - это линия A, а 4-6 - линия B et c.

import com.vividsolutions.jts.geom.*;

public class PointTest {

public static void main(String[] args){

// The input arguments have to have be equal in numbers. Otherwise this string is displayed  
if (args.length % 2 == 1) {
  System.out.println("Wrong input, try again");
}


else {

  int i=0;

  // Create a new empty array for the coordinates.

  Coordinate[] coordinates = new Coordinate[args.length/2];

  // Go through the args and add each point as a Coordinate object to the coordinates array.

      while (i < args.length) {
    // transform string arguments into double values
    double x = Double.parseDouble(args[i]);
    double y = Double.parseDouble(args[i+1]);
    // create a new Coordinate object and add it to the coordinates array
    Coordinate newCoordA = new Coordinate(x,y);
    coordinates[i/2] = newCoordA;
    //System.out.println(newCoordA.toString());    
    i=i+2;
  } 


  // Create a LineString from the array of coordinates.
  LineString line = new GeometryFactory().createLineString(coordinates);
  System.out.println(line.toString());


// Adding some function to "split up" the LineString??
} 

} 

}   
.
...