Line Class

package javaxt.geospatial.geometry;

//******************************************************************************
//**  Line Class - By Peter Borissow
//******************************************************************************
/**
 *   Basic Structure for storing lines
 *
 ******************************************************************************/

public class Line implements Geometry {
    
    
    private Points Points = null;
    private String srs = "EPSG:4326";
    
  //**************************************************************************
  //** Creates a new instance of Line
  //**************************************************************************
    
    public Line(){
    }
    
    
    public Line(Point[] Points){
        this.Points = new Points(Points);  
    }
    
    public Line(Points Points){
        this.Points = Points;  
    }
    
    
  //**************************************************************************
  //** getSRS
  //**************************************************************************
  //** Sets the srs attribute for this Geometry. */
    
    public void setSRS(String srsName){
        if (srsName==null) srs = "";
        else srs = srsName.trim();
    }
    
    
  //**************************************************************************
  //** getSRS
  //**************************************************************************
  //** Returns the srs name of this Geometry. */
    
    public String getSRS(){
        return srs;
    }
    
  //**************************************************************************
  //** getName
  //**************************************************************************
  //** Returns the name of this Geometry. */
    
    public String getName(){ 
        return new Geometry.Name(this).toString(); 
    }
    
    
  //**************************************************************************
  //** getPoints
  //**************************************************************************
  //** Returns an array of points that compose this Geometry. */
    
    public Point[] getPoints(){
        return Points.getPoints();
    }
    
  //**************************************************************************
  //** addPoint
  //**************************************************************************
  /**  Used to append a point to an array of points */
    
    public void addPoint(Point Coordinate){
        if (Coordinate==null) return;
        else{
            Points.addPoint(Coordinate);
        }
    }

  //**************************************************************************
  //** addPoints
  //**************************************************************************
  /**  Used to append a point or multiple points to an array of points. 
   *   Attempts to convert input string into coordinate touples.
   */
    /*
    public void addPoints(String Coordinates){
        Points.addPoints(Coordinates);
    }
    */
    
    
  //**************************************************************************
  //** toString
  //**************************************************************************
  /**  Used to convert a line to a String */
    
    public String toString(String CoordinateSeparator, String TupleSeparator){
        if (Points==null) return "";
        else{
            return Points.toString(CoordinateSeparator, TupleSeparator);
        }
    }
    
    
  //**************************************************************************
  //** toGML
  //**************************************************************************
  /**  Used to convert a line to GML (xml fragment) */
    
    public String toGML(){
        if (Points==null) return "";
        else{
            
            String srsName = " srsName=\"" + srs + "\"";
            if (srs.length()==0) srsName = "";
            
            StringBuffer Coordinates = new StringBuffer();
            Coordinates.append("<gml:LineString" + srsName + ">");
            Coordinates.append("<gml:coordinates>");
            Coordinates.append(toString(",", " "));
            Coordinates.append("</gml:coordinates>");
            Coordinates.append("</gml:LineString>");
            return Coordinates.toString().trim();
        }
    }
    
    
  //**************************************************************************
  //** toString
  //**************************************************************************
  /** Used to return a Well-known Text (WKT) representation of the line. */
    
    public String toString(){
        if (Points==null || Points.getLength()<=0) return null;
        else{
            return "LINESTRING((" + toString(" ", ", ") + "))";
        }
    }
    
}