1.intersection
package com.example.geotooltest;
import org.junit.Test;
import org.locationtech.jts.geom.Geometry;
import java.io.IOException;
public class GeometryUtil {
@Test
public void intersectionTest() throws IOException {
DataTypeConvert dtc = new DataTypeConvert();
String json1 = "{ \"type\": \"Polygon\", \"coordinates\": [ [ [ [ 114.318459657701752, 25.451711491442541 ], [ 114.338936430317901, 25.468215158924203 ], [ 114.365220048899801, 25.458129584352076 ], [ 114.377750611246995, 25.405562347188262 ], [ 114.322127139364355, 25.39822738386308 ], [ 114.318459657701752, 25.451711491442541 ] ] ] ] }";
Geometry geo1 = dtc.geojson2Geometry(json1);
String json2 = "{ \"type\": \"Polygon\", \"coordinates\": [ [ [ [ 114.355337061964661, 25.473019331992273 ], [ 114.460986089648614, 25.47481608416377 ], [ 114.47176660267759, 25.380306919943092 ], [ 114.357133814136162, 25.377791466902995 ], [ 114.355337061964661, 25.473019331992273 ] ] ] ] }";
Geometry geo2 = dtc.geojson2Geometry(json2);
Geometry geo12_intersect = geo1.intersection(geo2);
System.out.println(dtc.geometry2Geojson(geo12_intersect));
}
}
相交结果
橙色为intersection后的结果