svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.compat.cdc / org.gvsig.fmap.geometry / org.gvsig.fmap.geometry.jts / src / main / java / org / gvsig / fmap / geom / jts / primitive / surface / polygon / Polygon3D.java @ 42281
History | View | Annotate | Download (6.12 KB)
1 |
/* gvSIG. Desktop Geographic Information System.
|
---|---|
2 |
*
|
3 |
* Copyright ? 2007-2015 gvSIG Association
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
18 |
* MA 02110-1301, USA.
|
19 |
*
|
20 |
* For any additional information, do not hesitate to contact us
|
21 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
22 |
*/
|
23 |
package org.gvsig.fmap.geom.jts.primitive.surface.polygon; |
24 |
|
25 |
import java.awt.geom.AffineTransform; |
26 |
import java.awt.geom.PathIterator; |
27 |
import java.util.ArrayList; |
28 |
import java.util.Iterator; |
29 |
import java.util.List; |
30 |
|
31 |
import com.vividsolutions.jts.geom.Coordinate; |
32 |
|
33 |
import org.gvsig.fmap.geom.Geometry; |
34 |
import org.gvsig.fmap.geom.GeometryException; |
35 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
36 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
37 |
import org.gvsig.fmap.geom.jts.GeometryJTS; |
38 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D; |
39 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3D; |
40 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.BaseLine3D; |
41 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
42 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
43 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
44 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
45 |
import org.gvsig.fmap.geom.primitive.Line; |
46 |
import org.gvsig.fmap.geom.primitive.Polygon; |
47 |
import org.gvsig.fmap.geom.primitive.Ring; |
48 |
import org.gvsig.fmap.geom.primitive.SurfaceAppearance; |
49 |
|
50 |
|
51 |
|
52 |
/**
|
53 |
* @author fdiaz
|
54 |
*
|
55 |
*/
|
56 |
public class Polygon3D extends BaseLine3D implements Polygon { |
57 |
|
58 |
/**
|
59 |
*
|
60 |
*/
|
61 |
private static final long serialVersionUID = 5748137753517288500L; |
62 |
|
63 |
List<Ring> interiorRings = new ArrayList<Ring>(); |
64 |
|
65 |
/**
|
66 |
* @param subtype
|
67 |
*/
|
68 |
public Polygon3D() {
|
69 |
super();
|
70 |
} |
71 |
|
72 |
/**
|
73 |
*
|
74 |
*/
|
75 |
public Polygon3D(Coordinate[] coordinates) { |
76 |
super(coordinates);
|
77 |
} |
78 |
|
79 |
/* (non-Javadoc)
|
80 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
81 |
*/
|
82 |
public Geometry cloneGeometry() {
|
83 |
return new Polygon3D((Coordinate[]) coordinates.clone()); |
84 |
} |
85 |
|
86 |
/* (non-Javadoc)
|
87 |
* @see org.gvsig.fmap.geom.primitive.Surface#setSurfaceAppearance(org.gvsig.fmap.geom.primitive.SurfaceAppearance)
|
88 |
*/
|
89 |
public void setSurfaceAppearance(SurfaceAppearance app) { |
90 |
// TODO Auto-generated method stub
|
91 |
|
92 |
} |
93 |
|
94 |
/* (non-Javadoc)
|
95 |
* @see org.gvsig.fmap.geom.primitive.Surface#getSurfaceAppearance()
|
96 |
*/
|
97 |
public SurfaceAppearance getSurfaceAppearance() {
|
98 |
// TODO Auto-generated method stub
|
99 |
return null; |
100 |
} |
101 |
|
102 |
/* (non-Javadoc)
|
103 |
* @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
|
104 |
*/
|
105 |
public int getNumInteriorRings() { |
106 |
return this.interiorRings.size(); |
107 |
} |
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
|
111 |
*/
|
112 |
public Ring getInteriorRing(int index) { |
113 |
return interiorRings.get(index);
|
114 |
} |
115 |
|
116 |
/* (non-Javadoc)
|
117 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
|
118 |
*/
|
119 |
public void addInteriorRing(Ring ring) { |
120 |
interiorRings.add(ring); |
121 |
} |
122 |
|
123 |
/* (non-Javadoc)
|
124 |
* @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Line)
|
125 |
*/
|
126 |
public void addInteriorRing(Line ring) { |
127 |
interiorRings.add((Ring)ring); //FIXME: ?????
|
128 |
} |
129 |
|
130 |
/* (non-Javadoc)
|
131 |
* @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
|
132 |
*/
|
133 |
public void removeInteriorRing(int index) { |
134 |
interiorRings.remove(index); |
135 |
} |
136 |
|
137 |
/* (non-Javadoc)
|
138 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
139 |
*/
|
140 |
public MultiLine toLines() throws GeometryException { |
141 |
MultiLine multiLine = new MultiLine3D();
|
142 |
multiLine.addPrimitive(new Line3D(coordinates.toCoordinateArray()));
|
143 |
return multiLine;
|
144 |
} |
145 |
|
146 |
/* (non-Javadoc)
|
147 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
148 |
*/
|
149 |
public MultiPolygon toPolygons() throws GeometryException { |
150 |
MultiPolygon multiPolygon = new MultiPolygon3D();
|
151 |
multiPolygon.addPrimitive(this);
|
152 |
return multiPolygon;
|
153 |
} |
154 |
|
155 |
/* (non-Javadoc)
|
156 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
157 |
*/
|
158 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
159 |
return JTSUtils.createJTSPolygon(coordinates, interiorRings);
|
160 |
} |
161 |
|
162 |
|
163 |
|
164 |
/*
|
165 |
* (non-Javadoc)
|
166 |
*
|
167 |
* @see
|
168 |
* org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
169 |
* )
|
170 |
*/
|
171 |
public PathIterator getPathIterator(AffineTransform at) { |
172 |
PolygonIterator pi = new PolygonIterator(this, at); |
173 |
return pi;
|
174 |
} |
175 |
|
176 |
/* (non-Javadoc)
|
177 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#ensureOrientation(boolean)
|
178 |
*/
|
179 |
public boolean ensureOrientation(boolean ccw) throws GeometryOperationNotSupportedException, GeometryOperationException { |
180 |
boolean result = super.ensureOrientation(ccw); |
181 |
for (Iterator<Ring> iterator = interiorRings.iterator(); iterator.hasNext();) { |
182 |
GeometryJTS ring = (GeometryJTS) iterator.next(); |
183 |
ring.ensureOrientation(!ccw); |
184 |
} |
185 |
return result;
|
186 |
} |
187 |
|
188 |
/* (non-Javadoc)
|
189 |
* @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#flip()
|
190 |
*/
|
191 |
@Override
|
192 |
public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
193 |
super.flip();
|
194 |
for (Iterator<Ring> iterator = interiorRings.iterator(); iterator.hasNext();) { |
195 |
GeometryJTS ring = (GeometryJTS) iterator.next(); |
196 |
ring.flip(); |
197 |
} |
198 |
} |
199 |
} |