Skip to content

Commit cddc135

Browse files
committed
fixed lat/lon and added weighted binning
1 parent 3f7ee3e commit cddc135

1 file changed

Lines changed: 12 additions & 9 deletions

File tree

examples/java-api/src/main/java/org/locationtech/geowave/examples/stats/TrackSpatialBinningStatisticExample.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.geotools.feature.simple.SimpleFeatureBuilder;
2020
import org.geotools.feature.simple.SimpleFeatureTypeBuilder;
2121
import org.locationtech.geowave.adapter.vector.FeatureDataAdapter;
22+
import org.locationtech.geowave.core.geotime.binning.ComplexGeometryBinningOption;
2223
import org.locationtech.geowave.core.geotime.binning.SpatialBinningType;
2324
import org.locationtech.geowave.core.geotime.index.SpatialDimensionalityTypeProvider;
2425
import org.locationtech.geowave.core.geotime.index.SpatialOptions;
@@ -138,6 +139,10 @@ public static void main(final String[] args) {
138139
new SpatialFieldValueBinningStrategy(featureType.getGeometryDescriptor().getLocalName());
139140
spatialBinning.setType(SpatialBinningType.S2);
140141
spatialBinning.setPrecision(18); // ~10 meter resolution
142+
// Use weighted binning: scale contributions based on geometry overlap percentage
143+
// This prevents double-counting when tracks intersect multiple spatial bins
144+
spatialBinning.setComplexGeometry(
145+
ComplexGeometryBinningOption.USE_FULL_GEOMETRY_SCALE_BY_OVERLAP);
141146

142147
// Track count statistic
143148
final CountStatistic trackCount = new CountStatistic(featureType.getTypeName());
@@ -173,12 +178,12 @@ public static void main(final String[] args) {
173178
// Sum statistics for acceleration and speed
174179
final NumericStatsStatistic accelerationSum =
175180
new NumericStatsStatistic(featureType.getTypeName(), "acceleration");
176-
accelerationSum.setTag("Acceleration-Sum");
181+
accelerationSum.setTag("Acceleration-Stats");
177182
accelerationSum.setBinningStrategy(spatialBinning);
178183

179184
final NumericStatsStatistic speedSum =
180185
new NumericStatsStatistic(featureType.getTypeName(), "speed");
181-
speedSum.setTag("Speed-Sum");
186+
speedSum.setTag("Speed-Stats");
182187
speedSum.setBinningStrategy(spatialBinning);
183188

184189

@@ -347,8 +352,8 @@ private static List<TrackPoint> createTrackSequence(
347352

348353
for (int i = 0; i < points.length; i++) {
349354
double[] point = points[i];
350-
double lat = point[0];
351-
double lon = point[1];
355+
double lon = point[0];
356+
double lat = point[1];
352357
double speed = point[2];
353358
double acceleration = point[3];
354359
double heading = point[4];
@@ -427,7 +432,9 @@ private static void displayTrackStatistics(
427432

428433
System.out.println("***** Track Spatial Binning Statistics *****");
429434
System.out.println("Using S2 Level 18 (~10 meter resolution) spatial binning");
430-
System.out.println("Each track contributes one statistic value per spatial bin it intersects");
435+
System.out.println(
436+
"Using weighted binning: track contributions are scaled by geometry overlap percentage");
437+
System.out.println("This prevents double-counting when tracks intersect multiple spatial bins");
431438

432439
System.out.println("\n** Track Count by Spatial Bin **");
433440
try (CloseableIterator<Pair<ByteArray, Long>> it =
@@ -550,7 +557,6 @@ private static void displayTrackStatistics(
550557

551558
// Demonstrate querying within specific bounding boxes
552559
System.out.println("\n***** Bounding Box Queries *****");
553-
554560
// Query 1: Dense urban area where multiple tracks overlap
555561
final Envelope urbanArea = new Envelope(-77.040, -77.030, 38.885, 38.905);
556562
System.out.println(String.format("\n** Urban Area Query: %s **", urbanArea));
@@ -570,9 +576,6 @@ private static void displayTrackStatistics(
570576
final Long whiteHouseTracks =
571577
dataStore.getStatisticValue(trackCount, BinConstraints.ofObject(whiteHouseArea));
572578
System.out.println(String.format("Track count near White House: %d", whiteHouseTracks));
573-
574-
System.out.println("\nNote: Spatially binned statistics automatically aggregate results");
575-
System.out.println("from all spatial bins that intersect with the specified bounding box.");
576579
}
577580

578581
/**

0 commit comments

Comments
 (0)