GeoLatte / geolatte-geom

A geometry model that conforms to the OGC Simple Features for SQL specification.
Other
132 stars 63 forks source link

Mysql: Can't convert geometries of type org.geolatte.geom.LinearRing #152

Closed xak2000 closed 1 year ago

xak2000 commented 1 year ago

This code works in 1.7.0:

WkbEncoder encoder = Wkb.newEncoder(Wkb.Dialect.MYSQL_WKB);

PositionSequence<G2D> seq = PositionSequenceBuilders.fixedSized(5, G2D.class)
    .add(geoRectangle.getNortheast().getLon().asDouble(), geoRectangle.getNortheast().getLat().asDouble())
    .add(geoRectangle.getNorthwest().getLon().asDouble(), geoRectangle.getNorthwest().getLat().asDouble())
    .add(geoRectangle.getSouthwest().getLon().asDouble(), geoRectangle.getSouthwest().getLat().asDouble())
    .add(geoRectangle.getSoutheast().getLon().asDouble(), geoRectangle.getSoutheast().getLat().asDouble())
    .add(geoRectangle.getNortheast().getLon().asDouble(), geoRectangle.getNortheast().getLat().asDouble())
    .toPositionSequence(); // basically a closed LINESTRING

Geometry<G2D> geometry = Geometries.mkLinearRing(seq, CoordinateReferenceSystems.WGS84);
ByteBuffer buffer = encoder.encode(geometry, ByteOrder.NDR);

After upgrading to 1.8.2 (also tried 1.8.0) encoder.encode(...) throws:

org.geolatte.geom.codec.UnsupportedConversionException: Can't convert geometries of type org.geolatte.geom.LinearRing
    at org.geolatte.geom.codec.WkbDialect.geometryTypeCode(WkbDialect.java:127) ~[geolatte-geom-1.8.2.jar:na]
    at org.geolatte.geom.codec.BaseWkbVisitor.writeTypeCodeAndSrid(BaseWkbVisitor.java:136) ~[geolatte-geom-1.8.2.jar:na]
    at org.geolatte.geom.codec.BaseWkbVisitor.visit(BaseWkbVisitor.java:78) ~[geolatte-geom-1.8.2.jar:na]
    at org.geolatte.geom.LineString.accept(LineString.java:114) ~[geolatte-geom-1.8.2.jar:na]
    at org.geolatte.geom.codec.MySqlWkbEncoder.encode(MySqlWkbEncoder.java:42) ~[geolatte-geom-1.8.2.jar:na]
xak2000 commented 1 year ago

I think I found a root of this error.

Previously in 1.7.0 this method was used to get geometry type. This method correctly handles class inheritance and detects that type of LinearRing class (that inherits from LineString class) is LINE_STRING.

New logic introduced in 1.8.0 changed this and now inheritance is not handled.

maesenka commented 1 year ago

Thanks for the report, and diagnosis. It's fixed now in branch master. I'll make a release soon.

xak2000 commented 1 year ago

@maesenka Hello! Do you have any expectations about new release date?