レルムに多くの多角形を含むJsonファイルを解析しています。レルム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が
- RealmPolygonCoordinateを22260の項目が含まれてい
- 私はRealmPolygonがである場合を把握しようとしている352241のアイテム
が含まれていますが含まれています私が現在地の近くを見ている方向。 compassDataはRotationVectorSensor(0〜360度の間の値)から得られるとMAX_DISTANCEは1.5キロである
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;
}
}
}
:私はこのようなベアリングで31 locationsamplesを取っています。
31のlocationSampleポイントの1つがポリゴンの近くにあるかどうかを知りたい場合は、現在Realmデータベースに31回あるすべてのpolygonCoordinatesをループする必要があります。つまり: 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回あるすべてのpolygonCoordinatesをループする必要があります。 –
クエリーを実行するコードブロックをレルムとループで表示できますか? –