Subversion Repositories hibernate-spatial

Rev

Rev 155 | Rev 161 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
145 maesenka 1
/*
156 maesenka 2
 * $Id: LineStringDecoder.java 156 2010-01-28 22:59:30Z maesenka $
145 maesenka 3
 *
4
 * This file is part of Hibernate Spatial, an extension to the
5
 * hibernate ORM solution for geographic data.
6
 *
7
 * Copyright © 2009 Geovise BVBA
8
 *
9
 * This library is free software; you can redistribute it and/or
10
 * modify it under the terms of the GNU Lesser General Public
11
 * License as published by the Free Software Foundation; either
12
 * version 2.1 of the License, or (at your option) any later version.
13
 *
14
 * This library is distributed in the hope that it will be useful,
15
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17
 * Lesser General Public License for more details.
18
 *
19
 * You should have received a copy of the GNU Lesser General Public
20
 * License along with this library; if not, write to the Free Software
21
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
 *
23
 * For more information, visit: http://www.hibernatespatial.org/
24
 */
25
 
26
package org.hibernatespatial.sqlserver.convertors;
27
 
148 maesenka 28
import com.vividsolutions.jts.geom.Coordinate;
145 maesenka 29
import com.vividsolutions.jts.geom.CoordinateSequence;
30
import com.vividsolutions.jts.geom.LineString;
31
import org.hibernatespatial.mgeom.MCoordinate;
32
 
33
class LineStringDecoder extends AbstractDecoder<LineString> {
34
 
156 maesenka 35
    @Override
36
    protected OpenGisType getOpenGisType() {
37
        return OpenGisType.LINESTRING;
145 maesenka 38
    }
39
 
40
    protected LineString createNullGeometry() {
41
        return getGeometryFactory().createLineString((CoordinateSequence) null);
42
    }
43
 
44
    protected LineString createGeometry(SqlGeometryV1 nativeGeom) {
148 maesenka 45
        return createLineString(nativeGeom, 0, nativeGeom.getNumPoints());
145 maesenka 46
    }
47
 
156 maesenka 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
 
149 maesenka 57
    protected LineString createLineString(SqlGeometryV1 nativeGeom, int offset, int nextOffset) {
156 maesenka 58
        Coordinate[] coordinates = nativeGeom.coordinateRange(offset, nextOffset);
59
        return createLineString(coordinates, nativeGeom);
148 maesenka 60
    }
61
 
149 maesenka 62
    private LineString createLineString(Coordinate[] coords, SqlGeometryV1 nativeGeom) {
63
        if (nativeGeom.hasMValues()) {
64
            return getGeometryFactory().createMLineString((MCoordinate[]) coords);
65
        } else {
66
            return getGeometryFactory().createLineString(coords);
148 maesenka 67
        }
149 maesenka 68
 
148 maesenka 69
    }
70
 
156 maesenka 71
 
145 maesenka 72
}