Geometry

一、几何对象模型概述

        独立于计算机平台之外的、天然适用于分布式计算的、统一使用建模语言表示的一种对象模型。几何对象模型类图如下:

二、几何对象模型分类

        几何对象模型大致可以分为3类:简单数据模型、集合数据模型、曲线和曲面数据模型

1、简单数据模型

        1.1 点数据模型(Point、MultiPoint)

        1.2 多段线数据模型(线段 | LineString、直线 | Line、线性环 | LineRing、多重多段线 | MultiLineString)

        1.3 多边形数据模型(Polygon)

        1.4 多面体表面对象(PolyhedralSurface)

2、集合数据模型

        2.1 几何对象集合(GeometryCollection)

        2.2 曲面几何对象集合(MultiSurface)

        2.3 多边形几何对象集合(MultiPolygon)

        2.4 曲线几何对象集合(MultiCurve)

3、曲线和曲面数据模型

        3.1 曲线数据模型(Curve)

        3.2 曲面数据模型(Surface)

三、几何对象的WKT表示

        WKT(Well-known text)是一种文本标记语言,用于表示矢量几何对象、**空间参照系统**及空间参照系统之间的转换。它的二进制表示方式,亦即WKB(well-known binary)则胜于在传输和在数据库中存储相同的信息。该格式由开放地理空间联盟(OGC)制定。

四、几何对象创建

1、创建单点(Point)

1.1 通过坐标对象Coordinate创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate coord = new Coordinate(1, 1);
Point point = geometryFactory.createPoint(coord);

1.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
Point point = (Point) reader.read("POINT (1 1)");

2、创建多点(MultiPoint)

2.1 通过CoordinateSequence创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
CoordinateSequence coordinateSequence = new CoordinateSequence2D(1, 1,2,2,3,3);
MultiPoint multiPoint = geometryFactory.createMultiPoint(coordinateSequence);

2.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader(geometryFactory);
MultiPoint multiPoint = (MultiPoint) reader.read("MULTIPOINT(1 1,2 2,3 3)");

3、创建线段(LineString)

3.1 通过Coordinate创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords = new Coordinate[] {new Coordinate(0, 2), new Coordinate(2, 0), new Coordinate(8, 6) };
LineString line = geometryFactory.createLineString(coordinates);

3.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader( geometryFactory );
LineString line = (LineString) reader.read("LINESTRING(0 2, 2 0, 8 6)");

4、创建多重多线段(MultiLineString)

4.1 通过LineString[ ]创建

Coordinate[] coords  = new Coordinate[] {new Coordinate(2, 2), new Coordinate(3, 3)};
LineString lineString = geometryFactory.createLineString(coords);
Coordinate[] coords1  = new Coordinate[] {new Coordinate(3, 3), new Coordinate(4, 4)};
LineString lineString1 = geometryFactory.createLineString(coords1);

LineString[] lineStrings = new LineString[]{lineString, lineString1};
MultiLineString multiLineString = geometryFactory.createMultiLineString(lineStrings);

4.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
WKTReader reader = new WKTReader( geometryFactory );
MultiLineString multiLineString = (MultiLineString) reader.read("MULTILINESTRING((3 4,10 50,20 25),(-5 -8,-10 -8,-15 -4))");

5、创建单面(Polygon | 多边形)

5.1 通过Coordinate创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory();
Coordinate[] coords  =  new Coordinate[] {new Coordinate(4, 0), new Coordinate(2, 2),                     												 new Coordinate(4, 4), new Coordinate(6, 2), new Coordinate(4, 0) };
LinearRing ring = geometryFactory.createLinearRing( coords );
LinearRing holes[] = null; Polygon polygon = geometryFactory.createPolygon(ring, holes );

5.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
WKTReader reader = new WKTReader( geometryFactory );
Polygon polygon = (Polygon) reader.read("POLYGON((20 10, 30 0, 40 10, 30 20, 20 10))");

6、创建多面(MultiPolygon)

6.1 通过Polygon[ ] 创建

GeometryFactory#createMultiPolygon(Polygon[])

6.2 通过WKT创建

GeometryFactory geometryFactory = JTSFactoryFinder.getGeometryFactory( null );
WKTReader reader = new WKTReader( geometryFactory );
MultiPolygon multiPolygon = (MultiPolygon) reader.read("MULTIPOLYGON(((1 1,5 1,5 5,1 5,1 1),(2 2,2 3,3 3,3 2,2 2)),((6 3,9 2,9 4,6 3)))");

