View Javadoc
1   package de.dlr.shepard.data.spatialdata.model;
2   
3   import de.dlr.shepard.data.spatialdata.repositories.SpatialDataPointRepository;
4   import jakarta.persistence.Column;
5   import jakarta.persistence.Entity;
6   import jakarta.persistence.GeneratedValue;
7   import jakarta.persistence.GenerationType;
8   import jakarta.persistence.Id;
9   import jakarta.persistence.Table;
10  import java.util.Map;
11  import lombok.EqualsAndHashCode;
12  import lombok.Getter;
13  import lombok.Setter;
14  import org.hibernate.annotations.JdbcTypeCode;
15  import org.hibernate.type.SqlTypes;
16  import org.locationtech.jts.geom.Geometry;
17  
18  @Getter
19  @Setter
20  @EqualsAndHashCode(exclude = "id")
21  @Entity
22  @Table(name = SpatialDataPointRepository.SPATIAL_TABLE_NAME)
23  public class SpatialDataPoint {
24  
25    @Id
26    @GeneratedValue(strategy = GenerationType.IDENTITY)
27    private Long id;
28  
29    @Column(name = SpatialDataPointRepository.SPATIAL_COLUMN_CONTAINER_ID)
30    private Long containerId;
31  
32    /** timestamp in nanoseconds */
33    private Long time;
34  
35    /**
36     * This field can hold any geometry that is part of the specification, like Point, Linear, Polygon, etc.
37     * Atm it is only used to store 3D points.
38     *
39     * Hint: Be careful when using functions on the Geometry object because most of them do only work with 2D geometries.
40     * For example, the Geometry.toText() method returns 'POINT (x y)' event if the underlying coordinate has a z value.
41     */
42    private Geometry position;
43  
44    /**
45     * This field stores metadata that is in a JSON format.
46     * The metadata is used to store additional information about the geometry that
47     * can also be used for filtering.
48     */
49    @Column(columnDefinition = "jsonb")
50    @JdbcTypeCode(SqlTypes.JSON)
51    private Map<String, Object> metadata;
52  
53    /**
54     * Measurements hold the actual data of that position at this point in time.
55     * These values are also stored in a JSON format.
56     * It can be used to store just a single value or an array of values.
57     * In the future further data types can be added.
58     */
59    @Column(columnDefinition = "jsonb")
60    @JdbcTypeCode(SqlTypes.JSON)
61    private Map<String, Object> measurements;
62  
63    public SpatialDataPoint() {}
64  
65    public SpatialDataPoint(
66      Long id,
67      Long containerId,
68      Long time,
69      Geometry position,
70      Map<String, Object> metadata,
71      Map<String, Object> measurements
72    ) {
73      this.id = id;
74      this.containerId = containerId;
75      this.time = time;
76      this.position = position;
77      this.metadata = metadata;
78      this.measurements = measurements;
79    }
80  
81    public SpatialDataPoint(
82      Long containerId,
83      Long time,
84      Geometry position,
85      Map<String, Object> metadata,
86      Map<String, Object> measurements
87    ) {
88      this(null, containerId, time, position, metadata, measurements);
89    }
90  }