JTS介绍
The JTS Topology Suite is a Java API that implements a core set of spatial data operations
using an explicit precision model and robust geometric algorithms. It provides a complete
model for specifying 2-D linear Geometry. Many common operations in computational
geometry and spatial data processing are exposed in a clear, consistent and integrated API.
JTS is intended to be used in the development of applications that support the validation,
cleaning, integration and querying of spatial datasets.
This document is intended for developers who would like to use JTS to accomplish their
spatial data processing requirements. It describes common uses of the JTS API and gives
code examples
官方说它是一个java的api用来计算几何空间的操作工具
源码地址文档在doc目录下
JTS在Geotools中的使用
下载Geotoos的源码我们可以看到GeoTools使用了JTS的类
即Geotools依赖JTS的包
根据上述依赖关系可以知道Geomerty是所有图形的父类
- 创建Point点
GeometryFactory geometryFactory = new GeometryFactory();
Point point = geometryFactory.createPoint(transform(new Coordinate(113.549006,22.388645), 4490, 3857)); //可以将4490坐标系进行转换成3857
- 创建线段
/**
* 生成线段
* @param wkt
* @return
* @throws ParseException
*/
public static LineString createLineString(String wkt) throws ParseException {
WKTReader reader = new WKTReader( geometryFactory );
return (LineString) reader.read(wkt);
}
/**
* 生成线段
* @param coords
* @return
*/
public static LineString createLineString(Coordinate[] coords) {
GeometryFactory geometryFactory = new GeometryFactory(new