| 151 |
maesenka |
1 |
/*
|
| 156 |
maesenka |
2 |
* $Id: MultiPointDecoder.java 156 2010-01-28 22:59:30Z maesenka $
|
| 151 |
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 |
|
|
|
28 |
import com.vividsolutions.jts.geom.Coordinate;
|
|
|
29 |
import com.vividsolutions.jts.geom.MultiPoint;
|
|
|
30 |
import com.vividsolutions.jts.geom.Point;
|
|
|
31 |
|
|
|
32 |
public class MultiPointDecoder extends AbstractDecoder<MultiPoint> {
|
|
|
33 |
|
| 156 |
maesenka |
34 |
|
|
|
35 |
@Override
|
|
|
36 |
protected OpenGisType getOpenGisType() {
|
|
|
37 |
return OpenGisType.MULTIPOINT;
|
| 151 |
maesenka |
38 |
}
|
|
|
39 |
|
|
|
40 |
protected MultiPoint createNullGeometry() {
|
|
|
41 |
return getGeometryFactory().createMultiPoint(new Point[]{});
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
protected MultiPoint createGeometry(SqlGeometryV1 nativeGeom) {
|
| 156 |
maesenka |
45 |
//optimized multipoint decoding
|
| 151 |
maesenka |
46 |
Coordinate[] coords = new Coordinate[nativeGeom.getNumPoints()];
|
|
|
47 |
for (int cIdx = 0; cIdx < nativeGeom.getNumPoints(); cIdx++) {
|
|
|
48 |
coords[cIdx] = nativeGeom.getCoordinate(cIdx);
|
|
|
49 |
}
|
|
|
50 |
return getGeometryFactory().createMultiPoint(coords);
|
|
|
51 |
}
|
|
|
52 |
|
| 156 |
maesenka |
53 |
@Override
|
|
|
54 |
protected MultiPoint createGeometry(SqlGeometryV1 nativeGeom, int shapeIndex) {
|
|
|
55 |
int startChildIdx = shapeIndex + 1;
|
|
|
56 |
int endchildIdx = nativeGeom.getEndChildShape(shapeIndex);
|
|
|
57 |
Coordinate[] coordinates = new Coordinate[endchildIdx - startChildIdx];
|
|
|
58 |
for (int i = 0 ; i < coordinates.length; i++){
|
|
|
59 |
int figureOffset = nativeGeom.getStartFigureForShape(startChildIdx++);
|
|
|
60 |
int pntIdx = nativeGeom.getStartPointForFigure(figureOffset);
|
|
|
61 |
coordinates[i] = nativeGeom.getCoordinate(pntIdx);
|
|
|
62 |
}
|
|
|
63 |
return getGeometryFactory().createMultiPoint(coordinates);
|
|
|
64 |
}
|
| 151 |
maesenka |
65 |
|
| 156 |
maesenka |
66 |
|
| 151 |
maesenka |
67 |
}
|