Results 1 to 2 of 2
  1. #1
    minaise is offline Member
    Join Date
    Oct 2013
    Posts
    1
    Rep Power
    0

    Default creating lines in Java

    Hello

    I`m completely new to Java and in big trouble with the following exercise.
    Using JTS Topology Suite and Eclipse, I`m supposed to run a certain program to create 3 lines (LineString; a, b, c) with the coordinates (x,y) and as a result to find out which lines intersect the first line a.

    This is what have:

    Java Code:
    import com.vividsolutions.jts.geom.*;
    public class NewProj {
    public static void main(String[] args){
    
    if (args.length % 2 == 1) {
    
    else {
    
    int i=0;
    
    // Create a new empty array of coordinates.
    I don`t know how I could create three separate lines, each line a, b and c has 3 pairs of x,y coordinates. I think here I am creating just one big line with all the coordinates. 
    
    Coordinate[] coordinates  =  new Coordinate[] {
    new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y), 
    new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y),
    new Coordinate(x, y), new Coordinate(x, y), new Coordinate(x, y),
    };
    
    while (i < args.length) {
    
    double x = Double.parseDouble(args[i]);
    double y = Double.parseDouble(args[i+1]);
    
    Coordinate newCoord = new Coordinate(x,y);
    coordinates[i/2] = newCoord;
    // System.out.println(newCoord.toString());    
     i=i+2;
    } // while
    	
    // Create a new Geometry from the array of coordinates. 
    If understand correctly this is the command that is actually taking x,y coordinates from above and joining it for a line, right?
    Since I`m supposed to have 3 lines, should I amend it or copy 3x somehow? 
    
    LineString line = new GeometryFactory().createLineString(coordinates);
    
    Point startPoint = line.getStartPoint();
    Point endPoint = line.getEndPoint();
    
    
    // What do I have to write here to find out which lines intersect line a? 
    System.out.println("Answer" + ..................());		  
    
    	} // else
    
      } //main	
    
    }
    Any help much appreciated!!!
    Last edited by minaise; 10-28-2013 at 07:57 PM.

  2. #2
    Tolls is online now Moderator
    Join Date
    Apr 2009
    Posts
    11,805
    Rep Power
    19

    Default Re: creating lines in Java

    When posting code please wrap it in [code] tags [/code].

    And also show what the problem is (and if it's in that awful light blue then you need to remove the colour tags, as that's unreadable).
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 1
    Last Post: 09-16-2012, 09:11 PM
  2. Replies: 3
    Last Post: 03-17-2012, 03:19 AM
  3. How do I make lines and graphs in java?
    By TallOne in forum New To Java
    Replies: 5
    Last Post: 01-17-2012, 02:36 AM
  4. Replies: 3
    Last Post: 10-25-2011, 06:29 PM
  5. eliminating new lines in java
    By javajames in forum New To Java
    Replies: 5
    Last Post: 05-13-2011, 10:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •