jdeolive / geodb

Spatial database bindings for Java.
MIT License
67 stars 25 forks source link

EWKB and WKB geometries are incompatible #10

Closed boonen closed 12 years ago

boonen commented 12 years ago

We've come across a peculiar error in GeoDB's (E)WKB methods. Converting a geometry to an EWB (byte[]) and then converting this back to a geometry leads to a geometry that is not the same as its original.

The JUnit test below shows this behaviour (using version 0.6 of GeoDB from the Maven repository). A Point with coordinates (10, 10) is written to an EWKB and then transformed back to a Geometry. The result is a Poin with coordinates (0,0). Probably the error occurs on line 1173 of the GeoDB class).

package geodb;

import junit.framework.Assert;
import geodb.GeoDB;

import org.hibernatespatial.test.EWKTReader;
import org.junit.Test;

import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.io.ParseException;

public class GeoDBEWKBTest {

    @Test
    public void testGToEWKB() throws ParseException {
        Geometry g = new EWKTReader().read("SRID=4326;POINT (10 10)");
        // to and from ewkb
        byte[] ewkb = GeoDB.gToEWKB(g);
        Geometry gFromEwkb = GeoDB.gFromEWKB(ewkb);
        Assert.assertEquals(g, gFromEwkb);
    }
}
jdeolive commented 12 years ago

Thanks for the test case Jan! There was some bad logic in the ewkb encoding. Let me know if the new version fixes it for you.