From 7f6ae65e62bac16b71fe788f8a2ee281a7cb726d Mon Sep 17 00:00:00 2001 From: xiaoyan Date: Tue, 23 May 2023 15:41:36 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0geometry=E5=8F=B3?= =?UTF-8?q?=E7=A7=BB=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/navinfo/omqs/db/ImportPreProcess.kt | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/app/src/main/java/com/navinfo/omqs/db/ImportPreProcess.kt b/app/src/main/java/com/navinfo/omqs/db/ImportPreProcess.kt index ba4a91d7..dfdf88ea 100644 --- a/app/src/main/java/com/navinfo/omqs/db/ImportPreProcess.kt +++ b/app/src/main/java/com/navinfo/omqs/db/ImportPreProcess.kt @@ -1,6 +1,11 @@ package com.navinfo.omqs.db import com.navinfo.collect.library.data.entity.RenderEntity +import com.navinfo.collect.library.utils.GeometryTools +import org.locationtech.jts.algorithm.Angle +import org.locationtech.jts.geom.Coordinate +import org.locationtech.jts.geom.Geometry + class ImportPreProcess { /** @@ -11,4 +16,38 @@ class ImportPreProcess { renderEntity.properties["foo"] = "bar" return renderEntity } + + /** + * 计算指定数据指定方向的坐标 + * */ + fun translateRight(renderEntity: RenderEntity): RenderEntity { + // 获取当前renderEntity的geometry + val geometry = renderEntity.wkt + var angle = 0.0 // geometry的角度,如果是点,获取angle,如果是线,获取最后两个点的方向 + var point = Coordinate(geometry?.coordinate) + if (Geometry.TYPENAME_POINT == geometry?.geometryType) { + angle = if(renderEntity?.properties?.get("angle") == null) 0.0 else renderEntity?.properties?.get("angle")?.toDouble()!! + } else if (Geometry.TYPENAME_LINESTRING == geometry?.geometryType) { + val p1: Coordinate = geometry.coordinates.get(geometry.coordinates.size - 2) + val p2: Coordinate = geometry.coordinates.get(geometry.coordinates.size - 1) + // 计算线段的方向 + angle = Angle.angle(p1, p2) + point = p2 + } + + // 将角度转换为弧度 + val radian = Math.toRadians(angle) + + // 计算偏移距离 + val dx: Double = GeometryTools.convertDistanceToDegree(5.0, geometry?.coordinate?.y!!) * Math.cos(radian) + val dy: Double = GeometryTools.convertDistanceToDegree(5.0, geometry?.coordinate?.y!!) * Math.sin(radian) + + // 计算偏移后的点 + val coord = + Coordinate(point.getX() + dy, point.getY() - dx) + + // 将这个点记录在数据中 + renderEntity.properties["geometry"] = GeometryTools.createGeometry(doubleArrayOf(coord.x, coord.y)).toString() + return renderEntity + } } \ No newline at end of file