Search in sources :

Example 1 with WKBReader

use of org.locationtech.jts.io.WKBReader in project sis by apache.

the class Factory method parseWKB.

/**
 * Reads the given Well Known Binary (WKB).
 * This implementation does not change the buffer position.
 *
 * @param  data  the sequence of bytes to parse.
 * @return the geometry object for the given WKB.
 * @throws ParseException if the WKB can not be parsed.
 */
@Override
public GeometryWrapper<Geometry> parseWKB(final ByteBuffer data) throws ParseException {
    byte[] array;
    if (data.hasArray()) {
        /*
             * Try to use the underlying array without copy if possible.
             * Copy only if the position or length does not match.
             */
        array = data.array();
        int lower = data.arrayOffset();
        int upper = data.limit() + lower;
        lower += data.position();
        if (lower != 0 || upper != array.length) {
            array = Arrays.copyOfRange(array, lower, upper);
        }
    } else {
        array = new byte[data.remaining()];
        data.get(array);
    }
    // WKBReader(GeometryFactory) constructor is cheap.
    return new Wrapper(new WKBReader(factory).read(array));
}
Also used : GeometryWrapper(org.apache.sis.internal.feature.GeometryWrapper) Point(org.locationtech.jts.geom.Point) MultiPoint(org.locationtech.jts.geom.MultiPoint) WKBReader(org.locationtech.jts.io.WKBReader)

Aggregations

GeometryWrapper (org.apache.sis.internal.feature.GeometryWrapper)1 MultiPoint (org.locationtech.jts.geom.MultiPoint)1 Point (org.locationtech.jts.geom.Point)1 WKBReader (org.locationtech.jts.io.WKBReader)1