Quick Search:

View

Revision:

Diff

Diff from 201 to:

Annotations

Annotate by Age | Author | Mixed | None
/fisheye/browse/HibernateSpatial/trunk/hibernate-spatial-sqlserver/src/main/java/org/hibernatespatial/sqlserver/convertors/PolygonEncoder.java

Annotated File View

maesenka
149
1 /*
maesenka
201
2  * $Id: PolygonEncoder.java 201 2010-04-05 13:49:25Z maesenka $
maesenka
149
3  *
4  * This file is part of Hibernate Spatial, an extension to the
5  * hibernate ORM solution for geographic data.
6  *
maesenka
163
7  * Copyright © 2007-2010 Geovise BVBA
maesenka
149
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
maesenka
156
28 import com.vividsolutions.jts.geom.Coordinate;
maesenka
149
29 import com.vividsolutions.jts.geom.Geometry;
30 import com.vividsolutions.jts.geom.LineString;
31 import com.vividsolutions.jts.geom.Polygon;
32
maesenka
156
33 import java.util.List;
34
maesenka
201
35 /**
36  * <code>Encoder</code> for Polygons.
37  *
38  * @uthor Karel Maesen, Geovise BVBA
39  */
40 class PolygonEncoder extends AbstractEncoder<Polygon> {
maesenka
149
41
42     public boolean accepts(Geometry geom) {
43         return geom instanceof Polygon;
44     }
45
maesenka
156
46     @Override
47     protected void encode(Geometry geomint parentShapeIndexList<CoordinatecoordinatesList<FigurefiguresList<Shapeshapes) {
maesenka
162
48         if (!(geom instanceof Polygon)) throw new IllegalArgumentException("Polygon geometry expected.");
49         if (geom.isEmpty()) {
50             shapes.add(new Shape(parentShapeIndex, -1OpenGisType.POLYGON));
51             return;
52         }
53         Polygon polygon = (Polygongeom;
maesenka
156
54         int figureOffset = figures.size();
maesenka
162
55         shapes.add(new Shape(parentShapeIndexfigureOffsetOpenGisType.POLYGON));
maesenka
156
56
57         int pointOffset = coordinates.size();
58         addExteriorRing(polygoncoordinatesfigures);
59         addInteriorRings(polygoncoordinatesfigures);
60
maesenka
150
61     }
62
maesenka
156
63
maesenka
162
64     private void addInteriorRings(Polygon geomList<CoordinatecoordinatesList<Figurefigures) {
65         for (int idx = 0idx < geom.getNumInteriorRing(); idx++) {
maesenka
156
66             addInteriorRing(geom.getInteriorRingN(idx), coordinatesfigures);
maesenka
149
67         }
68     }
69
maesenka
156
70     private void addInteriorRing(LineString ringList<CoordinatecoordinatesList<Figurefigures) {
71         int pointOffset = coordinates.size();
72         addPoints(ringcoordinates);
maesenka
150
73         Figure figure = new Figure(FigureAttribute.InteriorRingpointOffset);
maesenka
156
74         figures.add(figure);
75
maesenka
149
76     }
77
maesenka
156
78     private void addPoints(LineString ringList<Coordinatecoordinates) {
maesenka
162
79         for (Coordinate c : ring.getCoordinates()) {
maesenka
156
80             coordinates.add(c);
81         }
82     }
83
84     private void addExteriorRing(Polygon geomList<CoordinatecoordinatesList<Figurefigures) {
maesenka
149
85         LineString shell = geom.getExteriorRing();
maesenka
156
86         int offset = coordinates.size();
87         addPoints(shellcoordinates);
maesenka
149
88         Figure exterior = new Figure(FigureAttribute.ExteriorRingoffset);
maesenka
156
89         figures.add(exterior);
maesenka
149
90     }
91
maesenka
156
92
maesenka
149
93 }
FishEye: Open Source License registered to Hibernate Spatial.
Your maintenance has expired. You can renew your license at http://www.atlassian.com/fisheye/renew
Atlassian FishEye, Subversion, CVS & Perforce analysis. (Version:1.5.2 Build:build-298 2008-05-26 ) - Administration - Page generated 2010-09-09 22:43 +0200