工作中发现postgis相关文档比较清晰, 想要找到需要的方法往往比较容易. 而geotools实现某些功能没有postgis直观, 往往需要好多类协同完成. 所以有必要维护一下postgis与geotools实现某些功能时的对应方法.
持续更新. 纯手工维护, 各位大佬有什么更好的方法欢迎指导.
JTS api 地址: http://locationtech.github.io/jts/javadoc/ GITHUB地址:https://github.com/locationtech/jts
postgis方法 | geotools方法 | qgis工具 | 功能描述 |
---|---|---|---|
ST_LineLocatePoint | org.locationtech.jts.linearref.LocationIndexedLine | 计算点在曲线中的位置(百分比) | |
ST_SimplifyPreserveTopology | com.vividsolutions.jts.simplify.TopologyPreservingSimplifier | 使用Douglas-Peucker算法,根据给定的几何对象,返回一个简化版的几何对象。避免创建新的派生的无效的几何对象(特别是多边形) | |
ST_LineSubstring | com.vividsolutions.jts.linearref.LengthIndexedLine | 根据传入的起止点的相对位置提取子轨迹 | |
ST_ClosestPoint | org.locationtech.jts.linearref.LocationIndexedLine | 获取点在线对象中的最近点在线中的位置 | |
split with lines | 道路link相交处打断(This algorithm splits the lines or polygons in one layer using the lines in another layer to define the breaking points. Intersection between geometries in both layers are considered as split points.) | ||
line intersections | 道路link相交处生成node(This algorithm creates point features where the lines in the Intersect layer intersect the lines in the Input layer.) | ||
Vector general/Split vector layer | 根据矢量图层中选中字段的不同取值讲矢量图层划分为多个图层,选中字段的相同取值的矢量数据放在同一个图层中(This algorithm takes a vector layer and an attribute and generates a set of vector layers in an output folder. Each of the layers created in that folder contains all features from the input layer with the same value for the specified attribute.The number of files generated is equal to the number of different values found for the specified attribute) |
-
计算点在曲线中的位置(百分比)
Geotools demo:GeometryFactory factory = new GeometryFactory(new PrecisionModel(PrecisionModel.FLOATING)); LocationIndexedLine indexedLine = new LocationIndexedLine(new LineString(new CoordinateArraySequence(new Coordinate[]{new Coordinate(0,0), new Coordinate(2,2)}), factory)); // 根据曲线位置获取响应的点坐标 Coordinate point = indexedLine.extractPoint(new LinearLocation(0,0.7)); System.out.println(point); // 根据给定的点坐标获取其在曲线中的位置 LinearLocation location1 = indexedLine.indexOf(new Coordinate(1.5,1)); System.out.println(location1.getSegmentFraction());
-
几何对象简化
Geotools demo:TopologyPreservingSimplifier.simplify(geometry, 0.001);