hibernatehibernate-spatial

Construct LineString using org.geolatte.geom


How do I convert the following MySQL expression to a corresponding org.geolatte.geom.LineString, using the org.hibernate:hibernate-spatial library.

LineString(Point(-1, start_timestamp), Point(1, end_timestamp));

The DSL.linestring requires a org.geolatte.geom.crs.CoordinateReferenceSystem, but I'm unsure which one I should use for this particular case.

What I have tried with so far

C2D position1 = new C2D(-1, 1546301554.000000);
C2D position2 = new C2D(1, 1546301559.000000);

GeographicCoordinateReferenceSystem gcrs = CoordinateReferenceSystems.mkGeographic(UNKNOWN_Angular);

LineString<C2D> lineString = DSL.linestring(gcrs, position1, position2);

The goal is to find overlapping dates, using LineString. I got it working using only SQL, but I'm a bit unsure how to implement the LineString using geolatte, primarily which CoordinateReferenceSystem I should be using. The LineString will be stored as a Geometry field, in a database table.

The LineString will include two Point, where the y coordinates will correspond to the start_datetime and the end_datetime.

Update: Maybe this approach is preferable

C2D position1 = new C2D(-1, 1546301554 (EPOCH START TIMESTAMP));
C2D position2 = new C2D(1, 1546301559 (EPOCH END TIMESTAMP));

ProjectedCoordinateReferenceSystem test = CoordinateReferenceSystems.mkProjected(UNKNOWN_LINEAR);

LineString<C2D> lineString = DSL.linestring(test, position1, position2);

Solution

  • You're actually using the geolatte-geom library here, not hibernate-spatial (although the latter does include the former as a dependency). Your code doesn't work because you're mixing two approaches (direct and via the DSL), and you're mixing cartesian and geographic coordinates. Also, for angular (geographic) coordinates, the allowed range is [-180, 180] for longitude, and [-90,+90] for latitude. So I'm not sure in what coordinate system you're working.

    The best approach would be:

    import static org.geolatte.geom.builder.Dsl.*
    GeographicCoordinateReferenceSystem gcrs = CoordinateReferenceSystems.mkGeographic(UNKNOWN_Angular);
    
    Linestring<G2D> ls = linestring(gcrs, g(-1, 50.4), g(1, 50.4));
    
    

    Have a look at the README that gives an introduction into the library.