我正在解析一个Json文件,其中包含很多多面体到Realm。我已经设定,方式如下:Realm Android和具有多面计算的大型数据集
RealmMultiPolygon类:
public int dangerLevel;
public int timeOfDay;
public RealmList<RealmPolygon> realmPolygons
RealmPolygon类:
public RealmList<RealmPolygonCoordinate> coordinates;
RealmPolygonCoordinate
public double latitude;
public double longitude;
至于项目的担忧:
- RealmMultiPolygon包含8项
- RealmPolygon包含22260项
- RealmPolygonCoordinate包含352241项
我试图找出是否RealmPolygon是一个方向,我正在看和在我目前的位置附近。我正在31个locationsamples与轴承这样的:
private void calculateUserDirectionLocations() {
Log.d(Constants.DEBUG, "update the locationbar");
if(compassData < 0) {
return;
}
int step = 50;
int bearingstep = 1;
double bearing = Math.round(compassData/bearingstep) * bearingstep;
if(userLocation != null) {
if(Math.abs(bearing - oldBearing) > 1) {
locationSamples.clear();
Log.d(Constants.DEBUG, "START location samples");
for(int i = 0; i <= Constants.MAX_DISTANCE; i+=step) {
if (i % step == 0) {
locationSamples.add(locationWithBearing((double) i));
}
}
Log.d(Constants.DEBUG, "END location samples");
updateColors();
oldBearing = bearing;
}
}
}
凡compassData从RotationVectorSensor获得(值0和360度之间)和MAX_DISTANCE是1.5公里。
现在,如果我想知道31个locationSample点之一是否靠近一个多边形,我必须遍历我目前在我的Realm数据库中31次所有的多边形坐标。这意味着: 31 * 352241 = 10919471
这是令人难以置信的缓慢,但我真的不能找到一个更好的解决方案。任何人都有一个想法如何更好/更快地做到这一点?
更新1 目前,我正在通过这样的坐标循环:
for(RealmMultiPolygon rmp : area.avalanche.multiPolygon) {
if(rmp.timeOfDay == 2) {
for (RealmPolygon polygon : rmp.realmPolygons) {
for(LatLng sample : locationSamples) {
tempPoint = new LatLng(polygon.coordinates.first().latitude, polygon.coordinates.first().longitude);
if(SphericalUtil.computeDistanceBetween(tempPoint, sample) <= 500) {
coords.add(tempPoint);
} else {
break;
}
}
}
}
}
你可以使它平行 –
*我必须遍历我目前在我的Realm数据库中所有的多边形坐标31次*你如何做到这一点? –
你可以显示在领域和循环中执行查询的代码块吗? –