関係判断
- ジオメトリ間の関係は次のとおりです。
等しい: |
幾何学的形状はトポロジー的に等しいです。 |
バラバラ: |
ジオメトリには共通点がありません。 |
交差: |
幾何学的形状には少なくとも1つの共通点があります(ばらばらとは異なります) |
タッチ: |
ジオメトリには少なくとも1つの共通境界点がありますが、内部点はありません。 |
クロス: |
幾何学的形状は、すべてではなく一部の内部点を共有します。 |
あり(内): |
ジオメトリAのラインはすべてジオメトリBの内側にあります。 |
含む: |
ジオメトリBのラインはすべてジオメトリAの内側にあります(包含とは異なります)。 |
オーバーラップ: |
幾何学的形状は、すべてではないがいくつかの共通点を共有し、交差点に独自の同じ領域があります。 |
- 次の例は、Equals、Disjoint、Intersects、Operations内での使用方法を示しています。
パッケージcom.alibaba.autonavi; import com.vividsolutions.jts.geom。*; import com.vividsolutions.jts.io.ParseException; import com.vividsolutions.jts.io.WKTReader; / ** * gemotry之间的关系 * @author xingxing.dxx * * / public class GeometryRelated { private GeometryFactory geometryFactory = new GeometryFactory(); / ** *いくつかのオブジェクトが重なっているかどうか * @return * @throws ParseException * / public boolean equalsGeo()throws ParseException { WKTReader reader = new WKTReader(geometryFactory); LineString geometry1 =(LineString)reader.read( "LINESTRING(0 0、2 0、5 0)"); LineString geometry2 =(LineString)reader.read( "LINESTRING(5 0、0 0)"); return geometry1.equals(geometry2); // true } / ** *幾何何対象没有交点(相邻) * @return * @throws ParseException * / public boolean disjointGeo()throws ParseException { WKTReader reader = new WKTReader(geometryFactory); LineString geometry1 =(LineString)reader.read( "LINESTRING(0 0、2 0、5 0)"); LineString geometry2 =(LineString)reader.read( "LINESTRING(0 1、0 2)"); geometry1.disjoint(geometry2);を返します。 } / ** *少なくとも1つのパブリック点(相交) * @return * / public boolean intersectsGeo()throws ParseException { WKTReaderリーダー=新しいWKTReader(geometryFactory); LineString geometry1 =(LineString)reader.read( "LINESTRING(0 0、2 0、5 0)"); LineString geometry2 =(LineString)reader.read( "LINESTRING(0 0、0 2)"); ジオメトリinterPoint = geometry1.intersection(geometry2); //相交点 System.out.println(interPoint.toText()); //输出POINT(0 0) return geometry1.intersects(geometry2); } / ** * x、yが座標のpointpoint(x、y)であるかどうかをジオメトリ表示されたポリゴンで * @param x * @param y * @param geometry wkt格式 * @return * / public boolean withinGeo(double x、double y、String geometry)はParseException { Coordinate coord = new Coordinate(x、y);をスローします。 ポイントpoint = geometryFactory.createPoint(coord); WKTReaderリーダー=新しいWKTReader(geometryFactory); ポリゴンポリゴン=(ポリゴン)reader.read(geometry); return point.within(polygon); } / ** * @param args * @throws ParseException * / public static void main(String [] args)throws ParseException { GeometryRelated gr = new GeometryRelated(); System.out.println(gr.equalsGeo()); System.out.println(gr.disjointGeo()); System.out.println(gr.intersectsGeo()); System.out.println(gr.withinGeo(5,5、 "POLYGON((0 0、10 0、10 10、0 10,0 0))")); } }
関係分析
- 関係分析にはいくつかのタイプがあります
バッファ分析(バッファ) |
指定された距離内にすべてのポリゴンとマルチポリゴンを含む |
凸包解析(ConvexHull) |
幾何学的形状のすべてのポイントを含む凸包ポリゴン(アウトソーシングポリゴン) |
交差点 |
A∩B交差演算は、ポリゴンABのすべての共通点のセットです |
共同分析(ユニオン) |
AUB ABの共同事業はABのすべてのポイントの集合です |
差異分析(差異) |
(AA∩B)AB形状の差異分析は、BにはないAのすべてのポイントのセットです。 |
対称差分析(SymDifference) |
(AUB-A∩B)AB形状の対称差分析は、AまたはBにあるが、ABに同時にないすべてのポイントのセットです。 |
2.特定の例を見てみましょう
パッケージcom.alibaba.autonavi; import java.util.ArrayList; import java.util.List; import com.vividsolutions.jts.geom.Coordinate; import com.vividsolutions.jts.geom.Geometry; import com.vividsolutions.jts.geom.GeometryFactory; import com.vividsolutions.jts.geom.LineString; / ** * gemotry之间的关系分析 * * @author xingxing.dxx * / public class Operation { private GeometryFactory geometryFactory = new GeometryFactory(); / ** *ポイントを作成 * * @param x * @param y * @return * / public Coordinate point(double x、double y){ 新しいCoordinate(x、y); } / ** *ラインを作成 * * @return * / public LineString createLine(List <Coordinate> points){ Coordinate [] coords =(Coordinate [])points.toArray(new Coordinate [points.size()]); LineString line = geometryFactory.createLineString(coords); 改行; } / ** * 戻り値指定距離内の多形および多多形 * * @param a * @param distance * @return * / public Geometry bufferGeo(Geometry a、double distance){ return a.buffer(distance); } / ** *(A)と(B)の最も近い2点間の距離を返します public Geometry unionGeo(Geometry a、Geometry b){ * * @param a * @param b * @return * / public double distanceGeo(Geometry a、Geometry b){ return a.distance(b); } / ** * 2つの幾何オブジェクトの交差 * * @param a * @ param b * @return * / public Geometry intersectionGeo(Geometry a、Geometry b){ return a.intersection(b); } / ** * Geometric object merge * * @param a * @param b * @return * / / ** * Aジオメトリオブジェクトでははい、Bジオメトリオブジェクトではありません a.union(b);を返します。 } * * @param a * @param b * @return * / public Geometry differenceGeo(Geometry a、Geometry b){ return a.difference(b); } public static void main(String [] args){ Operation op = new Operation(); //创建一条线 List <Coordinate> points1 = new ArrayList <Coordinate>(); points1.add(op.point(0、0)); points1.add(op.point(1、3)); points1.add(op.point(2、3)); LineString line1 = op.createLine(points1); //创建第二条线 List <Coordinate> points2 = new ArrayList <Coordinate>(); points2.add(op.point(3、0)); points2.add(op.point(3、3)); points2.add(op.point(5、6)); LineString line2 = op.createLine(points2); System.out.println(op.distanceGeo(line1、line2)); // out 1.0 System.out.println(op.intersectionGeo(line1、line2)); // out GEOMETRYCOLLECTION EMPTY System.out.println(op.unionGeo (line1、line2)); // out MULTILINESTRING((0 0、1 3、2 3)、(3 0、3 3、5 6))System.out.println(op.differenceGeo(line1、line2)); // out LINESTRING(0 0 、1 3、2 3)} }