我正在解析一個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次*你如何做到這一點? –
你可以顯示在領域和循環中執行查詢的代碼塊嗎? –