JTS学习笔记
基础的类
Geometry
geom对象Coordinate
坐标类Point
Point对象MultiPoint
基本对象MultiPoint等等GeometryFactory
工厂对象PreparedGeometryFactory
PreparedGeometry
几何对象Geometry
public abstract class Geometry implements Cloneable, Comparable, Serializable{...}
// 一系列常量protected static final int TYPECODE_POINT = 0;protected static final int TYPECODE_MULTIPOINT = 1;protected static final int TYPECODE_LINESTRING = 2;protected static final int TYPECODE_LINEARRING = 3;protected static final int TYPECODE_MULTILINESTRING = 4;protected static final int TYPECODE_POLYGON = 5;protected static final int TYPECODE_MULTIPOLYGON = 6;protected static final int TYPECODE_GEOMETRYCOLLECTION = 7;public static final String TYPENAME_POINT = "Point";public static final String TYPENAME_MULTIPOINT = "MultiPoint";public static final String TYPENAME_LINESTRING = "LineString";public static final String TYPENAME_LINEARRING = "LinearRing";public static final String TYPENAME_MULTILINESTRING = "MultiLineString";public static final String TYPENAME_POLYGON = "Polygon";public static final String TYPENAME_MULTIPOLYGON = "MultiPolygon";public static final String TYPENAME_GEOMETRYCOLLECTION = "GeometryCollection";// 边界框protected Envelope envelope;//创建本Geometry对象的工厂对象protected final GeometryFactory factory;protected int SRID;//可用于携带客户端定义的辅助数据的对象引用。private Object userData = null;// 构造方法public Geometry(GeometryFactory factory) {...}public abstract String getGeometryType();// 包含任何非空几何返回trueprotected static boolean hasNonEmptyElements(Geometry[] geometries){...}protected static boolean hasNullElements(Object[] array) {...}Geometry getGeometryN(int n){...}// 测试此 Geometry 是否简单。 SFS 对简单性的定义遵循一般规则,即如果几何没有自相切点、自交点或其他异常点,则该几何是简单的。public boolean isSimple(){...}// 距离public double distance(Geometry g){...}// 与geom的距离小于distancepublic boolean isWithinDistance(Geometry geom, double distance){...}// 是否是矩形多边形public boolean isRectangle(){...}// 找到质点public Point getCentroid(){...}// 返回内点public Point getInteriorPoint(){...}// 获取维度public abstract int getDimension();// 获取边界public abstract Geometry getBoundary();public abstract int getBoundaryDimension();// 此图形是否和g不相交public boolean disjoint(Geometry g)public boolean touches(Geometry g)//是否相交public boolean intersects(Geometry g)public boolean crosses(Geometry g)//是否在g图形内部public boolean within(Geometry g)// 是否包含gpublic boolean contains(Geometry g)//是否重叠public boolean overlaps(Geometry g)//是否覆盖public boolean covers(Geometry g)//是否被覆盖public boolean coveredBy(Geometry g) public String toText()//计算缓冲区public Geometry buffer(double distance) //最小凸边型public Geometry convexHull()//计算一个新几何,它的所有组件坐标序列都与这个几何相反(相反方向)。public Geometry reverse()//计算表示该几何图形和其他几何图形共有的点集的几何图形。public Geometry intersection(Geometry other)// 交集public Geometry union(Geometry other)// 差集 Computes a Geometry representing the closure of the point-set of the points contained in this Geometry that are not contained in the other Geometry.public Geometry difference(Geometry other)// 并集public Geometry symDifference(Geometry other)// 此几何内所有并集public Geometry union()// 在指定容差内相等public abstract boolean equalsExact(Geometry other, double tolerance);// 完全相等public boolean equalsNorm(Geometry g)//使用或在此几何的坐标上执行操作。如果此方法修改了任何坐标值,则必须调用 geometryChanged 来更新几何状态。public abstract void apply(CoordinateFilter filter);//深克隆public Object clone()
多边形类 Polygon
public class Polygon extends Geometry implements Polygonal{...}
//外边缘protected LinearRing shell = null;
//内边缘protected LinearRing[] holes;
/*
shell:外边线
holes:里面的洞的边线
factory:GeometryFactory
*/
Polygon(LinearRing shell, LinearRing[] holes, GeometryFactory factory){...}
// 获取外边线
LinearRing getExteriorRing(){...}
//获取内洞的周长
int getNumInteriorRing(){...}
//获取第n个洞
LinearRing getInteriorRingN(int n){...}
// 其他方法继承自Geometry
线LineString
public class LineString extends Geometry implements Lineal{...}
// The points of this LineString.
protected CoordinateSequence points;
// 初始化
private void init(CoordinateSequence points){...}
// 获取`CoordinateSequence points`序列的第N个坐标
Coordinate getCoordinateN(int n){...}
// 获取`CoordinateSequence points`的第`n`个点
Point getPointN(int n){...}
//返回第0个,空就返回null
Point getStartPoint(){...}
Point getEndPoint(){...}
//是否封闭
isClosed()
//是否是圈圈
isRing()
// 其他方法继承自Geometry
GeometryFactory
介绍
提供一组实用方法,用于从坐标列表构建几何对象。请注意,工厂构造函数方法不会以任何方式更改输入坐标。特别是,它们没有四舍五入到提供的 PrecisionModel。假设输入坐标满足给定的精度。此类的实例是线程安全的。
方法介绍:
构造器:
public GeometryFactory(PrecisionModel precisionModel, int SRID,CoordinateSequenceFactory coordinateSequenceFactory)
public GeometryFactory(CoordinateSequenceFactory coordinateSequenceFactory)
public GeometryFactory(PrecisionModel precisionModel)
public GeometryFactory(PrecisionModel precisionModel, int SRID)
public GeometryFactory()
其中
PrecisionModel
是精度模型
转换成数组
创建各种基本类型
PreparedGeometryFactory
PreparedGeometry
封装了一些判断的方法,提高重复调用的性能。
输入输出类(转换类)
eg:
Geometry g1 = new WKTReader().read("LINESTRING (0 0, 10 10, 20 20)");System.out.println("Geometry 1: " + g1);
Geometry 1: LINESTRING (0 0, 10 10, 20 20) Geometry 2: LINESTRING (0 0, 10 10, 20 20)