五、Geometry操作方法

1、几何关系判断(返回值 boolean)

2、几何关系分析(返回值 几何对象)

2.1 buffer(缓冲区分析)

public Geometry buffer(double distance);

 distance 参数:缓冲区扩展的距离(可以是正数(向外扩展)、负数(向内扩展)或 0(边界))。示意图如下(注:绿色线代表扩展之后的):

2.2 intersection(交叉分析)

public Geometry intersection(Geometry other);

 geometryA.intersection(geometryB):获取两个几何体之间的交叉部分的几何体

2.3 convexHull(凸壳分析)

包含几何形体的所有点的最小凸壳多边形(外包多边形)。示意图如下:

2.4 union(联合分析)

获取多面体所有点的集合。示意图如下:

2.5 difference(差异分析)

获取一个多面体里有,另一个多面体里没有的点的集合。示意图如下:

2.6 symDifference(对称差异分析)

不同时在两个多面体中的所有点的集合。示意图如下:

### 解决无效几何图形问题的方法 在处理 ANSYS Workbench 中的“Invalid Geometry”错误时,通常需要仔细检查模型中的几何结构是否存在不连续性或其他潜在问题。以下是一些可能的原因以及解决方案: #### 几何验证的重要性 几何体的有效性直接影响仿真分析的结果质量。如果几何体存在缺陷,则可能导致求解器无法正常运行或计算失败。因此,在创建或导入几何之前,应确保其满足基本的质量标准[^1]。 #### 常见原因及对应措施 1. **重叠面或边** 当两个或者多个表面相互覆盖而未被正确识别为单一实体时,可能会引发此类警告消息。可以尝试通过布尔操作来清理这些冗余部分。 2. **零厚度区域** 如果某些部位具有极小甚至接近于无的实际尺寸(即所谓的“针孔效应”),也可能触发该类异常提示。建议调整公差设置或将这些问题区段重新建模以消除过薄现象。 3. **自由边/悬空节点** 自由边缘是指那些不属于任何体积对象的一部分但却仍然存在于整体装配当中的线条;同样地,“悬挂结点”指的是孤立存在的顶点而非连接到其他构件上的端点形式。这两种情况都需删除掉才能继续下一步骤工作流程执行下去。 4. **拓扑复杂度超出支持范围** 对非常复杂的形状进行有限元网格划分有时会遇到困难,因为软件难以自动适应所有的细节特征。此时可考虑简化原始设计文件后再提交给程序做进一步处理。 5. **坐标系变换误差** 在不同参照框架之间转换过程中产生的舍入偏差也有可能造成最终呈现出来的轮廓不符合预期规格要求。务必确认所有参数单位保持一致并精确控制数值输入过程。 6. **数据交换格式丢失精度** 使用STEP、IGES等通用接口导出再读回CAD图纸期间难免会有一定程度的信息损失风险发生。所以最好尽量采用原生应用程序专属保存方式减少不必要的失真可能性。 7. **GIS 数据中的无效几何** 在地理信息系统 (GIS) 领域中,`MDSYS.SDO_Geometry`, `MDSYS.ST_Geometry`, 和 `SDE.ST_Geometry` 是用于表示空间数据的不同几何类型。对于 GIS 数据而言,无效几何可能是由于缩放比例的变化引起的。例如,纽约市在一个州地图上是一个点,但在城市地图上则由几个多边形组成[^3]。这种情况下,可以通过修复工具或手动编辑来纠正几何问题。 8. **数据库存储与查询** 确保使用的几何类型适合具体的应用场景,并且在数据库中正确存储和检索几何数据。这涉及到理解每种几何类型的特性和适用场合[^2]。 ```python def validate_geometry(geometry): """ A function to check and repair invalid geometries. Args: geometry: The input geometry object that needs validation. Returns: bool: True if valid after repairs; False otherwise. """ try: # Attempt repairing the geometry using built-in methods or libraries repaired_geom = geometry.repair() # Validate whether it's now clean without errors if not repaired_geom.is_valid(): raise ValueError("Geometry could not be fully validated.") return True except Exception as e: print(f"Error during geometry processing: {str(e)}") return False ``` 上述代码片段展示了一个简单的函数模板,用来检测并尝试修正传入的几何对象是否有误。实际应用时可根据所选平台的具体 API 进行适当修改。 ---
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值