如何判断GeoTools 的Geometry类型

代码如下,截取自GeoTools文档

public enum Geometries
extends Enum<Geometries>
Constants to identify JTS geometry types, reducing the need for boiler-plate code such as this...
 if (Polygon.class.isAssignableFrom(myObject.getClass()) ||
         MultiPolygon.class.isAssignableFrom(myObject.getClass())) {
     // do polygon thing
     ...
 } else if (LineString.class.isAssignableFrom(myObject.getClass()) ||
         MultiLineString.class.isAssignableFrom(myObject.getClass())) {
     // do line thing
     ....
 } else {
     // do point thing
     ....
 }
 Instead you can do this...
 Geometries geomType = Geometries.get(myObject);
 switch (geomType) {
     case POLYGON:
     case MULTIPOLYGON:
         // do polygon thing
         break;
     case LINESTRING:
     case MULTILINESTRING:
         // do line thing
         break;
     case POINT:
     case MULTIPOINT:
         // do point thing
         break;
     default:
         // e.g. unspecified Geometry, GeometryCollection
         break;
 }
 You can also work with Class objects...
 Class aClas = ...
 Geometries type = Geometries.getForBinding( aClass );
 
  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
你可以使用Geotools库来实现地块重叠判断Geotools是一个用于地理空间数据处理的开源Java库,它提供了许多功能来处理和分析地理空间数据。 要判断两个地块是否重叠,你可以使用Geotools的几何操作。首先,你需要将地块数据转换为Geotools的几何对象。通常情况下,地块可以表示为多边形。 下面是一个示例代码片段,展示了如何使用Geotools判断两个地块是否重叠: ```java import org.geotools.geometry.jts.JTS; import org.geotools.geometry.jts.JTSFactoryFinder; import org.locationtech.jts.geom.Geometry; import org.locationtech.jts.geom.Polygon; public class GeotoolsExample { public static void main(String[] args) { // 创建地块1的多边形 Polygon polygon1 = createPolygon(/* 地块1的坐标数据 */); // 创建地块2的多边形 Polygon polygon2 = createPolygon(/* 地块2的坐标数据 */); // 执行地块重叠判断 boolean isOverlap = polygon1.intersects(polygon2); // 输出结果 if (isOverlap) { System.out.println("地块重叠"); } else { System.out.println("地块不重叠"); } } private static Polygon createPolygon(/* 地块的坐标数据 */) { // 使用JTS库创建几何工厂 final org.locationtech.jts.geom.GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory(); // 创建地块的坐标数组(示例使用简单的矩形) Coordinate[] coordinates = new Coordinate[] { new Coordinate(0, 0), new Coordinate(0, 1), new Coordinate(1, 1), new Coordinate(1, 0), new Coordinate(0, 0) }; // 创建地块的多边形 Polygon polygon = geometryFactory.createPolygon(coordinates); return polygon; } } ``` 请根据你的实际需求替换示例代码的地块坐标数据,然后运行代码即可判断两个地块是否重叠。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值