feat: 增加车道边线渲染

This commit is contained in:
2023-06-02 10:05:53 +08:00
parent e9735ee4d8
commit 6a77e69ed7
14 changed files with 529 additions and 159 deletions

View File

@@ -20,6 +20,19 @@
"code": 2010,
"name": "道路方向"
},
"2013": {
"table": "OMDB_LANE_MARK_BOUNDARYTYPE",
"code": 2013,
"name": "车道边界类型",
"transformer": [
{
"k": "geometry",
"v": "~",
"klib": "geometry",
"vlib": "unpackingLaneBoundary()"
}
]
},
"2019": {
"table": "OMDB_LINK_SPEEDLIMIT",
"code": 2019,
@@ -55,6 +68,11 @@
"code": 2041,
"name": "车道数"
},
"2083":{
"table": "OMDB_RDBOUND_BOUNDARYTYPE",
"code": 2083,
"name": "道路边界类型"
},
"2201":{
"table": "OMDB_BRIDGE",
"code": 2201,
@@ -131,7 +149,7 @@
"k": "geometry",
"v": "~",
"klib": "geometry",
"vlib": "translateRightWithAngle()"
"vlib": "generateRestrictionRerference()"
}
]
},

View File

@@ -1,7 +1,11 @@
package com.navinfo.omqs.db
import com.navinfo.collect.library.data.entity.ReferenceEntity
import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.collect.library.utils.GeometryTools
import io.realm.Realm
import org.json.JSONArray
import org.json.JSONObject
import org.locationtech.jts.algorithm.Angle
import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.Geometry
@@ -60,7 +64,9 @@ class ImportPreProcess {
var radian = 0.0 // geometry的角度如果是点获取angle如果是线获取最后两个点的方向
var point = Coordinate(geometry?.coordinate)
if (Geometry.TYPENAME_POINT == geometry?.geometryType) {
val angle = if(renderEntity?.properties?.get("angle") == null) 0.0 else renderEntity?.properties?.get("angle")?.toDouble()!!
// angle为正北方向夹角需要将其转换为与正东方向夹角
var angle = if(renderEntity?.properties?.get("angle") == null) 0.0 else renderEntity?.properties?.get("angle")?.toDouble()!!
angle-=90
radian = Math.toRadians(angle)
} else if (Geometry.TYPENAME_LINESTRING == geometry?.geometryType) {
val p1: Coordinate = geometry.coordinates.get(geometry.coordinates.size - 2)
@@ -77,6 +83,7 @@ class ImportPreProcess {
// 计算偏移后的点
// val coordMid =
// Coordinate(point.getX() + dy, point.getY() - dx)
// 计算指定距离外与当前位置成90度夹角的点位
val pointStart = GeoPoint(point.getY() - dx, point.getX() + dy)
// val pointStart = GeoPoint(pointMid.latitude-dy, pointMid.longitude-dx)
val pointEnd = GeoPoint(pointStart.latitude- dx, pointStart.longitude+ dy)
@@ -107,4 +114,66 @@ class ImportPreProcess {
}
return "0"
}
/**
* 解析车道边线数据二级属性
* */
fun unpackingLaneBoundary(renderEntity: RenderEntity) {
if (renderEntity.code == 2013&&!renderEntity.properties["shapeList"].isNullOrEmpty()&&renderEntity.properties["shapeList"]!="null") {
// 解析shapeList将数组中的属性放会properties
val shapeList = JSONArray(renderEntity.properties["shapeList"])
val shape = shapeList.getJSONObject(0)
for (key in shape.keys()) {
renderEntity.properties[key] = shape[key].toString()
}
}
}
/**
* 自动生成普通交限的参考数据
* */
fun generateRestrictionRerference(renderEntity: RenderEntity) {
// 获取当前renderEntity的geometry
val geometry = renderEntity.wkt
var radian = 0.0 // geometry的角度如果是点获取angle如果是线获取最后两个点的方向
var point = Coordinate(geometry?.coordinate)
if (Geometry.TYPENAME_POINT == geometry?.geometryType) {
var angle = if(renderEntity?.properties?.get("angle") == null) 0.0 else renderEntity?.properties?.get("angle")?.toDouble()!!
radian = Math.toRadians(angle)
}
// 计算偏移距离
val dx: Double = GeometryTools.convertDistanceToDegree(3.0, geometry?.coordinate?.y!!) * Math.sin(radian)
val dy: Double = GeometryTools.convertDistanceToDegree(3.0, geometry?.coordinate?.y!!) * Math.cos(radian)
// 计算偏移后的点
val pointTranS =
GeoPoint(point.getY() - dx, point.getX() + dy) // 向右偏移的点
// 计算与原有方向平行的终点坐标
val pointTranE = GeoPoint(pointTranS.latitude + dy, pointTranS.longitude + dx)
renderEntity.geometry = GeometryTools.createGeometry(pointTranS).toString()
// 将这个点记录在数据中
val startEndReference = ReferenceEntity()
startEndReference.renderEntityId = renderEntity.id
startEndReference.name = "普通交限参考线"
startEndReference.table = renderEntity.table
// 起终点坐标组成的线
startEndReference.geometry = GeometryTools.createLineString(listOf(GeoPoint(point.y, point.x), pointTranS)).toString()
startEndReference.properties["qi_table"] = renderEntity.table
startEndReference.properties["type"] = "s_2_e"
Realm.getDefaultInstance().insert(startEndReference)
val angleReference = ReferenceEntity()
angleReference.renderEntityId = renderEntity.id
angleReference.name = "普通交限参考方向"
angleReference.table = renderEntity.table
// 与原有方向指向平行的线
angleReference.geometry = GeometryTools.createLineString(listOf(pointTranS, pointTranE)).toString()
angleReference.properties["qi_table"] = renderEntity.table
angleReference.properties["type"] = "angle"
Realm.getDefaultInstance().insert(angleReference)
}
}

View File

@@ -228,7 +228,7 @@ class LoginViewModel @Inject constructor(
.name("OMQS.realm")
.encryptionKey(password)
// .modules(Realm.getDefaultModule(), MyRealmModule())
.schemaVersion(1)
.schemaVersion(2)
.build()
Realm.setDefaultConfiguration(config)
// 拷贝配置文件到用户目录下

View File

@@ -111,7 +111,7 @@ class PersonalCenterFragment : BaseFragment(), FSAFActivityCallbacks {
viewModel.readRealmData()
// 定位到指定位置
niMapController.mMapView.vtmMap.animator()
.animateTo(GeoPoint(28.724637921467508 ,115.83412668023867 ))
.animateTo(GeoPoint(40.03342017243118, 116.3211538409127 ))
}
R.id.personal_center_menu_task_list -> {
findNavController().navigate(R.id.TaskManagerFragment)