Subversion Repositories hibernate-spatial

Rev

Blame | Last modification | View Log | RSS feed

package org.hibernatespatial.wkb;

import com.vividsolutions.jts.geom.Coordinate;
import com.vividsolutions.jts.geom.Geometry;
import com.vividsolutions.jts.geom.GeometryFactory;
import org.hibernatespatial.jts.geom.CoordinateDimension;
import org.hibernatespatial.mgeom.MCoordinate;

/**
 * @author Karel Maesen, Geovise BVBA
 *         creation-date: Nov 12, 2010
 */
public abstract class WKBElementDecoder {

    private final GeometryFactory factory;

    public WKBElementDecoder(GeometryFactory factory){
        this.factory = factory;
    }

    protected GeometryFactory factory(){
        return this.factory;
    }

    public abstract Geometry decode(Bytes nativeGeom, CoordinateDimension dimension);

    protected Coordinate readCoordinate(Bytes bytes, CoordinateDimension dimension) {
        MCoordinate coordinate = new MCoordinate(bytes.getDouble(), bytes.getDouble());
        if (dimension.hasZ()) {
            coordinate.z = bytes.getDouble();
        }
        if (dimension.hasM()){
            coordinate.m = bytes.getDouble();
        }
        return coordinate;
    }
}