Skip to content

Commit 54ca549

Browse files
committed
add: AIS_Transform_Full: transforming WKT coords into WKB & update readme guide for those new program examples
1 parent 51fae2b commit 54ca549

2 files changed

Lines changed: 551 additions & 23 deletions

File tree

src/main/java/examples/EXAMPLES_GUIDE.md

Lines changed: 238 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ mvn test -Dtest=TestFile#testName
4949
## Programs Overview
5050

5151

52-
#### 1. `Hello_World` - Introduction to Temporal Types
52+
#### 1. `N01_Hello_World` - Introduction to Temporal Types
5353
**Concepts**: Temporal instant, sequence, sequence set, interpolation
5454

5555
Creates and displays temporal geometric points with different
@@ -73,7 +73,7 @@ mvn exec:java -Dexec.mainClass="examples.N01_Hello_World"
7373

7474
---
7575

76-
#### 2. `Hello_World_Geodetic` - Geographic Coordinates
76+
#### 2. `N01_Hello_World_Geodetic` - Geographic Coordinates
7777
**Concepts**: Geographic vs geometric coordinates, EPSG:4326
7878

7979
Same as Hello_World but uses **geodetic coordinates** (latitude
@@ -91,7 +91,7 @@ mvn exec:java -Dexec.mainClass="examples.N01_Hello_World_Geodetic"
9191
---
9292

9393

94-
#### 3. `AIS_Read` - Parse CSV Data
94+
#### 3. `N02_AIS_Read` - Parse CSV Data
9595
**Concepts**: Reading CSV, creating temporal instants, coordinate systems
9696

9797
Reads AIS (Automatic Identification System) ship tracking data from CSV
@@ -121,7 +121,7 @@ MMSI: 228041600, Location: SRID=4326;Point(-3.56 39.85
121121

122122
---
123123

124-
#### 4. `AIS_Assemble` - Build Trajectories
124+
#### 4. `N03_AIS_Assemble` - Build Trajectories
125125
**Concepts**: Aggregating instants, constructing sequences, distance
126126
calculation
127127

@@ -154,7 +154,7 @@ MMSI: 228041600, Number of input instants: 10523
154154

155155
---
156156

157-
#### 5. `BerlinMOD_Assemble` - Vehicle Trip Assembly
157+
#### 5. `N03_BerlinMOD_Assemble` - Vehicle Trip Assembly
158158
**Concepts**: Synthetic trajectory data, HexWKB encoding
159159

160160
Similar to AIS_Assemble but for synthetic vehicle data in Brussels.
@@ -179,7 +179,7 @@ mvn exec:java -Dexec.mainClass="examples.N03_BerlinMOD_Assemble"
179179
---
180180

181181

182-
#### 6. `AIS_Store` - Write to MobilityDB
182+
#### 6. `N04_AIS_Store` - Write to MobilityDB
183183
**Concepts**: Database connectivity, SQL insertion, MobilityDB types
184184

185185
Reads AIS data and stores it directly in PostgreSQL/MobilityDB.
@@ -215,8 +215,8 @@ you are using Linux
215215

216216
---
217217

218-
#### 7. `AIS_Stream_DB` - Streaming to Database
219-
**Concepts**: Memory-efficient streaming, incremental updates
218+
#### 7. `N04_AIS_Stream_DB` - Streaming to Database
219+
**Concepts**: Expandable sequences, memory-efficient streaming, incremental updates
220220

221221
Processes large AIS datasets by streaming to database instead of holding
222222
everything in memory.
@@ -225,21 +225,36 @@ everything in memory.
225225
mvn exec:java -Dexec.mainClass="examples.N04_AIS_Stream_DB"
226226
```
227227

228-
**Strategy**:
229-
1. Accumulate 1000 instants per ship in memory
230-
2. Build sequence and INSERT/UPDATE in database
231-
3. Keep last 2 instants for continuity
232-
4. Clear memory and continue
228+
**Architecture**: Expandable Sequences (FAITHFUL to C)
229+
```
230+
Record → Append to expandable sequence → When full (1000 instants)
231+
→ Send to database → Restart with last 2 instants → Continue
232+
```
233233

234-
**Key Function**:
234+
235+
**Process**:
236+
1. Create expandable sequence with first instant
237+
2. Append subsequent instants using `temporal_append_tinstant()`
238+
3. When count reaches 1000: INSERT/UPDATE to database
239+
4. Restart sequence keeping last 2 instants for continuity
240+
5. Continue until end of file
241+
242+
**Key Functions**:
243+
- `temporal_append_tinstant()` - Append instant to expandable sequence
244+
- `restartSequence()` - Simulate MEOS C's internal function `tsequence_restart()`
245+
- `getSequenceCount()` - Get instant count (simulates `seq->count`)
235246
- `update()` - MobilityDB function to merge temporal values
236247

237-
**Advantage**: Can process datasets larger than available RAM
248+
249+
**Continuity Between Batches**:
250+
- Keeps last 2 instants when restarting
251+
- Creates seamless trajectory when merged in database
252+
- MobilityDB `update()` function connects sequences
238253

239254
---
240255

241-
#### 8. `AIS_Stream_File` - Streaming to File
242-
**Concepts**: File streaming, memory management
256+
#### 8. `N04_AIS_Stream_File` - Streaming to File
257+
**Concepts**: Expandable sequences, file streaming, memory management
243258

244259
Same concept as AIS_Stream_DB but writes to CSV file instead.
245260

@@ -249,12 +264,27 @@ mvn exec:java -Dexec.mainClass="examples.N04_AIS_Stream_File"
249264

250265
**Output**: `ais_trips_new_stream.csv`
251266

252-
**Use case**: When database is unavailable or file export is needed
267+
**Architecture**: Same as AIS_Stream_DB
268+
```
269+
Record → Append to expandable sequence → When full (1000 instants)
270+
→ Write to file → Restart with last 2 instants → Continue
271+
```
272+
273+
**Key Functions**:
274+
- `temporal_append_tinstant()` - Build sequence incrementally
275+
- `restartSequence()` - Keep last 2 instants for continuity
276+
- `tspatial_out()` - Convert sequence to WKT string
277+
278+
**Output Format**:
279+
```csv
280+
228041600, SRID=4326;LINESTRING(...) @ [2009-06-01 00:01:11+00, ...)
281+
230907000, SRID=4326;LINESTRING(...) @ [2009-06-01 00:02:45+00, ...)
282+
```
253283

254284
---
255285

256286

257-
#### 9. `BerlinMOD_Disassemble` - Extract Observations
287+
#### 9. `N05_BerlinMOD_Disassemble` - Extract Observations
258288
**Concepts**: Temporal decomposition, sorting, coordinate reference
259289
systems
260290

@@ -286,7 +316,7 @@ mvn exec:java -Dexec.mainClass="examples.N05_BerlinMOD_Disassemble"
286316

287317
---
288318

289-
#### 10. `BerlinMOD_Clip` - Spatial Analysis
319+
#### 10. `N06_BerlinMOD_Clip` - Spatial Analysis
290320
**Concepts**: Spatial clipping, geometric operations, administrative
291321
boundaries
292322

@@ -327,7 +357,7 @@ Veh | Distance | 1 2 3 ... | Inside | Outside
327357

328358
---
329359

330-
#### 11. `BerlinMOD_Tile` - Grid-Based Aggregation
360+
#### 11. `N07_BerlinMOD_Tile` - Grid-Based Aggregation
331361
**Concepts**: Spatial tiling, temporal binning, 2D grids
332362

333363
Divides space and time into regular grids (tiles) and aggregates trips.
@@ -374,7 +404,7 @@ Speed
374404

375405
---
376406

377-
#### 12. `BerlinMOD_Simplify` - Trajectory Simplification
407+
#### 12. `N08_BerlinMOD_Simplify` - Trajectory Simplification
378408
**Concepts**: Douglas-Peucker, data compression, tolerance
379409

380410
Reduces trajectory complexity while preserving shape.
@@ -413,7 +443,7 @@ Vehicle: 1, Date: 2020-06-01, Seq: 1
413443

414444
---
415445

416-
#### 13. `BerlinMOD_Aggregate` - Temporal Count
446+
#### 13. `N09_BerlinMOD_Aggregate` - Temporal Count
417447
**Concepts**: Temporal aggregation, overlap analysis, time-based
418448
statistics
419449

@@ -459,6 +489,132 @@ STBOX X((473212,6578740),(499152,6607165)), T([2020-06-01, 2020-06-11])
459489

460490
---
461491

492+
493+
#### 14. `N10_AIS_Assemble_Full` - Batch Processing
494+
**Concepts**: Large-scale trajectory assembly, data validation
495+
496+
```bash
497+
mvn exec:java -Dexec.mainClass="examples.N10_AIS_Assemble_Full"
498+
```
499+
500+
**Process**:
501+
1. Read CSV line by line (European date format DD/MM/YYYY)
502+
2. Validate coordinates (Denmark: 40-84°N, -16 to 33°E)
503+
3. Filter duplicates (same timestamp = skip)
504+
4. Accumulate instants in ArrayList per ship
505+
5. Build complete sequences at end
506+
6. Calculate distance & time-weighted average SOG
507+
508+
**Data Validation**:
509+
```java
510+
LAT: 40.18° to 84.17°
511+
LON: -16.1° to 32.88°
512+
SOG: 0.0 to 1022.0 (0-102.2 knots)
513+
Duplicate timestamps: Filtered
514+
```
515+
516+
**Output Example**:
517+
```
518+
| MMSI | #Rec | #TrInst | #SInst | Distance | Speed |
519+
| 219000001 | 1243 | 1187 | 1198 | 134567.234567 | 8.234567 |
520+
```
521+
522+
**Key Functions**:
523+
- `geogpoint_make2d()` - Create geographic points
524+
- `tsequence_make()` - Build sequences
525+
- `tpoint_length()` - Calculate distance
526+
- `tnumber_twavg()` - Time-weighted average
527+
528+
**Use cases**:
529+
- Historical trajectory analysis
530+
- Fleet statistics & reporting
531+
- Traffic pattern analysis
532+
533+
---
534+
535+
#### 15. `N11_AIS_Expand_Full` - Incremental Building
536+
**Concepts**: Expandable sequences, memory optimization
537+
538+
```bash
539+
mvn exec:java -Dexec.mainClass="examples.N11_AIS_Expand_Full"
540+
```
541+
542+
**Architecture**: INCREMENTAL BUILDING
543+
```
544+
Record → Create/Append to sequence → Sequence ALWAYS ready
545+
If the sequence needs more space → MEOS auto-expands it with memory optimization
546+
```
547+
548+
**Key Difference from N10**:
549+
```
550+
N10: [Inst1] [Inst2] ... [InstN] → tsequence_make() at END
551+
N11: [I1]→[I1-I2]→[I1-I2-I3] → temporal_append_tinstant() CONTINUOUSLY
552+
```
553+
554+
**Process**:
555+
1. Read CSV (same validation as N10)
556+
2. For FIRST instant: Create initial sequence
557+
3. For subsequent: Append with `temporal_append_tinstant()`
558+
4. MEOS auto-expands capacity (doubles: 64→128→256...)
559+
5. Sequence always available for queries
560+
561+
**Core Function**:
562+
```java
563+
Pointer newSeq = temporal_append_tinstant(
564+
sequence, instant, 0.0, null, true);
565+
```
566+
567+
568+
**Use cases**:
569+
- Real-time GPS tracking
570+
- Streaming data ingestion
571+
- Memory-constrained environments
572+
- 24/7 continuous monitoring
573+
574+
---
575+
576+
#### 16. `N12_AIS_Transform_Full` - Coordinates Transformation
577+
**Concepts**: Coordinate system transformation
578+
579+
Transform AIS coordinates from **geographic** (lat/lon) to **projected** (meters).
580+
581+
```bash
582+
mvn exec:java -Dexec.mainClass="examples.N12_AIS_Transform_Full"
583+
```
584+
585+
**Transformation**:
586+
- FROM: EPSG:4326 (WGS84 - latitude/longitude in degrees)
587+
- TO: EPSG:25832 (ETRS89 / UTM Zone 32N - meters for Denmark)
588+
589+
**Why Transform?**
590+
591+
Geographic (EPSG:4326):
592+
```
593+
Copenhagen: 55.6761°N, 12.5683°E
594+
Distance: Complex geodesic formulas
595+
```
596+
597+
Projected (EPSG:25832):
598+
```
599+
Copenhagen: X=691,875m, Y=6,176,943m
600+
Distance: √((Δx)² + (Δy)²) ← Simple!
601+
```
602+
603+
**Key Functions**:
604+
```java
605+
Pointer geog = geogpoint_make2d(4326, lon, lat);
606+
Pointer utm = geo_transform(geog, 25832);
607+
String ewkt = geo_as_ewkt(utm, 6);
608+
```
609+
610+
**Use cases**:
611+
- Accurate distance calculations (meters!)
612+
- Grid-based spatial analysis
613+
- GIS system integration
614+
- ETL pipelines
615+
616+
---
617+
462618
## Data Files
463619

464620
All data files are in `src/main/java/examples/data/`:
@@ -468,6 +624,12 @@ All data files are in `src/main/java/examples/data/`:
468624
- Format: `T,MMSI,Latitude,Longitude,SOG`
469625
- Coordinate system: EPSG:4326 (WGS84 lat/lon)
470626

627+
### Full-Scale AIS Dataset (Danish Maritime Authority)
628+
- Download from: http://aisdata.ais.dk/
629+
- Format: `Timestamp,Type,MMSI,Latitude,Longitude,NavStatus,ROT,SOG,...`
630+
- Date format: **DD/MM/YYYY HH:MM:SS** (European)
631+
- Coordinate system: EPSG:4326 (WGS84 lat/lon)
632+
471633
### BerlinMOD Dataset (Vehicle Tracking)
472634
- `berlinmod_instants.csv` - 89K observations (5 vehicles, 11 days)
473635
- `berlinmod_trips.csv` - 154 trips in HexWKB format
@@ -501,6 +663,44 @@ Pointer seq = tsequence_make(instantsArray, count,
501663
lowerInc, upperInc, interpolation, normalize);
502664
```
503665

666+
### Expandable Sequences (Streaming)
667+
```java
668+
// Create initial sequence with first instant
669+
Pointer seq = tsequence_make(instArray, 1,
670+
true, true, TInterpolation.LINEAR.getValue(), true);
671+
672+
// Append subsequent instants (auto-expands!)
673+
Pointer newSeq = temporal_append_tinstant(
674+
seq, // Current sequence
675+
instant, // New instant to add
676+
0.0, // maxdist (0 = no spatial gap limit)
677+
null, // maxt (null = no time gap limit)
678+
true // expand (auto-expand capacity)
679+
);
680+
681+
// Update pointer
682+
seq = newSeq;
683+
684+
// Get instant count
685+
int count = temporal_num_instants(seq);
686+
687+
// Extract instant by index (1-indexed!)
688+
Pointer inst = temporal_instant_n(seq, index);
689+
```
690+
691+
**When to use**:
692+
- Streaming scenarios (N04_AIS_Stream_DB, N04_AIS_Stream_File)
693+
- Unknown final size
694+
- Memory-efficient incremental building needed
695+
696+
**Comparison**:
697+
698+
| Approach | When to Use |
699+
|----------|-------------|
700+
| `tsequence_make()` | All instants available upfront |
701+
| `temporal_append_tinstant()` | Streaming/incremental build |
702+
703+
504704
### Parsing
505705
```java
506706
// Timestamp
@@ -541,6 +741,21 @@ Pointer outside = tpoint_minus_geom(trip, geometry, zspan);
541741
double dist = tpoint_distance(trip1, trip2);
542742
```
543743

744+
### Coordinate Transformation
745+
```java
746+
// Transform to different CRS
747+
Pointer geog = geogpoint_make2d(4326, lon, lat);
748+
Pointer transformed = point_transform(geog, 25832);
749+
750+
// Get coordinates as EWKT (Extended Well-Known Text)
751+
String ewkt = geo_as_ewkt(transformed, 6); // 6 decimal places
752+
// → "SRID=25832;POINT(691875.234567 6176943.876543)"
753+
754+
// Get coordinates as WKB (Well-Known Binary - hex)
755+
String wkb = geo_out(transformed);
756+
// → "0101000020E8640000..." (binary format)
757+
```
758+
544759
## Troubleshooting
545760

546761
### ClassNotFoundException

0 commit comments

Comments
 (0)