Code examples

Updated at:

This topic shows you how to download, compile, and run the Lindorm spatiotemporal trajectory sample code. The sample writes and queries Automatic Identification System (AIS) vessel trajectory data using the Moving Object Database (MOD) API.

Download and compile the sample code

  1. Download the sample package: lindorm-mod-sample

  2. Decompress the package, then navigate to the lindorm-sample directory.

  3. Compile the source code:

    • -Dmaven.test.skip=true: skips unit tests to speed up the build

    • -s ../settings.xml: uses the bundled Maven settings file, which points to the required dependencies

    mvn install -Dmaven.test.skip=true -s ../settings.xml

    After the build completes, the compiled JAR lindorm-mod-sample-1.0.0.jar appears in the target/ directory.

How it works

All write and query operations use the same run command. The behavior is controlled entirely by mod_template.json:

java -jar target/lindorm-mod-sample-1.0.0.jar src/main/resources/template/mod_template.json

Edit mod_template.json to switch between write and query modes, or to adjust parameters. The sample file at src/main/resources/template/mod_template.json serves as a starting point.

Write trajectory data

Configure mod_template.json for a write operation:

{
  "operation" : "WRITE",
  "zk_address" : "your_zk_address",
  "catalog" : "example",
  "schema" : "traj",
  "enable_secondary_index" : "true",
  "print_info": "false",
  "enabled_indices" : "id,xz2t",
  "primary_index" : "id",
  "thread_num": 8,
  "input_dir": "path_to_repository/lindorm-sample/src/main/resources/data/traj"
}

Parameters

Parameter Description Example
operation Operation type: WRITE or QUERY WRITE
zk_address ZooKeeper address for your Lindorm instance 192.168.0.1:2181
catalog Catalog (database namespace) to write data into example
schema Table name for storing trajectory data traj
enable_secondary_index Set to true to enable secondary indexes true
enabled_indices Comma-separated list of index types to create. See Create index tables for available types id,xz2t
primary_index Index to use as the primary index id
print_info Set to true to print detailed write progress. Useful for debugging false
thread_num Number of concurrent threads for writing. Default: 1 8
input_dir Path to the directory containing AIS trajectory point data files path_to_repository/lindorm-sample/src/main/resources/data/traj

Trajectory splitting

The sample splits trajectory objects into segments before indexing. Four split policies are available:

Policy Splits when...
BY_COUNT The segment reaches the specified number of trajectory points (default: 50 points per segment)
BY_DURATION The segment reaches the specified time duration
BY_DISTANCE The segment reaches the specified distance
BY_ANGLE The heading angle change exceeds the specified threshold

To change the active policy or threshold, edit SplitConfigs in MOD.java.

Run the write operation:

java -jar target/lindorm-mod-sample-1.0.0.jar src/main/resources/template/mod_template.json

Query trajectory data

Configure mod_template.json for a query operation:

{
  "operation" : "QUERY",
  "zk_address" : "your_zk_address",
  "catalog" : "example",
  "schema" : "traj",
  "predicate" : "INTERSECTS(geom, POLYGON ((-76 28, -74 28, -74 30, -76 30, -76 28))) and traj_start_time >= 1549510271 AND traj_start_time <= 1549583941",
  "return_complete_trajectory" : "false",
  "print_results" : "true"
}

Parameters

Parameter Description Example
operation Operation type QUERY
zk_address ZooKeeper address for your Lindorm instance 192.168.0.1:2181
catalog Catalog to query example
schema Table name to query traj
predicate Query filter combining a spatial predicate and a time range. The spatial predicate uses INTERSECTS(geom, <WKT geometry>). The time range uses Unix timestamps See example above
return_complete_trajectory When false (default), returns only the trajectory segments that match the query conditions. Set to true to return the complete trajectory data false
print_results Set to true to print query results to stdout true

Run the query:

java -jar target/lindorm-mod-sample-1.0.0.jar src/main/resources/template/mod_template.json

The output lists the trajectory objects that intersect the specified geographic area and time range. Each returned object corresponds to a trajectory segment — or the full trajectory if return_complete_trajectory is true — that matches the predicate.

What's next

  • Create index tables — learn about the available index types, including XZ2T, and when to use each