Package chunmap.model.geom

Source Code of chunmap.model.geom.GeoPoint

/**
* Copyright (c) 2009-2011, chunquedong(YangJiandong)
*
* This file is part of ChunMap project
* Licensed under the GNU LESSER GENERAL PUBLIC LICENSE(Version >=3)
*
* History:
*     2010-05-05  Jed Young  Creation
*/
package chunmap.model.geom;

import java.util.ArrayList;
import java.util.List;

import chunmap.model.coord.Transform;
import chunmap.model.coord.CPoint;
import chunmap.model.coord.Coordinate2D;
import chunmap.model.coord.Coordinate3D;
import chunmap.model.elem.Envelope;

/**
* 点
*
* @author chunquedong
*
*/
public class GeoPoint extends AbstractGeometry implements Comparable<GeoPoint> {

  private final CPoint coordinate;

  public GeoPoint(double x, double y) {
    this(new Coordinate2D(x, y));
  }

  public GeoPoint(CPoint coord) {
    coordinate=coord;
  }
  // ------------------------------------------------------------

  public double getX() {
    return coordinate.getX();
  }

  public double getY() {
    return coordinate.getY();
  }

  public CPoint getCoordinate() {
    return coordinate;
  }

  public boolean isPoint3D() {
    if (coordinate instanceof Coordinate3D)
      return true;
    else
      return false;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    if (getClass() != obj.getClass())
      return false;
    GeoPoint p = (GeoPoint) obj;
    return coordinate.equals(p.coordinate);
  }

  public boolean approximateEquals(GeoPoint obj) {
    if (this == obj)
      return true;
    if (obj == null)
      return false;
    return coordinate.approximateEquals(obj.coordinate);
  }

  @Override
  public int hashCode() {
    return coordinate.hashCode();
  }

  @Override
  public String toString() {
    return "POINT(" + getX() + " " + getY() + ")";
  }

  @Override
  protected Envelope calculateEnvelop() {
    return new Envelope(getX(), getY(), getX(), getY());
  }

  @Override
  public GeometryType getGeometryType() {
    return GeometryType.Point;
  }

  /*
   * (non-Javadoc)
   *
   * @see java.lang.Comparable#compareTo(java.lang.Object)
   */
  @Override
  public int compareTo(GeoPoint other) {
    return coordinate.compareTo(other.coordinate);
  }

  @Override
  public Geometry getBoundary() {
    return null;
  }

  @Override
  public GeometryCollection toGeometryCollection() {
    List<GeoPoint> gs = new ArrayList<GeoPoint>();
    gs.add(this);
    return new MultiPoint(gs);
  }

  @Override
  public Geometry transform(Transform transf) {
    return new GeoPoint(transf.convert(this.coordinate));
  }

  @Override
  protected boolean isSimple() {
    return true;
  }

}
TOP

Related Classes of chunmap.model.geom.GeoPoint

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.