JTS-Orientation方向计算

org.locationtech.jts.algorithm.Orientation 使用说明

用于计算基本几何结构(包括点三重体(三角形)和环)的方向的函数。方向是平面几何的基本属性。

Orientation.index(Coordinate p1, Coordinate p2, Coordinate q)

说明

计算q点处在p1点->p2点方向的左侧还是右侧,左侧(逆时针方向)返回1,右侧(顺时针方向)返回-1

操作示例

JTS-Orientation方向计算_第1张图片

package com.leokok.jts.learning.jts.core.algorithm;

import org.locationtech.jts.algorithm.Orientation;
import org.locationtech.jts.geom.Coordinate;

/**
 * 用于计算基本几何结构(包括点三重体(三角形)和环)的方向的函数。方向是平面几何的基本属性。
 */
public class OrientationTest {

    public static void main(String[] args) {
        Coordinate p0 = new Coordinate(219.3649559090992, 140.84159161824724);
        Coordinate p1 = new Coordinate(168.9018919682399, -5.713787599646864);

        Coordinate p = new Coordinate(186.80814046338352, 46.28973405831556);
        int orient = Orientation.index(p0, p1, p);
        int orientInv = Orientation.index(p1, p0, p);

        System.out.println("p在p0->p1的左侧:"+orient);
        System.out.println("p在p1->p0的右侧:"+orientInv);
    }
}

输出:

p在p0->p1的左侧:-1
p在p1->p0的右侧:1

Orientation.isCCW(Coordinate[] ring)

说明

判断环是否是逆时针方向

操作示例

JTS-Orientation方向计算_第2张图片

@Test
public void isCCWTest() throws ParseException {
    WKTReader wktReader = new WKTReader();
    Geometry geometry = wktReader.read("POLYGON ((415.1715 77.9175, 415.1712 77.9172, 415.1711 77.91685, 415.1717 77.9165, 415.1718 77.91649, 415.1724 77.9166, 415.1728 77.9169, 415.17286 77.91726, 415.1728 77.9176, 415.1725 77.9179, 415.1719 77.918, 415.1716 77.918, 415.1715 77.9175))");

    Coordinate[] coordinates = geometry.getCoordinates();

    System.out.println(Orientation.isCCW(coordinates));
}

输出 true

你可能感兴趣的:(JTS,GIS,java,开发语言)