Sample code

Updated at: 2024-10-18 08:21

This topic describes the spatiotemporal trajectory feature.

1. Download the sample code

lindorm-ganosbase-mod-sample

Download and decompress the package, and then go to the lindorm-sample directory.

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

After the code is compiled, the package lindorm-mod-sample-1.0.0.jar is generated in the specified directory.

2. Use the sample code

Go to the lindorm-sample directory.

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

Use a JSON file to configure parameters and operations to perform. For more information, see the sample file mod_template.json.

2.1 Write data

In the mod_template.json file, configure parameters for data write operations. In the following sample code, you can specify the directory where the dataset of AIS trajectory points resides, query trajectory data and store trajectory objects that are split based on secondary indexes, use the IDs of the trajectory objects as the primary index and XZ2T as the secondary index, create a table named traj, and write data to the table. For trajectory splitting, the policies BY_DURATION, BY_DISTANCE, BY_ANGLE, and BY_COUNT are available. The trajectory data is split after each set of 50 trajectory points. To configure a policy, use the SplitConfigs parameter in MOD.java.

{
  "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",
}

Set enabled_indices to the type of the index that you want to create. For more information about index types, see Create index tables. To use secondary indexes, set enable_secondary_index to true and primary_index to the primary index that you want to use. The thread_num parameter specifies the concurrent threads that you want to use for data write operations. By default, the thread_num value is 1.

After you perform the preceding steps, run the following sample command to write data:

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

2.2 Query data

In the mod_template.json file, configure parameters for data queries. You can retain the default settings for the query range.

{
  "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"
}

The predicate parameter specifies the query statement. The return_complete_trajectory parameter specifies whether to return the complete trajectory data. If you query trajectory data that is stored in split mode, the trajectory points that match the query conditions are returned by default. To return the complete trajectory data, set return_complete_trajectory to true.

Run the following sample command to query data:

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

View the query result.

    Feedback
    phone Contact Us

    Chat now with Alibaba Cloud Customer Service to assist you in finding the right products and services to meet your needs.

    alicare alicarealicarealicare