优化数据库查询

This commit is contained in:
squallzhjch 2023-10-25 10:17:16 +08:00
parent 9cf39d476c
commit c7122376cf
19 changed files with 1301 additions and 840 deletions

View File

@ -59,15 +59,7 @@
"name": "道路方向", "name": "道路方向",
"zoomMin": 15, "zoomMin": 15,
"zoomMax": 17, "zoomMax": 17,
"checkLinkId": false, "checkLinkId": false
"transformer": [
{
"k": "geometry",
"v": "~",
"klib": "geometry",
"vlib": "addRdLinkDirect()"
}
]
}, },
"2011": { "2011": {
"table": "OMDB_LINK_NAME", "table": "OMDB_LINK_NAME",

View File

@ -4,6 +4,7 @@ import android.util.Log
import com.google.gson.annotations.Expose import com.google.gson.annotations.Expose
import com.navinfo.collect.library.data.entity.RenderEntity import com.navinfo.collect.library.data.entity.RenderEntity
import com.navinfo.omqs.db.ImportPreProcess import com.navinfo.omqs.db.ImportPreProcess
import io.realm.Realm
import kotlin.reflect.KFunction import kotlin.reflect.KFunction
import kotlin.reflect.KParameter import kotlin.reflect.KParameter
import kotlin.reflect.full.declaredMemberFunctions import kotlin.reflect.full.declaredMemberFunctions
@ -12,13 +13,15 @@ import kotlin.reflect.full.declaredMemberFunctions
class ImportConfig { class ImportConfig {
@Expose @Expose
var tableMap: MutableMap<String, TableInfo> = mutableMapOf() var tableMap: MutableMap<String, TableInfo> = mutableMapOf()
@Expose @Expose
val tableGroupName: String = "OMDB数据" val tableGroupName: String = "OMDB数据"
@Expose
var checked : Boolean = true
val preProcess: ImportPreProcess = ImportPreProcess()
fun transformProperties(renderEntity: RenderEntity): RenderEntity? { @Expose
var checked: Boolean = true
val preProcess: ImportPreProcess = ImportPreProcess()
fun transformProperties(renderEntity: RenderEntity, realm: Realm): RenderEntity? {
preProcess.realm = realm
val transformList = tableMap[renderEntity.code.toString()]?.transformer val transformList = tableMap[renderEntity.code.toString()]?.transformer
if (transformList.isNullOrEmpty()) { if (transformList.isNullOrEmpty()) {
Log.e("qj", "子表转换为空===${renderEntity.code}") Log.e("qj", "子表转换为空===${renderEntity.code}")
@ -27,7 +30,7 @@ class ImportConfig {
Log.e("qj", "子表转换不为空===${renderEntity.code}") Log.e("qj", "子表转换不为空===${renderEntity.code}")
for (transform in transformList) { for (transform in transformList) {
// 开始执行转换 // 开始执行转换
val key:String = transform.k val key: String = transform.k
val value = transform.v val value = transform.v
val keylib = transform.klib val keylib = transform.klib
val valuelib = transform.vlib val valuelib = transform.vlib
@ -36,7 +39,10 @@ class ImportConfig {
continue continue
} }
// 如果key和value都为空说明当前数据需要增加一个新字段 // 如果key和value都为空说明当前数据需要增加一个新字段
if (key.isNullOrEmpty()&&value.isNullOrEmpty()&&!renderEntity.properties.containsKey(keylib)) { if (key.isNullOrEmpty() && value.isNullOrEmpty() && !renderEntity.properties.containsKey(
keylib
)
) {
renderEntity.properties[keylib] = valuelib renderEntity.properties[keylib] = valuelib
continue continue
} }
@ -44,26 +50,32 @@ class ImportConfig {
m@ for (k in processKeyOrValue(key)) { m@ for (k in processKeyOrValue(key)) {
if (renderEntity.properties.containsKey(k)) { // json配置的key可以匹配到数据 if (renderEntity.properties.containsKey(k)) { // json配置的key可以匹配到数据
for (v in processKeyOrValue(value)) { for (v in processKeyOrValue(value)) {
if ("~" == v ) { // ~符可以匹配任意元素 if ("~" == v) { // ~符可以匹配任意元素
if (valuelib.endsWith(")")) { // 以()结尾说明该value配置是一个function需要通过反射调用指定方法 if (valuelib.endsWith(")")) { // 以()结尾说明该value配置是一个function需要通过反射调用指定方法
// 获取方法名 // 获取方法名
val methodName = valuelib.substringBefore("(") val methodName = valuelib.substringBefore("(")
// 获取参数 // 获取参数
val params: List<String> = valuelib.substringAfter("(").substringBefore(")").split(",").filter{ it.isNotEmpty() }.map { it.trim() } val params: List<String> =
val method = preProcess::class.members.filter { it.name == methodName }.first() as KFunction<*> valuelib.substringAfter("(").substringBefore(")").split(",")
.filter { it.isNotEmpty() }.map { it.trim() }
val method =
preProcess::class.members.filter { it.name == methodName }
.first() as KFunction<*>
val methodParams = method.parameters val methodParams = method.parameters
val callByParams = mutableMapOf<KParameter, Any>( val callByParams = mutableMapOf<KParameter, Any>(
methodParams[0] to preProcess, methodParams[0] to preProcess,
methodParams[1] to renderEntity methodParams[1] to renderEntity,
) )
for ((index, value) in params.withIndex()) { for ((index, value) in params.withIndex()) {
// 前2个参数确定为对象本身和RenderEntity因此自定义参数从index+2开始设置 // 前2个参数确定为对象本身和RenderEntity因此自定义参数从index+2开始设置
if (methodParams.size>index+2) { if (methodParams.size > index + 2) {
callByParams[methodParams[index+2]] = value.replace("'", "") callByParams[methodParams[index + 2]] =
value.replace("'", "")
} }
} }
when(val result = method.callBy(callByParams)) { // 如果方法返回的数据类型是boolean且返回为false则该数据不处理 when (val result =
method.callBy(callByParams)) { // 如果方法返回的数据类型是boolean且返回为false则该数据不处理
is Boolean -> is Boolean ->
if (!result) { if (!result) {
return null return null
@ -78,8 +90,12 @@ class ImportConfig {
// 获取方法名 // 获取方法名
val methodName = valuelib.substringBefore("(") val methodName = valuelib.substringBefore("(")
// 获取参数 // 获取参数
val params: List<String> = valuelib.substringAfter("(").substringBefore(")").split(",").filter{ it.isNotEmpty() }.map { it.trim() } val params: List<String> =
val method = preProcess::class.members.filter { it.name == methodName }.first() as KFunction<*> valuelib.substringAfter("(").substringBefore(")").split(",")
.filter { it.isNotEmpty() }.map { it.trim() }
val method =
preProcess::class.members.filter { it.name == methodName }
.first() as KFunction<*>
val methodParams = method.parameters val methodParams = method.parameters
val callByParams = mutableMapOf<KParameter, Any>( val callByParams = mutableMapOf<KParameter, Any>(
@ -88,11 +104,11 @@ class ImportConfig {
) )
for ((index, value) in params.withIndex()) { for ((index, value) in params.withIndex()) {
// 前2个参数确定为对象本身和RenderEntity因此自定义参数从index+2开始设置 // 前2个参数确定为对象本身和RenderEntity因此自定义参数从index+2开始设置
if (methodParams.size>index+2) { if (methodParams.size > index + 2) {
callByParams[methodParams[index+2]] = value callByParams[methodParams[index + 2]] = value
} }
} }
when(val result = method.callBy(callByParams)) { when (val result = method.callBy(callByParams)) {
is Boolean -> is Boolean ->
if (!result) { if (!result) {
return null return null
@ -107,6 +123,7 @@ class ImportConfig {
} }
} }
} }
preProcess.realm = null
return renderEntity return renderEntity
} }
@ -125,14 +142,15 @@ class TableInfo {
val zoomMin: Int = 16 val zoomMin: Int = 16
val zoomMax: Int = 21 val zoomMax: Int = 21
val checkLinkId: Boolean = true//是否需要校验linkid val checkLinkId: Boolean = true//是否需要校验linkid
val filterData : Boolean = false//是否需要过滤数据 val filterData: Boolean = false//是否需要过滤数据
val existSubCode : Boolean = false//是否存在子编码 val existSubCode: Boolean = false//是否存在子编码
val catch: Boolean = false//是否需要捕捉 // 需要根据丹丹提供的捕捉原则进行设置参考文档W行设置条件https://navinfo.feishu.cn/sheets/shtcnfsxKZhekU26ezBcHgl7aWh?sheet=BZd6yM val catch: Boolean =
false//是否需要捕捉 // 需要根据丹丹提供的捕捉原则进行设置参考文档W行设置条件https://navinfo.feishu.cn/sheets/shtcnfsxKZhekU26ezBcHgl7aWh?sheet=BZd6yM
val name: String = "" val name: String = ""
var checked : Boolean = true var checked: Boolean = true
var transformer: MutableList<Transform> = mutableListOf() var transformer: MutableList<Transform> = mutableListOf()
var is3D : Boolean = false // 是否支持3D默认情况下都不支持3D在数据导入阶段会自动抹去Z轴高程信息 var is3D: Boolean = false // 是否支持3D默认情况下都不支持3D在数据导入阶段会自动抹去Z轴高程信息
} }
class Transform { class Transform {

File diff suppressed because it is too large Load Diff

View File

@ -20,41 +20,43 @@ import java.util.*
class ImportPreProcess { class ImportPreProcess {
val code2NameMap = Code2NameMap() val code2NameMap = Code2NameMap()
// lateinit var cacheRdLink: Map<String?, RenderEntity>
// lateinit var cacheRdLink: Map<String?, RenderEntity>
val defaultTranslateDistance = 3.0 val defaultTranslateDistance = 3.0
val testFlag: Boolean = false val testFlag: Boolean = false
var realm: Realm? = null
fun checkCircleRoad(renderEntity: RenderEntity): Boolean { fun checkCircleRoad(renderEntity: RenderEntity): Boolean {
val linkInId = renderEntity.properties["linkIn"] val linkInId = renderEntity.properties["linkIn"]
val linkOutId = renderEntity.properties["linkOut"] val linkOutId = renderEntity.properties["linkOut"]
// // 根据linkIn和linkOut获取对应的link数据 // // 根据linkIn和linkOut获取对应的link数据
// val linkInEntity = cacheRdLink[linkInId] // val linkInEntity = cacheRdLink[linkInId]
// val linkOutEntity = cacheRdLink[linkOutId] // val linkOutEntity = cacheRdLink[linkOutId]
realm?.let {
val linkInEntity = it.where(RenderEntity::class.java)
.equalTo("code", DataCodeEnum.OMDB_RD_LINK.code)
.and().equalTo("linkPid", linkInId)
.findFirst()
val linkOutEntity = it.where(RenderEntity::class.java)
.equalTo("code", DataCodeEnum.OMDB_RD_LINK.code)
.and().equalTo("linkPid", linkOutId)
.findFirst()
// 根据linkIn和linkOut从数据库获取对应的link数据 Log.d(
Realm.getInstance(Constant.currentInstallTaskConfig) "checkCircleRoad",
.use { realm -> "LinkInEntity: ${linkInId}- ${linkInEntity?.properties?.get("snodePid")}LinkOutEntity: ${linkOutId}- ${
val linkInEntity = realm.where(RenderEntity::class.java) linkOutEntity?.properties?.get("enodePid")
.equalTo("code", DataCodeEnum.OMDB_RD_LINK.code) }"
.and().equalTo("linkPid", linkInId) )
.findFirst() // 查询linkIn的sNode和linkOut的eNode是否相同如果相同认为数据是环形路口返回false
val linkOutEntity = realm.where(RenderEntity::class.java) if (linkInEntity != null && linkOutEntity != null) {
.equalTo("code", DataCodeEnum.OMDB_RD_LINK.code) if (linkInEntity.properties["snodePid"] == linkOutEntity.properties["enodePid"] || linkInEntity.properties["enodePid"] == linkOutEntity.properties["snodePid"] || linkInEntity.properties["snodePid"] == linkOutEntity.properties["snodePid"] || linkInEntity.properties["enodePid"] == linkOutEntity.properties["enodePid"]) {
.and().equalTo("linkPid", linkOutId) return false
.findFirst()
Log.d(
"checkCircleRoad",
"LinkInEntity: ${linkInId}- ${linkInEntity?.properties?.get("snodePid")}LinkOutEntity: ${linkOutId}- ${
linkOutEntity?.properties?.get("enodePid")
}"
)
// 查询linkIn的sNode和linkOut的eNode是否相同如果相同认为数据是环形路口返回false
if (linkInEntity != null && linkOutEntity != null) {
if (linkInEntity.properties["snodePid"] == linkOutEntity.properties["enodePid"] || linkInEntity.properties["enodePid"] == linkOutEntity.properties["snodePid"] || linkInEntity.properties["snodePid"] == linkOutEntity.properties["snodePid"] || linkInEntity.properties["enodePid"] == linkOutEntity.properties["enodePid"]) {
return false
}
} }
} }
}
// // 根据linkIn和linkOut从数据库获取对应的link数据
// Realm.getInstance(Constant.currentInstallTaskConfig)
return true return true
} }
@ -78,8 +80,8 @@ class ImportPreProcess {
} }
} }
// 如果是正向,则取最后一个点作为渲染图标的位置 // 如果是正向,则取最后一个点作为渲染图标的位置
var point = geometry!!.coordinates[geometry!!.coordinates.size-1] var point = geometry!!.coordinates[geometry!!.coordinates.size - 1]
if (isReverse){ if (isReverse) {
// 逆向的话取第一个点作为渲染图标的位置 // 逆向的话取第一个点作为渲染图标的位置
point = geometry.coordinates[0] point = geometry.coordinates[0]
} }
@ -214,16 +216,16 @@ class ImportPreProcess {
startGeometry!!.coordinates[startGeometry.numPoints - 1] // 获取这个geometry对应的结束点坐标 startGeometry!!.coordinates[startGeometry.numPoints - 1] // 获取这个geometry对应的结束点坐标
if (translateGeometry.geometryType == Geometry.TYPENAME_LINESTRING) { // 如果是线数据,则取倒数第二个点作为偏移的起止点 if (translateGeometry.geometryType == Geometry.TYPENAME_LINESTRING) { // 如果是线数据,则取倒数第二个点作为偏移的起止点
pointEnd = pointEnd =
translateGeometry!!.coordinates[translateGeometry.numPoints - 2] // 获取这个geometry对应的结束点坐标 translateGeometry.coordinates[translateGeometry.numPoints - 2] // 获取这个geometry对应的结束点坐标
} }
if (startGeometry.geometryType == Geometry.TYPENAME_LINESTRING) { // 如果是线数据,则取倒数第二个点作为偏移的起止点 if (startGeometry.geometryType == Geometry.TYPENAME_LINESTRING) { // 如果是线数据,则取倒数第二个点作为偏移的起止点
pointStart = pointStart =
startGeometry!!.coordinates[startGeometry.numPoints - 2] // 获取这个geometry对应的结束点坐标 startGeometry.coordinates[startGeometry.numPoints - 2] // 获取这个geometry对应的结束点坐标
} }
// 将这个起终点的线记录在数据中 // 将这个起终点的线记录在数据中
val startEndReference = ReferenceEntity() val startEndReference = ReferenceEntity()
startEndReference.renderEntityId = renderEntity.id // startEndReference.renderEntityId = renderEntity.id
startEndReference.name = "${renderEntity.name}参考线" startEndReference.name = "${renderEntity.name}参考线"
startEndReference.table = renderEntity.table startEndReference.table = renderEntity.table
startEndReference.zoomMin = renderEntity.zoomMin startEndReference.zoomMin = renderEntity.zoomMin
@ -253,7 +255,7 @@ class ImportPreProcess {
// 将这个起终点的线记录在数据中 // 将这个起终点的线记录在数据中
val startReference = ReferenceEntity() val startReference = ReferenceEntity()
startReference.renderEntityId = renderEntity.id // startReference.renderEntityId = renderEntity.id
startReference.name = "${renderEntity.name}参考点" startReference.name = "${renderEntity.name}参考点"
startReference.code = renderEntity.code startReference.code = renderEntity.code
startReference.table = renderEntity.table startReference.table = renderEntity.table
@ -290,7 +292,7 @@ class ImportPreProcess {
Log.e("qj", "generateS2EReferencePoint===1") Log.e("qj", "generateS2EReferencePoint===1")
val endReference = ReferenceEntity() val endReference = ReferenceEntity()
endReference.renderEntityId = renderEntity.id // endReference.renderEntityId = renderEntity.id
endReference.name = "${renderEntity.name}参考点" endReference.name = "${renderEntity.name}参考点"
endReference.code = renderEntity.code endReference.code = renderEntity.code
endReference.table = renderEntity.table endReference.table = renderEntity.table
@ -405,7 +407,7 @@ class ImportPreProcess {
val coorEnd = Coordinate(pointStart.getX() + dx, pointStart.getY() + dy, pointStart.z) val coorEnd = Coordinate(pointStart.getX() + dx, pointStart.getY() + dy, pointStart.z)
val angleReference = ReferenceEntity() val angleReference = ReferenceEntity()
angleReference.renderEntityId = renderEntity.id // angleReference.renderEntityId = renderEntity.id
angleReference.name = "${renderEntity.name}参考方向" angleReference.name = "${renderEntity.name}参考方向"
angleReference.table = renderEntity.table angleReference.table = renderEntity.table
angleReference.zoomMin = renderEntity.zoomMin angleReference.zoomMin = renderEntity.zoomMin
@ -492,7 +494,7 @@ class ImportPreProcess {
for (i in 0 until laneInfoDirectArray.length()) { for (i in 0 until laneInfoDirectArray.length()) {
// 根据后续的数据生成辅助表数据 // 根据后续的数据生成辅助表数据
val referenceEntity = ReferenceEntity() val referenceEntity = ReferenceEntity()
referenceEntity.renderEntityId = renderEntity.id // referenceEntity.renderEntityId = renderEntity.id
referenceEntity.name = "${renderEntity.name}参考方向" referenceEntity.name = "${renderEntity.name}参考方向"
referenceEntity.table = renderEntity.table referenceEntity.table = renderEntity.table
referenceEntity.enable = renderEntity.enable referenceEntity.enable = renderEntity.enable
@ -500,7 +502,7 @@ class ImportPreProcess {
referenceEntity.zoomMin = renderEntity.zoomMin referenceEntity.zoomMin = renderEntity.zoomMin
referenceEntity.zoomMax = renderEntity.zoomMax referenceEntity.zoomMax = renderEntity.zoomMax
// 与原数据使用相同的geometry // 与原数据使用相同的geometry
referenceEntity.geometry = renderEntity.geometry.toString() referenceEntity.geometry = renderEntity.geometry
referenceEntity.properties["qi_table"] = renderEntity.table referenceEntity.properties["qi_table"] = renderEntity.table
referenceEntity.properties["currentDirect"] = referenceEntity.properties["currentDirect"] =
laneInfoDirectArray[i].toString().split(",").distinct().joinToString("_") laneInfoDirectArray[i].toString().split(",").distinct().joinToString("_")
@ -579,7 +581,7 @@ class ImportPreProcess {
} }
// 获取最小的shape值将其记录增加记录在properties的name属性下 // 获取最小的shape值将其记录增加记录在properties的name属性下
if (shape != null) { if (shape != null) {
renderEntity.properties["name"] = shape["name"].toString() renderEntity.properties["name"] = shape.optString("name", "")
} else { } else {
renderEntity.properties["name"] = "" renderEntity.properties["name"] = ""
} }
@ -588,25 +590,25 @@ class ImportPreProcess {
/** /**
* 通过rdDirect对象向rdLink的relation字段 * 通过rdDirect对象向rdLink的relation字段
* */ * */
fun addRdLinkDirect(renderEntity: RenderEntity) { // fun addRdLinkDirect(renderEntity: RenderEntity) {
// 尝试更新RD_link的relation记录中的方向字段 // // 尝试更新RD_link的relation记录中的方向字段
val rdLinkEntity = queryRdLink(renderEntity.properties["linkPid"]!!) // val rdLinkEntity = queryRdLink(renderEntity.properties["linkPid"]!!)
if (rdLinkEntity?.linkRelation == null) { // if (rdLinkEntity?.linkRelation == null) {
rdLinkEntity?.linkRelation = LinkRelation() // rdLinkEntity?.linkRelation = LinkRelation()
} // }
rdLinkEntity?.linkRelation?.direct = renderEntity.properties["direct"]!!.toInt() // rdLinkEntity?.linkRelation?.direct = renderEntity.properties["direct"]!!.toInt()
Realm.getInstance(Constant.currentInstallTaskConfig).insertOrUpdate(rdLinkEntity) // Realm.getInstance(Constant.currentInstallTaskConfig).insertOrUpdate(rdLinkEntity)
} // }
/** /**
* 查询指定的Rdlink数据 * 查询指定的Rdlink数据
* */ * */
fun queryRdLink(rdLinkId: String): RenderEntity? { // fun queryRdLink(rdLinkId: String): RenderEntity? {
return Realm.getInstance(Constant.currentInstallTaskConfig).where(RenderEntity::class.java) // //////// return Realm.getInstance(Constant.currentInstallTaskConfig).where(RenderEntity::class.java)
.equalTo("code", DataCodeEnum.OMDB_RD_LINK.code) // .equalTo("code", DataCodeEnum.OMDB_RD_LINK.code)
.and().equalTo("linkPid", rdLinkId) // .and().equalTo("linkPid", rdLinkId)
.findFirst() // .findFirst()
} // }
/** /**
* 生成电子眼对应的渲染名称 * 生成电子眼对应的渲染名称
@ -626,21 +628,28 @@ class ImportPreProcess {
* 生成车道中心线面宽度 * 生成车道中心线面宽度
* */ * */
fun generateAddWidthLine(renderEntity: RenderEntity) { fun generateAddWidthLine(renderEntity: RenderEntity) {
// 添加车道中心面渲染原则,根据车道宽度进行渲染 try {
val angleReference = ReferenceEntity() // 添加车道中心面渲染原则,根据车道宽度进行渲染
angleReference.renderEntityId = renderEntity.id val angleReference = ReferenceEntity()
angleReference.name = "${renderEntity.name}车道中线面" // angleReference.renderEntityId = renderEntity.id
angleReference.table = renderEntity.table angleReference.name = "${renderEntity.name}车道中线面"
angleReference.geometry = GeometryTools.createGeometry(renderEntity.geometry).buffer(0.000035).toString()//GeometryTools.computeLine(0.000035,0.000035,renderEntity.geometry) angleReference.table = renderEntity.table
angleReference.properties["qi_table"] = renderEntity.table angleReference.geometry =
angleReference.properties["widthProperties"] = "3" GeometryTools.createGeometry(renderEntity.geometry).buffer(0.000035)
angleReference.zoomMin = renderEntity.zoomMin .toString()//GeometryTools.computeLine(0.000035,0.000035,renderEntity.geometry)
angleReference.zoomMax = renderEntity.zoomMax angleReference.properties["qi_table"] = renderEntity.table
angleReference.taskId = renderEntity.taskId angleReference.properties["widthProperties"] = "3"
angleReference.enable = renderEntity.enable angleReference.zoomMin = renderEntity.zoomMin
val listResult = mutableListOf<ReferenceEntity>() angleReference.zoomMax = renderEntity.zoomMax
listResult.add(angleReference) angleReference.taskId = renderEntity.taskId
insertData(listResult) angleReference.enable = renderEntity.enable
val listResult = mutableListOf<ReferenceEntity>()
listResult.add(angleReference)
insertData(listResult)
} catch (e: Exception) {
Log.e("jingo", "车道中心线 generateAddWidthLine ${e.message}")
}
} }
@ -656,7 +665,7 @@ class ImportPreProcess {
for (i in 0 until nodeListJsonArray.length()) { for (i in 0 until nodeListJsonArray.length()) {
val nodeJSONObject = nodeListJsonArray.getJSONObject(i) val nodeJSONObject = nodeListJsonArray.getJSONObject(i)
val intersectionReference = ReferenceEntity() val intersectionReference = ReferenceEntity()
intersectionReference.renderEntityId = renderEntity.id // intersectionReference.renderEntityId = renderEntity.id
intersectionReference.name = "${renderEntity.name}参考点" intersectionReference.name = "${renderEntity.name}参考点"
intersectionReference.code = renderEntity.code intersectionReference.code = renderEntity.code
intersectionReference.table = renderEntity.table intersectionReference.table = renderEntity.table
@ -823,7 +832,7 @@ class ImportPreProcess {
val coorEnd = Coordinate(pointStart.getX() + dx, pointStart.getY() + dy, pointStart.z) val coorEnd = Coordinate(pointStart.getX() + dx, pointStart.getY() + dy, pointStart.z)
val dynamicSrcReference = ReferenceEntity() val dynamicSrcReference = ReferenceEntity()
dynamicSrcReference.renderEntityId = renderEntity.id // dynamicSrcReference.renderEntityId = renderEntity.id
dynamicSrcReference.name = "${renderEntity.name}动态icon" dynamicSrcReference.name = "${renderEntity.name}动态icon"
dynamicSrcReference.table = renderEntity.table dynamicSrcReference.table = renderEntity.table
dynamicSrcReference.zoomMin = renderEntity.zoomMin dynamicSrcReference.zoomMin = renderEntity.zoomMin
@ -842,13 +851,16 @@ class ImportPreProcess {
insertData(listResult) insertData(listResult)
} }
private fun insertData(list:List<ReferenceEntity>){ private fun insertData(list: List<ReferenceEntity>) {
Log.e("qj", "子表插入==") realm?.let {
if(list!=null&& list.isNotEmpty()){ Log.e("qj", "子表插入==")
Log.e("qj", "子表插入开始==") if (list != null && list.isNotEmpty()) {
Realm.getInstance(Constant.currentInstallTaskConfig).insert(list) Log.e("qj", "子表插入开始==")
Log.e("qj", "子表插入结束==") it.insert(list)
Log.e("qj", "子表插入结束==")
}
} }
} }
/** /**
@ -894,7 +906,8 @@ class ImportPreProcess {
val coorEnd = Coordinate(pointStart.getX() + dx, pointStart.getY() + dy, pointStart.z) val coorEnd = Coordinate(pointStart.getX() + dx, pointStart.getY() + dy, pointStart.z)
// renderEntity.geometry = WKTWriter(3).write(GeometryTools.createLineString(arrayOf(pointStart, coorEnd))) // renderEntity.geometry = WKTWriter(3).write(GeometryTools.createLineString(arrayOf(pointStart, coorEnd)))
renderEntity.geometry = GeometryTools.createGeometry(GeoPoint(centerPoint!!.y, centerPoint.x)).toString() renderEntity.geometry =
GeometryTools.createGeometry(GeoPoint(centerPoint!!.y, centerPoint.x)).toString()
val code = renderEntity.properties["signType"] val code = renderEntity.properties["signType"]
renderEntity.properties["src"] = "assets:omdb/appendix/1105_${code}_0.svg" renderEntity.properties["src"] = "assets:omdb/appendix/1105_${code}_0.svg"
} }
@ -930,9 +943,11 @@ class ImportPreProcess {
val listResult = mutableListOf<ReferenceEntity>() val listResult = mutableListOf<ReferenceEntity>()
val coorEnd = Coordinate(pointStart.getX() + dx, pointStart.getY() + dy, pointStart.z) val coorEnd = Coordinate(pointStart.getX() + dx, pointStart.getY() + dy, pointStart.z)
renderEntity.geometry = WKTWriter(3).write(GeometryTools.createLineString(arrayOf(pointStart, coorEnd))) renderEntity.geometry =
WKTWriter(3).write(GeometryTools.createLineString(arrayOf(pointStart, coorEnd)))
} else { } else {
renderEntity.geometry = GeometryTools.createGeometry(GeoPoint(centerPoint!!.y, centerPoint.x)).toString() renderEntity.geometry =
GeometryTools.createGeometry(GeoPoint(centerPoint!!.y, centerPoint.x)).toString()
} }
} }
} }

View File

@ -65,13 +65,12 @@ class RealmOperateHelper() {
val yEnd = tileYSet.stream().max(Comparator.naturalOrder()).orElse(null) val yEnd = tileYSet.stream().max(Comparator.naturalOrder()).orElse(null)
// 查询realm中对应tile号的数据 // 查询realm中对应tile号的数据
// val realm = getSelectTaskRealmInstance() // val realm = getSelectTaskRealmInstance()
val sql =
" ((tileXMin <= $xStart and tileXMax >= $xStart) or (tileXMin <=$xEnd and tileXMax >=$xStart)) and ((tileYMin <= $yStart and tileYMax >= $yStart) or (tileYMin <=$yEnd and tileYMin >=$yStart))"
val realmList = val realmList =
getSelectTaskRealmTools(realm, RenderEntity::class.java, false) getSelectTaskRealmTools(realm, RenderEntity::class.java, false)
.equalTo("table", DataCodeEnum.OMDB_LINK_DIRECT.name) .equalTo("table", DataCodeEnum.OMDB_LINK_DIRECT.name)
.greaterThanOrEqualTo("tileX", xStart) .rawPredicate(sql)
.lessThanOrEqualTo("tileX", xEnd)
.greaterThanOrEqualTo("tileY", yStart)
.lessThanOrEqualTo("tileY", yEnd)
.findAll() .findAll()
// 将获取到的数据和查询的polygon做相交只返回相交的数据 // 将获取到的数据和查询的polygon做相交只返回相交的数据
val dataList = realm.copyFromRealm(realmList) val dataList = realm.copyFromRealm(realmList)
@ -285,11 +284,11 @@ class RealmOperateHelper() {
val yEnd = tileYSet.stream().max(Comparator.naturalOrder()).orElse(null) val yEnd = tileYSet.stream().max(Comparator.naturalOrder()).orElse(null)
val realm = getSelectTaskRealmInstance() val realm = getSelectTaskRealmInstance()
var realmList = mutableListOf<RenderEntity>() var realmList = mutableListOf<RenderEntity>()
val sql =
" ((tileXMin <= $xStart and tileXMax >= $xStart) or (tileXMin <=$xEnd and tileXMax >=$xStart)) and ((tileYMin <= $yStart and tileYMax >= $yStart) or (tileYMin <=$yEnd and tileYMin >=$yStart))"
val realmQuery = getSelectTaskRealmTools(realm, RenderEntity::class.java, false) val realmQuery = getSelectTaskRealmTools(realm, RenderEntity::class.java, false)
.greaterThanOrEqualTo("tileX", xStart) .rawPredicate(sql)
.lessThanOrEqualTo("tileX", xEnd)
.greaterThanOrEqualTo("tileY", yStart)
.lessThanOrEqualTo("tileY", yEnd)
// 筛选不显示的数据 // 筛选不显示的数据
if (catchAll) { if (catchAll) {
// 查询realm中对应tile号的数据 // 查询realm中对应tile号的数据

View File

@ -154,20 +154,6 @@ class GlobalModule {
) )
} }
// /**
// * realm 注册
// */
// @Provides
// @Singleton
// fun provideRealmService(context: Application): RealmCoroutineScope {
// return RealmCoroutineScope(context)
// }
// @Singleton
// @Provides
// fun provideRealmDefaultInstance(): Realm {
// return Realm.getDefaultInstance()
// }
@Singleton @Singleton
@Provides @Provides

View File

@ -1,7 +1,5 @@
package com.navinfo.omqs.ui.activity.login package com.navinfo.omqs.ui.activity.login
import android.app.Activity
import android.app.ActivityManager
import android.content.Intent import android.content.Intent
import android.os.Bundle import android.os.Bundle
import android.util.DisplayMetrics import android.util.DisplayMetrics
@ -11,7 +9,6 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.databinding.DataBindingUtil import androidx.databinding.DataBindingUtil
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
import androidx.lifecycle.viewModelScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import com.navinfo.omqs.R import com.navinfo.omqs.R
import com.navinfo.omqs.databinding.ActivityLoginBinding import com.navinfo.omqs.databinding.ActivityLoginBinding
@ -19,8 +16,6 @@ import com.navinfo.omqs.ui.activity.CheckPermissionsActivity
import com.navinfo.omqs.ui.activity.map.MainActivity import com.navinfo.omqs.ui.activity.map.MainActivity
import com.umeng.commonsdk.UMConfigure import com.umeng.commonsdk.UMConfigure
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
/** /**
* 登陆页面 * 登陆页面

View File

@ -342,6 +342,8 @@ class MainViewModel @Inject constructor(
Constant.currentSelectTaskConfig = Constant.currentSelectTaskConfig =
RealmConfiguration.Builder().directory(Constant.currentSelectTaskFolder) RealmConfiguration.Builder().directory(Constant.currentSelectTaskFolder)
.name("OMQS.realm").encryptionKey(Constant.PASSWORD) .name("OMQS.realm").encryptionKey(Constant.PASSWORD)
// .assetFile("${Constant.currentSelectTaskFolder}/OMQS.realm")
// .readOnly()
// .allowQueriesOnUiThread(true) // .allowQueriesOnUiThread(true)
.schemaVersion(2).build() .schemaVersion(2).build()
MapParamUtils.setTaskConfig(Constant.currentSelectTaskConfig) MapParamUtils.setTaskConfig(Constant.currentSelectTaskConfig)
@ -353,8 +355,7 @@ class MainViewModel @Inject constructor(
if (naviEngineStatus == 1) { if (naviEngineStatus == 1) {
naviEngineNew.let { naviEngineNew.let {
// naviMutex.lock() // naviMutex.lock()
Log.e("jingo","${Thread.currentThread().name} ${Thread.currentThread().hashCode()}") if (testRealm == null)
if (testRealm == null)
testRealm = realmOperateHelper.getSelectTaskRealmInstance() testRealm = realmOperateHelper.getSelectTaskRealmInstance()
if (currentTaskBean != null) { if (currentTaskBean != null) {
naviEngineNew.bindingRoute( naviEngineNew.bindingRoute(

View File

@ -107,7 +107,8 @@ class TaskViewModel @Inject constructor(
if (currentSelectTaskBean == null) { if (currentSelectTaskBean == null) {
liveDataToastMessage.postValue("还没有开启任何任务") liveDataToastMessage.postValue("还没有开启任何任务")
} else { } else {
val links = realmOperateHelper.queryLink(realm, val links = realmOperateHelper.queryLink(
realm,
point = point, point = point,
) )
if (links.isNotEmpty()) { if (links.isNotEmpty()) {
@ -184,7 +185,7 @@ class TaskViewModel @Inject constructor(
if (task.syncStatus != FileManager.Companion.FileUploadStatus.DONE) { if (task.syncStatus != FileManager.Companion.FileUploadStatus.DONE) {
//赋值时间,用于查询过滤 //赋值时间,用于查询过滤
task.operationTime = DateTimeUtil.getNowDate().time task.operationTime = DateTimeUtil.getNowDate().time
}else{//已上传数据不做更新 } else {//已上传数据不做更新
continue continue
} }
} else { } else {
@ -194,7 +195,7 @@ class TaskViewModel @Inject constructor(
//赋值时间,用于查询过滤 //赋值时间,用于查询过滤
task.operationTime = DateTimeUtil.getNowDate().time task.operationTime = DateTimeUtil.getNowDate().time
} }
realm.copyToRealmOrUpdate(task) it.copyToRealmOrUpdate(task)
} }
} }
@ -273,10 +274,15 @@ class TaskViewModel @Inject constructor(
liveDataTaskLinks.value = taskBean.hadLinkDvoList liveDataTaskLinks.value = taskBean.hadLinkDvoList
showTaskLinks(taskBean) showTaskLinks(taskBean)
MapParamUtils.setTaskId(taskBean.id) MapParamUtils.setTaskId(taskBean.id)
Constant.currentSelectTaskFolder = File(Constant.USER_DATA_PATH + "/${taskBean.id}") // Constant.currentSelectTaskFolder = File(Constant.USER_DATA_PATH + "/${taskBean.id}")
Constant.currentSelectTaskFolder = File(Constant.USER_DATA_PATH + "/237")
Constant.currentSelectTaskConfig = Constant.currentSelectTaskConfig =
RealmConfiguration.Builder().directory(Constant.currentSelectTaskFolder) RealmConfiguration.Builder()
.name("OMQS.realm").encryptionKey(Constant.PASSWORD) .directory(Constant.currentSelectTaskFolder)
.name("OMQS.realm")
.encryptionKey(Constant.PASSWORD)
// .assetFile("${Constant.currentSelectTaskFolder}/OMQS.realm")
// .readOnly()
//.allowQueriesOnUiThread(true) //.allowQueriesOnUiThread(true)
.schemaVersion(2).build() .schemaVersion(2).build()
MapParamUtils.setTaskConfig(Constant.currentSelectTaskConfig) MapParamUtils.setTaskConfig(Constant.currentSelectTaskConfig)
@ -574,7 +580,7 @@ class TaskViewModel @Inject constructor(
} }
//根据Link数据查询对应数据上要素对要素进行显示重置 //根据Link数据查询对应数据上要素对要素进行显示重置
data.properties["linkPid"]?.let { data.properties["linkPid"]?.let {
realmOperateHelper.queryLinkToMutableRenderEntityList(realm,it) realmOperateHelper.queryLinkToMutableRenderEntityList(realm, it)
?.forEach { renderEntity -> ?.forEach { renderEntity ->
if (renderEntity.enable != 1) { if (renderEntity.enable != 1) {
renderEntity.enable = 1 renderEntity.enable = 1
@ -629,7 +635,10 @@ class TaskViewModel @Inject constructor(
//重置数据为隐藏 //重置数据为隐藏
if (hadLinkDvoBean.linkStatus == 2) { if (hadLinkDvoBean.linkStatus == 2) {
realmOperateHelper.queryLinkToMutableRenderEntityList(realm,hadLinkDvoBean.linkPid) realmOperateHelper.queryLinkToMutableRenderEntityList(
realm,
hadLinkDvoBean.linkPid
)
?.forEach { renderEntity -> ?.forEach { renderEntity ->
if (renderEntity.enable == 1) { if (renderEntity.enable == 1) {
renderEntity.enable = 0 renderEntity.enable = 0

View File

@ -21,16 +21,7 @@ import java.util.*
* */ * */
@Parcelize @Parcelize
open class LinkRelation() : RealmObject(), Parcelable { open class LinkRelation() : RealmObject(), Parcelable {
@PrimaryKey var linkPid:String = ""
var linkPid:String = UUID.randomUUID().toString()
@Index
var sNodeId: String? = null var sNodeId: String? = null
@Index
var eNodeId: String? = null var eNodeId: String? = null
var direct: Int = 0
constructor(direct: Int) : this() {
this.direct = direct
}
} }

View File

@ -14,21 +14,25 @@ import java.util.*
* 渲染要素对应的实体 * 渲染要素对应的实体
* */ * */
open class ReferenceEntity() : RealmObject() { open class ReferenceEntity() : RealmObject() {
@PrimaryKey // @PrimaryKey
var id: String = UUID.randomUUID().toString() // id // var id: Int = 0 // id
var renderEntityId: String = "" // 参考的renderEntity的Id // var renderEntityId: Int = 0 // 参考的renderEntity的Id
@Ignore
lateinit var name: String //要素名 lateinit var name: String //要素名
lateinit var table: String //要素表名 lateinit var table: String //要素表名
var code: String = "0" // 要素编码 var code: String = "0" // 要素编码
@Ignore
var zoomMin: Int = 18 //显示最小级别 var zoomMin: Int = 18 //显示最小级别
@Ignore
var zoomMax: Int = 23 //显示最大级别 var zoomMax: Int = 23 //显示最大级别
var taskId: Int = 0 //任务ID var taskId: Int = 0 //任务ID
var enable:Int = 0 // 默认0不是显示 1为渲染显示 var enable: Int = 0 // 默认0不是显示 1为渲染显示
var tileXMin:Int =0 var tileXMin: Int = 0
var tileXMax:Int = 0 var tileXMax: Int = 0
var tileYMin:Int =0 var tileYMin: Int = 0
var tileYMax:Int = 0 var tileYMax: Int = 0
var geometry: String = "" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下 var geometry: String =
"" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下
get() { get() {
wkt = GeometryTools.createGeometry(field) wkt = GeometryTools.createGeometry(field)
return field return field
@ -64,11 +68,16 @@ open class ReferenceEntity() : RealmObject() {
} }
return field return field
} }
@Ignore
var properties: RealmDictionary<String> = RealmDictionary() var properties: RealmDictionary<String> = RealmDictionary()
@Ignore
var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码 var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码
@Ignore
var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码 var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码
constructor(name: String): this() { constructor(name: String) : this() {
this.name = name this.name = name
} }
} }

View File

@ -1,9 +1,12 @@
package com.navinfo.collect.library.data.entity package com.navinfo.collect.library.data.entity
import android.os.Parcelable import android.os.Parcelable
import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.navinfo.collect.library.system.Constant import com.navinfo.collect.library.system.Constant
import com.navinfo.collect.library.utils.GeometryTools import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.GeometryToolsKt import com.navinfo.collect.library.utils.GeometryToolsKt
import com.navinfo.collect.library.utils.StrZipUtil
import io.realm.RealmDictionary import io.realm.RealmDictionary
import io.realm.RealmObject import io.realm.RealmObject
import io.realm.RealmSet import io.realm.RealmSet
@ -15,24 +18,35 @@ import org.locationtech.jts.geom.Coordinate
import org.locationtech.jts.geom.Geometry import org.locationtech.jts.geom.Geometry
import org.oscim.core.MercatorProjection import org.oscim.core.MercatorProjection
import java.util.* import java.util.*
import java.util.zip.GZIPInputStream
/** /**
* 渲染要素对应的实体 * 渲染要素对应的实体
* */ * */
@Parcelize @Parcelize
open class RenderEntity() : RealmObject(), Parcelable { open class RenderEntity() : RealmObject(), Parcelable {
@PrimaryKey // @PrimaryKey
var id: String = UUID.randomUUID().toString() // id // var id: String = UUID.randomUUID().toString() // id
lateinit var name: String //要素名 lateinit var name: String //要素名
lateinit var table: String //要素表名 lateinit var table: String //要素表名
var code: String = "0" // 要素编码 var code: String = "0" // 要素编码
var geometry: String = "" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下 // var geometryDb: String = ""
var geometry: String =
"" // 要素渲染参考的geometry该数据可能会在导入预处理环节被修改原始geometry会保存在properties的geometry字段下
get() { get() {
wkt = GeometryTools.createGeometry(field) wkt = GeometryTools.createGeometry(field)
return field return field
} }
// get() {
// if (geometryDb != null && geometryDb.isNotEmpty() && field.isEmpty()) {
// field = StrZipUtil.uncompress(geometryDb)
// }
// return field
// }
set(value) { set(value) {
field = value field = value
// geometryDb = StrZipUtil.compress(value)
// 根据geometry自动计算当前要素的x-tile和y-tile // 根据geometry自动计算当前要素的x-tile和y-tile
GeometryToolsKt.getTileXByGeometry(value, tileX) GeometryToolsKt.getTileXByGeometry(value, tileX)
@ -64,22 +78,40 @@ open class RenderEntity() : RealmObject(), Parcelable {
} }
return field return field
} }
@Ignore
var properties: RealmDictionary<String> = RealmDictionary() var properties: RealmDictionary<String> = RealmDictionary()
get() {
if (propertiesDb != null && propertiesDb.isNotEmpty() && field.isEmpty()) {
try {
val gson = Gson()
val type = object : TypeToken<List<RealmDictionary<String>>>() {}.type
field = gson.fromJson(StrZipUtil.uncompress(propertiesDb), type)
} catch (e: Exception) {
}
}
return field
}
var propertiesDb: String = ""
@Ignore @Ignore
var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码 var tileX: RealmSet<Int> = RealmSet() // x方向的tile编码
@Ignore @Ignore
var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码 var tileY: RealmSet<Int> = RealmSet() // y方向的tile编码
var tileXMin:Int =0 var tileXMin: Int = 0
var tileXMax:Int = 0 var tileXMax: Int = 0
var tileYMin:Int =0 var tileYMin: Int = 0
var tileYMax:Int = 0 var tileYMax: Int = 0
var taskId: Int = 0 //任务ID var taskId: Int = 0 //任务ID
var zoomMin: Int = 18 //显示最小级别 var zoomMin: Int = 18 //显示最小级别
var zoomMax: Int = 23 //显示最大级别 var zoomMax: Int = 23 //显示最大级别
var enable:Int = 0 // 默认0不是显示 1为渲染显示 2为常显 var enable: Int = 0 // 默认0不是显示 1为渲染显示 2为常显
var catchEnable:Int = 0 // 0不捕捉 1捕捉 var catchEnable: Int = 0 // 0不捕捉 1捕捉
@Index
lateinit var linkPid: String // RenderEntity关联的linkPid集合(可能会关联多个) var linkPid: String = "" // RenderEntity关联的linkPid集合(可能会关联多个)
var linkRelation: LinkRelation? = null var linkRelation: LinkRelation? = null
constructor(name: String) : this() { constructor(name: String) : this() {

View File

@ -0,0 +1,40 @@
package com.navinfo.collect.library.data.entity
import android.os.Parcelable
import com.navinfo.collect.library.utils.GeometryTools
import com.navinfo.collect.library.utils.GeometryToolsKt
import io.realm.RealmDictionary
import io.realm.RealmObject
import io.realm.RealmSet
import io.realm.annotations.Ignore
import io.realm.annotations.Index
import kotlinx.parcelize.Parcelize
import org.locationtech.jts.geom.Geometry
/**
* 渲染要素对应的实体
* */
@Parcelize
open class RenderEntity1() : RealmObject(), Parcelable {
lateinit var name: String //要素名
lateinit var table: String //要素表名
var code: String = "0" // 要素编码
var geometry: String = ""
var propertiesDb: String = ""
var tileXMin: Int = 0
var tileXMax: Int = 0
var tileYMin: Int = 0
var tileYMax: Int = 0
var taskId: Int = 0 //任务ID
var zoomMin: Int = 18 //显示最小级别
var zoomMax: Int = 23 //显示最大级别
var enable: Int = 0 // 默认0不是显示 1为渲染显示 2为常显
var catchEnable: Int = 0 // 0不捕捉 1捕捉
var linkPid: String = "" // RenderEntity关联的linkPid集合(可能会关联多个)
var linkRelation: LinkRelation? = null
constructor(name: String) : this() {
this.name = name
}
}

View File

@ -110,13 +110,12 @@ public class OMDBReferenceDataSource implements ITileDataSource {
@Override @Override
public void cancel() { public void cancel() {
if (Realm.getDefaultInstance().isInTransaction()) { // if (Realm.getDefaultInstance().isInTransaction()) {
Realm.getDefaultInstance().cancelTransaction(); // Realm.getDefaultInstance().cancelTransaction();
} // }
} }
public void update() { public void update() {
isUpdate = true; isUpdate = true;
Log.e("qj", Thread.currentThread().getName());
} }
} }

View File

@ -207,13 +207,12 @@ public class OMDBTileDataSource implements ITileDataSource {
@Override @Override
public void cancel() { public void cancel() {
if (Realm.getDefaultInstance().isInTransaction()) { // if (Realm.getDefaultInstance().isInTransaction()) {
Realm.getDefaultInstance().cancelTransaction(); // Realm.getDefaultInstance().cancelTransaction();
} // }
} }
public void update() { public void update() {
isUpdate = true; isUpdate = true;
Log.e("qj", Thread.currentThread().getName());
} }
} }

View File

@ -27,7 +27,7 @@ public class OMDBTileSource extends RealmDBTileSource {
@Override @Override
public OpenResult open() { public OpenResult open() {
Log.d("qj", Realm.getDefaultInstance().where(RenderEntity.class).findAll().size()+"open安装数量"); // Log.d("qj", Realm.getDefaultInstance().where(RenderEntity.class).findAll().size()+"open安装数量");
return OpenResult.SUCCESS; return OpenResult.SUCCESS;
} }

View File

@ -35,27 +35,28 @@ public class RealmDBTileDataSource implements ITileDataSource {
public void query(MapTile tile, ITileDataSink mapDataSink) { public void query(MapTile tile, ITileDataSink mapDataSink) {
// 获取tile对应的坐标范围 // 获取tile对应的坐标范围
if (tile.zoomLevel>=15&&tile.zoomLevel<=Constant.OVER_ZOOM) { if (tile.zoomLevel>=15&&tile.zoomLevel<=Constant.OVER_ZOOM) {
int m = Constant.OVER_ZOOM-tile.zoomLevel; // int m = Constant.OVER_ZOOM-tile.zoomLevel;
int xStart = (int)tile.tileX<<m; // int xStart = (int)tile.tileX<<m;
int xEnd = (int)((tile.tileX+1)<<m); // int xEnd = (int)((tile.tileX+1)<<m);
int yStart = (int)tile.tileY<<m; // int yStart = (int)tile.tileY<<m;
int yEnd = (int)((tile.tileY+1)<<m); // int yEnd = (int)((tile.tileY+1)<<m);
//
RealmQuery<GeometryFeatureEntity> realmQuery = Realm.getDefaultInstance().where(GeometryFeatureEntity.class) // RealmQuery<GeometryFeatureEntity> realmQuery = Realm.getDefaultInstance().where(GeometryFeatureEntity.class)
.rawPredicate("tileX>="+xStart+" and tileX<="+xEnd+" and tileY>="+yStart+" and tileY<="+yEnd); // .rawPredicate("tileX>="+xStart+" and tileX<="+xEnd+" and tileY>="+yStart+" and tileY<="+yEnd);
// 筛选不显示的数据 // // 筛选不显示的数据
if (Constant.HAD_LAYER_INVISIABLE_ARRAY!=null&&Constant.HAD_LAYER_INVISIABLE_ARRAY.length>0) { // if (Constant.HAD_LAYER_INVISIABLE_ARRAY!=null&&Constant.HAD_LAYER_INVISIABLE_ARRAY.length>0) {
realmQuery.beginGroup(); // realmQuery.beginGroup();
for (String type: Constant.HAD_LAYER_INVISIABLE_ARRAY) { // for (String type: Constant.HAD_LAYER_INVISIABLE_ARRAY) {
realmQuery.notEqualTo("name", type); // realmQuery.notEqualTo("name", type);
} // }
realmQuery.endGroup(); // realmQuery.endGroup();
} // }
List<GeometryFeatureEntity> listResult = realmQuery.distinct("id").findAll(); // List<GeometryFeatureEntity> listResult = realmQuery.distinct("id").findAll();
mThreadLocalDecoders.get().decode(tile, mapDataSink, listResult); // mThreadLocalDecoders.get().decode(tile, mapDataSink, listResult);
mapDataSink.completed(QueryResult.SUCCESS); // mapDataSink.completed(QueryResult.SUCCESS);
Realm.getDefaultInstance().close(); // Realm.getDefaultInstance().close();
// Log.d("RealmDBTileDataSource", "tile:"+tile.getBoundingBox().toString()); // Log.d("RealmDBTileDataSource", "tile:"+tile.getBoundingBox().toString());
mapDataSink.completed(QueryResult.SUCCESS);
} else { } else {
mapDataSink.completed(QueryResult.SUCCESS); mapDataSink.completed(QueryResult.SUCCESS);
} }
@ -68,8 +69,8 @@ public class RealmDBTileDataSource implements ITileDataSource {
@Override @Override
public void cancel() { public void cancel() {
if (Realm.getInstance(RealmUtils.getInstance().getRealmConfiguration()).isInTransaction()) { // if (Realm.getInstance(RealmUtils.getInstance().getRealmConfiguration()).isInTransaction()) {
Realm.getInstance(RealmUtils.getInstance().getRealmConfiguration()).cancelTransaction(); // Realm.getInstance(RealmUtils.getInstance().getRealmConfiguration()).cancelTransaction();
} // }
} }
} }

View File

@ -0,0 +1,282 @@
package com.navinfo.collect.library.utils
import sun.misc.BASE64Decoder
import sun.misc.BASE64Encoder
import java.io.ByteArrayInputStream
import java.io.ByteArrayOutputStream
import java.io.IOException
import java.util.*
import java.util.zip.*
object StrZipUtil {
/**
* @param input 需要压缩的字符串
* @return 压缩后的字符串
* @throws IOException IO
*/
fun compress(input: String): String {
if (input.isEmpty()) {
return input
}
try {
val out = ByteArrayOutputStream()
val gzipOs = GZIPOutputStream(out)
gzipOs.write(input.toByteArray())
gzipOs.close()
return BASE64Encoder().encode(out.toByteArray())
} catch (e: Exception) {
return input
}
}
/**
* @param zippedStr 压缩后的字符串
* @return 解压缩后的
* @throws IOException IO
*/
fun uncompress(zippedStr: String): String {
if (zippedStr.isEmpty()) {
return zippedStr
}
try {
val out = ByteArrayOutputStream()
val `in` = ByteArrayInputStream(
BASE64Decoder().decodeBuffer(zippedStr)
)
val gzipIs = GZIPInputStream(`in`)
val buffer = ByteArray(256)
var n: Int
while (gzipIs.read(buffer).also { n = it } >= 0) {
out.write(buffer, 0, n)
}
// toString()使用平台默认编码也可以显式的指定如toString("GBK")
return out.toString()
} catch (e: Exception) {
return zippedStr
}
}
/***
* 压缩GZip
*
* @param data
* @return
*/
fun gZip(data: ByteArray?): ByteArray? {
var b: ByteArray? = null
try {
val bos = ByteArrayOutputStream()
val gzip = GZIPOutputStream(bos)
gzip.write(data)
gzip.finish()
gzip.close()
b = bos.toByteArray()
bos.close()
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
return b
}
/***
* 解压GZip
*
* @param data
* @return
*/
fun unGZip(data: ByteArray?): ByteArray? {
var b: ByteArray? = null
try {
val bis = ByteArrayInputStream(data)
val gzip = GZIPInputStream(bis)
val buf = ByteArray(1024)
var num = -1
val baos = ByteArrayOutputStream()
while (gzip.read(buf, 0, buf.size).also { num = it } != -1) {
baos.write(buf, 0, num)
}
b = baos.toByteArray()
baos.flush()
baos.close()
gzip.close()
bis.close()
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
return b
}
/***
* 压缩Zip
*
* @param data
* @return
*/
fun zip(data: ByteArray): ByteArray? {
var b: ByteArray? = null
try {
val bos = ByteArrayOutputStream()
val zip = ZipOutputStream(bos)
val entry = ZipEntry("zip")
entry.size = data.size.toLong()
zip.putNextEntry(entry)
zip.write(data)
zip.closeEntry()
zip.close()
b = bos.toByteArray()
bos.close()
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
return b
}
/***
* 解压Zip
*
* @param data
* @return
*/
fun unZip(data: ByteArray?): ByteArray? {
var b: ByteArray? = null
try {
val bis = ByteArrayInputStream(data)
val zip = ZipInputStream(bis)
while (zip.nextEntry != null) {
val buf = ByteArray(1024)
var num = -1
val baos = ByteArrayOutputStream()
while (zip.read(buf, 0, buf.size).also { num = it } != -1) {
baos.write(buf, 0, num)
}
b = baos.toByteArray()
baos.flush()
baos.close()
}
zip.close()
bis.close()
} catch (ex: java.lang.Exception) {
ex.printStackTrace()
}
return b
}
// /***
// * 压缩BZip2
// *
// * @param data
// * @return
// */
// public static byte[] bZip2(byte[] data) {
// byte[] b = null;
// try {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// CBZip2OutputStream bzip2 = new CBZip2OutputStream(bos);
// bzip2.write(data);
// bzip2.flush();
// bzip2.close();
// b = bos.toByteArray();
// bos.close();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// return b;
// }
// /***
// * 解压BZip2
// *
// * @param data
// * @return
// */
// public static byte[] unBZip2(byte[] data) {
// byte[] b = null;
// try {
// ByteArrayInputStream bis = new ByteArrayInputStream(data);
// CBZip2InputStream bzip2 = new CBZip2InputStream(bis);
// byte[] buf = new byte[1024];
// int num = -1;
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// while ((num = bzip2.read(buf, 0, buf.length)) != -1) {
// baos.write(buf, 0, num);
// }
// b = baos.toByteArray();
// baos.flush();
// baos.close();
// bzip2.close();
// bis.close();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// return b;
// }
// /***
// * 压缩BZip2
// *
// * @param data
// * @return
// */
// public static byte[] bZip2(byte[] data) {
// byte[] b = null;
// try {
// ByteArrayOutputStream bos = new ByteArrayOutputStream();
// CBZip2OutputStream bzip2 = new CBZip2OutputStream(bos);
// bzip2.write(data);
// bzip2.flush();
// bzip2.close();
// b = bos.toByteArray();
// bos.close();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// return b;
// }
// /***
// * 解压BZip2
// *
// * @param data
// * @return
// */
// public static byte[] unBZip2(byte[] data) {
// byte[] b = null;
// try {
// ByteArrayInputStream bis = new ByteArrayInputStream(data);
// CBZip2InputStream bzip2 = new CBZip2InputStream(bis);
// byte[] buf = new byte[1024];
// int num = -1;
// ByteArrayOutputStream baos = new ByteArrayOutputStream();
// while ((num = bzip2.read(buf, 0, buf.length)) != -1) {
// baos.write(buf, 0, num);
// }
// b = baos.toByteArray();
// baos.flush();
// baos.close();
// bzip2.close();
// bis.close();
// } catch (Exception ex) {
// ex.printStackTrace();
// }
// return b;
// }
/**
* 把字节数组转换成16进制字符串
*
* @param bArray
* @return
*/
fun bytesToHexString(bArray: ByteArray): String? {
val sb = StringBuffer(bArray.size)
var sTemp: String
for (i in bArray.indices) {
sTemp = Integer.toHexString(0xFF and bArray[i].toInt())
if (sTemp.length < 2) sb.append(0)
sb.append(sTemp.uppercase(Locale.getDefault()))
}
return sb.toString()
}
}

2
vtm

@ -1 +1 @@
Subproject commit 6a6bb9ab5eaf6bb4c05b3110c612c32ef4c6ef3d Subproject commit c046e788f5c739612a31c308639fca2de639669a