Subversion Repositories hibernate-spatial

Rev

Rev 155 | Rev 161 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 155 Rev 156
Line 1... Line 1...
1
/*
1
/*
2
 * $Id: LineStringDecoder.java 155 2010-01-13 21:00:35Z maesenka $
2
 * $Id: LineStringDecoder.java 156 2010-01-28 22:59:30Z maesenka $
3
 *
3
 *
4
 * This file is part of Hibernate Spatial, an extension to the
4
 * This file is part of Hibernate Spatial, an extension to the
5
 * hibernate ORM solution for geographic data.
5
 * hibernate ORM solution for geographic data.
6
 *
6
 *
7
 * Copyright © 2009 Geovise BVBA
7
 * Copyright © 2009 Geovise BVBA
Line 30... Line 30...
30
import com.vividsolutions.jts.geom.LineString;
30
import com.vividsolutions.jts.geom.LineString;
31
import org.hibernatespatial.mgeom.MCoordinate;
31
import org.hibernatespatial.mgeom.MCoordinate;
32
 
32
 
33
class LineStringDecoder extends AbstractDecoder<LineString> {
33
class LineStringDecoder extends AbstractDecoder<LineString> {
34
 
34
 
-
 
35
    @Override
35
    public boolean accepts(SqlGeometryV1 nativeGeom) {
36
    protected OpenGisType getOpenGisType() {
36
        return nativeGeom.openGisType() == OpenGisType.LINESTRING;
37
        return OpenGisType.LINESTRING;
37
    }
38
    }
38
 
39
 
39
    protected LineString createNullGeometry() {
40
    protected LineString createNullGeometry() {
40
        return getGeometryFactory().createLineString((CoordinateSequence) null);
41
        return getGeometryFactory().createLineString((CoordinateSequence) null);
41
    }
42
    }
42
 
43
 
43
    protected LineString createGeometry(SqlGeometryV1 nativeGeom) {
44
    protected LineString createGeometry(SqlGeometryV1 nativeGeom) {
44
        return createLineString(nativeGeom, 0, nativeGeom.getNumPoints());
45
        return createLineString(nativeGeom, 0, nativeGeom.getNumPoints());
45
    }
46
    }
46
 
47
 
-
 
48
    @Override
-
 
49
    protected LineString createGeometry(SqlGeometryV1 nativeGeom, int shapeIndex) {
-
 
50
        int figureOffset = nativeGeom.getStartFigureForShape(shapeIndex);
-
 
51
        //linestring shapes have exactly one figure
-
 
52
        int startOffset = nativeGeom.getStartPointForFigure(figureOffset);
-
 
53
        int endOffset = nativeGeom.getEndPointForFigure(figureOffset);
-
 
54
        return createLineString(nativeGeom, startOffset, endOffset);
-
 
55
    }
-
 
56
 
47
    protected LineString createLineString(SqlGeometryV1 nativeGeom, int offset, int nextOffset) {
57
    protected LineString createLineString(SqlGeometryV1 nativeGeom, int offset, int nextOffset) {
48
        Coordinate[] coords = createCoordinateArray(nextOffset - offset, nativeGeom);
58
        Coordinate[] coordinates = nativeGeom.coordinateRange(offset, nextOffset);
49
        for (int idx = offset, i = 0; idx < nextOffset; idx++, i++) {
-
 
50
            coords[i] = nativeGeom.getCoordinate(idx);
-
 
51
        }
-
 
52
        return createLineString(coords, nativeGeom);
59
        return createLineString(coordinates, nativeGeom);
53
    }
60
    }
54
 
61
 
55
    private LineString createLineString(Coordinate[] coords, SqlGeometryV1 nativeGeom) {
62
    private LineString createLineString(Coordinate[] coords, SqlGeometryV1 nativeGeom) {
56
        if (nativeGeom.hasMValues()) {
63
        if (nativeGeom.hasMValues()) {
57
            return getGeometryFactory().createMLineString((MCoordinate[]) coords);
64
            return getGeometryFactory().createMLineString((MCoordinate[]) coords);
Line 59... Line 66...
59
            return getGeometryFactory().createLineString(coords);
66
            return getGeometryFactory().createLineString(coords);
60
        }
67
        }
61
 
68
 
62
    }
69
    }
63
 
70
 
64
    private Coordinate[] createCoordinateArray(int size, SqlGeometryV1 nativeGeom) {
-
 
65
        if (nativeGeom.hasMValues()) {
-
 
66
            return new MCoordinate[size];
-
 
67
        } else {
-
 
68
            return new Coordinate[size];
-
 
69
        }
-
 
70
    }
-
 
71
 
71
 
72
}
72
}