JavaXT
|
|
Point Classpackage javaxt.geospatial.geometry; //****************************************************************************** //** Point Class - By Peter Borissow //****************************************************************************** /** * Basic structure for Points * ******************************************************************************/ public class Point implements Geometry { public double y = 0; public double x = 0; public double z = 0; public String srs = "EPSG:4326"; //************************************************************************** //** Creates a new instance of Line //************************************************************************** /** * @param x Longitude (sometimes referred to as Northing or x) * specified in Decimal Degrees * * @param y Latitude (sometimes referred to as Easting or y) * specified in Decimal Degrees * ***************************************************************************/ public Point(double x, double y){ this.x = x; this.y = y; } //************************************************************************** //** 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(); } public double getLatitude(){ return y; } public double getLongitude(){ return x; } public boolean equals(Object obj){ if (obj!=null){ return obj.hashCode()==this.hashCode(); } else{ return false; } } /* public boolean equals(Point point){ return equals(point.x, point.y); } public boolean equals(double x, double y){ if ((this.x == x) && (this.y == y)){ return true; } else{ return false; } } */ //************************************************************************** //** toString //************************************************************************** /** Used to return a Well-known Text (WKT) representation of the point. */ public String toString(){ return "POINT(" + x + " " + y + ")"; } //************************************************************************** //** toString //************************************************************************** /** Used to return a Well-known Text (WKT) representation of the point. */ public String toString(String CoordinateSeparator){ return x + CoordinateSeparator + y; } //************************************************************************** //** toGML //************************************************************************** /** Used to convert a Point to GML (xml fragment) */ public String toGML(){ String srsName = " srsName=\"" + srs + "\""; if (srs.length()==0) srsName = ""; StringBuffer Coordinates = new StringBuffer(); Coordinates.append("<gml:Point" + srsName + ">"); Coordinates.append("<gml:coordinates>"); Coordinates.append(toString(",")); Coordinates.append("</gml:coordinates>"); Coordinates.append("</gml:Point>"); return Coordinates.toString().trim(); } public int hashCode() { //Algorithm from Effective Java by Joshua Bloch [Jon Aquino] int result = 17; result = 37 * result + hashCode(x); result = 37 * result + hashCode(y); return result; } /** * Returns a hash code for a double value, using the algorithm from * Joshua Bloch's book <i>Effective Java"</i> */ private static int hashCode(double x) { long f = Double.doubleToLongBits(x); return (int)(f^(f>>>32)); } } |