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 / Polygon3DM.java @ 47432
History | View | Annotate | Download (14.1 KB)
1 | 42269 | fdiaz | /* 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 | 47432 | fdiaz | import com.vividsolutions.jts.geom.Coordinate; |
26 | import com.vividsolutions.jts.geom.CoordinateSequence; |
||
27 | import java.awt.Shape; |
||
28 | 42275 | fdiaz | import java.awt.geom.AffineTransform; |
29 | import java.awt.geom.PathIterator; |
||
30 | 42269 | fdiaz | import java.util.ArrayList; |
31 | 42281 | fdiaz | import java.util.Iterator; |
32 | 42269 | fdiaz | import java.util.List; |
33 | 42464 | fdiaz | import org.cresques.cts.ICoordTrans; |
34 | 42270 | fdiaz | import org.gvsig.fmap.geom.Geometry; |
35 | 42269 | fdiaz | import org.gvsig.fmap.geom.GeometryException; |
36 | import org.gvsig.fmap.geom.aggregate.MultiLine; |
||
37 | import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
||
38 | 42281 | fdiaz | import org.gvsig.fmap.geom.jts.GeometryJTS; |
39 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.aggregate.MultiLine3DM; |
40 | import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon3DM; |
||
41 | 47432 | fdiaz | import org.gvsig.fmap.geom.jts.mgeom.MCoordinate; |
42 | 42270 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.curve.line.BaseLine3DM; |
43 | 42269 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3DM; |
44 | 42283 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.point.Point3DM; |
45 | import org.gvsig.fmap.geom.jts.primitive.ring.Ring3DM; |
||
46 | 46332 | fdiaz | import org.gvsig.fmap.geom.jts.primitive.surface.split.SurfaceSplitOperation; |
47 | 44612 | jjdelcerro | import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
48 | 42274 | fdiaz | import org.gvsig.fmap.geom.jts.util.JTSUtils; |
49 | 42281 | fdiaz | import org.gvsig.fmap.geom.operation.GeometryOperationException; |
50 | import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
||
51 | 42269 | fdiaz | import org.gvsig.fmap.geom.primitive.Line; |
52 | import org.gvsig.fmap.geom.primitive.Polygon; |
||
53 | import org.gvsig.fmap.geom.primitive.Ring; |
||
54 | import org.gvsig.fmap.geom.primitive.SurfaceAppearance; |
||
55 | |||
56 | |||
57 | /**
|
||
58 | * @author fdiaz
|
||
59 | *
|
||
60 | */
|
||
61 | 42270 | fdiaz | public class Polygon3DM extends BaseLine3DM implements Polygon { |
62 | 42269 | fdiaz | |
63 | /**
|
||
64 | *
|
||
65 | */
|
||
66 | private static final long serialVersionUID = -5989088152154360862L; |
||
67 | |||
68 | List<Ring> interiorRings = new ArrayList<Ring>(); |
||
69 | |||
70 | /**
|
||
71 | * @param subtype
|
||
72 | */
|
||
73 | 42271 | fdiaz | public Polygon3DM() {
|
74 | 42283 | fdiaz | super(Geometry.TYPES.POLYGON);
|
75 | 42269 | fdiaz | } |
76 | |||
77 | |||
78 | /**
|
||
79 | *
|
||
80 | */
|
||
81 | public Polygon3DM(Coordinate[] coordinates) { |
||
82 | 42304 | fdiaz | super(Geometry.TYPES.POLYGON, coordinates);
|
83 | 42283 | fdiaz | closePrimitive(); |
84 | 42269 | fdiaz | } |
85 | |||
86 | 47432 | fdiaz | public Polygon3DM(ArrayListCoordinateSequence coordinates) {
|
87 | super(Geometry.TYPES.POLYGON, coordinates);
|
||
88 | closePrimitive(); |
||
89 | } |
||
90 | 42269 | fdiaz | |
91 | 47432 | fdiaz | |
92 | 42269 | fdiaz | /* (non-Javadoc)
|
93 | * @see org.gvsig.fmap.geom.primitive.Surface#setSurfaceAppearance(org.gvsig.fmap.geom.primitive.SurfaceAppearance)
|
||
94 | */
|
||
95 | public void setSurfaceAppearance(SurfaceAppearance app) { |
||
96 | // TODO Auto-generated method stub
|
||
97 | |||
98 | } |
||
99 | |||
100 | /* (non-Javadoc)
|
||
101 | * @see org.gvsig.fmap.geom.primitive.Surface#getSurfaceAppearance()
|
||
102 | */
|
||
103 | public SurfaceAppearance getSurfaceAppearance() {
|
||
104 | // TODO Auto-generated method stub
|
||
105 | return null; |
||
106 | } |
||
107 | |||
108 | /* (non-Javadoc)
|
||
109 | * @see org.gvsig.fmap.geom.primitive.Surface#getNumInteriorRings()
|
||
110 | */
|
||
111 | public int getNumInteriorRings() { |
||
112 | return interiorRings.size();
|
||
113 | } |
||
114 | |||
115 | /* (non-Javadoc)
|
||
116 | * @see org.gvsig.fmap.geom.primitive.Surface#getInteriorRing(int)
|
||
117 | */
|
||
118 | public Ring getInteriorRing(int index) { |
||
119 | return interiorRings.get(index);
|
||
120 | } |
||
121 | |||
122 | /* (non-Javadoc)
|
||
123 | * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Ring)
|
||
124 | */
|
||
125 | public void addInteriorRing(Ring ring) { |
||
126 | interiorRings.add(ring); |
||
127 | } |
||
128 | |||
129 | /* (non-Javadoc)
|
||
130 | * @see org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.geom.primitive.Line)
|
||
131 | */
|
||
132 | 42283 | fdiaz | public void addInteriorRing(Line line) { |
133 | Ring3DM ring = new Ring3DM();
|
||
134 | ring.ensureCapacity(line.getNumVertices()); |
||
135 | for(int i=0; i<line.getNumVertices(); i++){ |
||
136 | Point3DM vertex = (Point3DM)line.getVertex(i); |
||
137 | ring.addVertex(new Point3DM(vertex.getX(), vertex.getY(), vertex.getZ(), vertex.getM()));
|
||
138 | } |
||
139 | ring.closePrimitive(); |
||
140 | interiorRings.add(ring); |
||
141 | 42269 | fdiaz | } |
142 | |||
143 | 42283 | fdiaz | /*
|
144 | * (non-Javadoc)
|
||
145 | *
|
||
146 | * @see
|
||
147 | * org.gvsig.fmap.geom.primitive.Surface#addInteriorRing(org.gvsig.fmap.
|
||
148 | * geom.primitive.Polygon)
|
||
149 | */
|
||
150 | public void addInteriorRing(Polygon polygon) { |
||
151 | Ring3DM ring = new Ring3DM();
|
||
152 | ring.ensureCapacity(polygon.getNumVertices()); |
||
153 | for(int i=0; i<polygon.getNumVertices(); i++){ |
||
154 | Point3DM vertex = (Point3DM)polygon.getVertex(i); |
||
155 | ring.addVertex(new Point3DM(vertex.getX(), vertex.getY(), vertex.getZ(), vertex.getM()));
|
||
156 | } |
||
157 | ring.closePrimitive(); |
||
158 | interiorRings.add(ring); |
||
159 | } |
||
160 | |||
161 | 42269 | fdiaz | /* (non-Javadoc)
|
162 | * @see org.gvsig.fmap.geom.primitive.Surface#removeInteriorRing(int)
|
||
163 | */
|
||
164 | public void removeInteriorRing(int index) { |
||
165 | interiorRings.remove(index); |
||
166 | } |
||
167 | |||
168 | /*
|
||
169 | * (non-Javadoc)
|
||
170 | *
|
||
171 | * @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
||
172 | */
|
||
173 | public MultiLine toLines() throws GeometryException { |
||
174 | MultiLine multiLine = new MultiLine3DM();
|
||
175 | multiLine.addPrimitive(new Line3DM(coordinates.toCoordinateArray()));
|
||
176 | return multiLine;
|
||
177 | } |
||
178 | |||
179 | /*
|
||
180 | * (non-Javadoc)
|
||
181 | *
|
||
182 | * @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
||
183 | */
|
||
184 | public MultiPolygon toPolygons() throws GeometryException { |
||
185 | MultiPolygon multiPolygon = new MultiPolygon3DM();
|
||
186 | multiPolygon.addPrimitive(this);
|
||
187 | return multiPolygon;
|
||
188 | } |
||
189 | |||
190 | 42270 | fdiaz | |
191 | /* (non-Javadoc)
|
||
192 | * @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
||
193 | */
|
||
194 | 47346 | fdiaz | @Override
|
195 | 44040 | jjdelcerro | public Polygon cloneGeometry() { |
196 | 42304 | fdiaz | Polygon3DM cloned = new Polygon3DM(cloneCoordinates().toCoordinateArray());
|
197 | for (int i = 0; i < getNumInteriorRings(); i++){ |
||
198 | cloned.addInteriorRing((Ring)getInteriorRing(i).cloneGeometry()); |
||
199 | } |
||
200 | 47346 | fdiaz | cloned.setProjection(this.getProjection());
|
201 | 42304 | fdiaz | return cloned;
|
202 | 42270 | fdiaz | } |
203 | 42274 | fdiaz | |
204 | 44040 | jjdelcerro | @Override
|
205 | 44612 | jjdelcerro | public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
206 | ArrayListCoordinateSequence coordinates2D = new ArrayListCoordinateSequence(coordinates.size());
|
||
207 | for (Coordinate coordinate : this.coordinates) { |
||
208 | coordinates2D.add(new Coordinate(coordinate.x, coordinate.y));
|
||
209 | } |
||
210 | Polygon2D poligon2D = new Polygon2D(coordinates2D);
|
||
211 | 45157 | jolivas | poligon2D.setProjection(this.getProjection());
|
212 | 44612 | jjdelcerro | for (int i = 0; i < getNumInteriorRings(); i++){ |
213 | poligon2D.addInteriorRing((Ring)getInteriorRing(i).force2D()); |
||
214 | } |
||
215 | return poligon2D;
|
||
216 | } |
||
217 | |||
218 | @Override
|
||
219 | 47432 | fdiaz | public Geometry force2DM() throws GeometryOperationNotSupportedException, GeometryOperationException { |
220 | ArrayListCoordinateSequence coordinates2DM = new ArrayListCoordinateSequence(coordinates.size());
|
||
221 | for (Coordinate coordinate : this.coordinates) { |
||
222 | coordinates2DM.add(MCoordinate.create2dWithMeasure(coordinate.x, coordinate.y, coordinate.getOrdinate(CoordinateSequence.M))); |
||
223 | } |
||
224 | Polygon2DM poligon2DM = new Polygon2DM(coordinates2DM);
|
||
225 | poligon2DM.setProjection(this.getProjection());
|
||
226 | for (int i = 0; i < getNumInteriorRings(); i++){ |
||
227 | poligon2DM.addInteriorRing((Ring)getInteriorRing(i).force2DM()); |
||
228 | } |
||
229 | return poligon2DM;
|
||
230 | } |
||
231 | |||
232 | @Override
|
||
233 | public Geometry force3D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
234 | ArrayListCoordinateSequence coordinates3D = new ArrayListCoordinateSequence(coordinates.size());
|
||
235 | for (Coordinate coordinate : this.coordinates) { |
||
236 | coordinates3D.add(new Coordinate(coordinate.x, coordinate.y, coordinate.getOrdinate(CoordinateSequence.Z)));
|
||
237 | } |
||
238 | Polygon3D poligon3D = new Polygon3D(coordinates3D);
|
||
239 | poligon3D.setProjection(this.getProjection());
|
||
240 | for (int i = 0; i < getNumInteriorRings(); i++){ |
||
241 | poligon3D.addInteriorRing((Ring)getInteriorRing(i).force3D()); |
||
242 | } |
||
243 | return poligon3D;
|
||
244 | } |
||
245 | |||
246 | @Override
|
||
247 | public Geometry force3DM() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
248 | ArrayListCoordinateSequence coordinates3DM = new ArrayListCoordinateSequence(coordinates.size());
|
||
249 | for (Coordinate coordinate : this.coordinates) { |
||
250 | coordinates3DM.add(MCoordinate.create3dWithMeasure(coordinate.x, coordinate.y, coordinate.z, coordinate.getOrdinate(CoordinateSequence.M))); |
||
251 | } |
||
252 | Polygon3DM poligon3DM = new Polygon3DM(coordinates3DM);
|
||
253 | poligon3DM.setProjection(this.getProjection());
|
||
254 | for (int i = 0; i < getNumInteriorRings(); i++){ |
||
255 | poligon3DM.addInteriorRing((Ring)getInteriorRing(i).force3DM()); |
||
256 | } |
||
257 | return poligon3DM;
|
||
258 | } |
||
259 | |||
260 | |||
261 | @Override
|
||
262 | 44040 | jjdelcerro | @SuppressWarnings("CloneDoesntCallSuperClone") |
263 | public Polygon clone() throws CloneNotSupportedException { |
||
264 | return this.cloneGeometry(); |
||
265 | } |
||
266 | |||
267 | 42274 | fdiaz | /* (non-Javadoc)
|
268 | * @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
||
269 | */
|
||
270 | public com.vividsolutions.jts.geom.Geometry getJTS() {
|
||
271 | return JTSUtils.createJTSPolygon(coordinates, interiorRings);
|
||
272 | } |
||
273 | 42275 | fdiaz | |
274 | |||
275 | /*
|
||
276 | * (non-Javadoc)
|
||
277 | *
|
||
278 | * @see
|
||
279 | * org.gvsig.fmap.geom.Geometry#getPathIterator(java.awt.geom.AffineTransform
|
||
280 | * )
|
||
281 | */
|
||
282 | public PathIterator getPathIterator(AffineTransform at) { |
||
283 | PolygonIterator pi = new PolygonIterator(this, at); |
||
284 | return pi;
|
||
285 | } |
||
286 | |||
287 | 42281 | fdiaz | /* (non-Javadoc)
|
288 | * @see org.gvsig.fmap.geom.jts.GeometryJTS#ensureOrientation(boolean)
|
||
289 | */
|
||
290 | public boolean ensureOrientation(boolean ccw) throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
291 | boolean result = super.ensureOrientation(ccw); |
||
292 | for (Iterator<Ring> iterator = interiorRings.iterator(); iterator.hasNext();) { |
||
293 | GeometryJTS ring = (GeometryJTS) iterator.next(); |
||
294 | ring.ensureOrientation(!ccw); |
||
295 | } |
||
296 | return result;
|
||
297 | } |
||
298 | |||
299 | /* (non-Javadoc)
|
||
300 | * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#flip()
|
||
301 | */
|
||
302 | @Override
|
||
303 | public void flip() throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
304 | super.flip();
|
||
305 | for (Iterator<Ring> iterator = interiorRings.iterator(); iterator.hasNext();) { |
||
306 | GeometryJTS ring = (GeometryJTS) iterator.next(); |
||
307 | ring.flip(); |
||
308 | } |
||
309 | } |
||
310 | 42304 | fdiaz | |
311 | |||
312 | /* (non-Javadoc)
|
||
313 | * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#transform(java.awt.geom.AffineTransform)
|
||
314 | */
|
||
315 | @Override
|
||
316 | public void transform(AffineTransform at) { |
||
317 | super.transform(at);
|
||
318 | for (Iterator<Ring> iterator = interiorRings.iterator(); iterator.hasNext();) { |
||
319 | GeometryJTS ring = (GeometryJTS) iterator.next(); |
||
320 | ring.transform(at); |
||
321 | } |
||
322 | } |
||
323 | 42441 | fdiaz | |
324 | |||
325 | /* (non-Javadoc)
|
||
326 | * @see org.gvsig.fmap.geom.Geometry#offset(double)
|
||
327 | */
|
||
328 | public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
329 | 44099 | jjdelcerro | return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance)); |
330 | 42441 | fdiaz | } |
331 | 42464 | fdiaz | |
332 | 45762 | fdiaz | @Override
|
333 | public Geometry offset(int joinStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
||
334 | return JTSUtils.createGeometry(this.getProjection(), getJTS().buffer(distance, JTSUtils.calculateQuadrantSegments(joinStyle))); |
||
335 | } |
||
336 | 42464 | fdiaz | |
337 | /* (non-Javadoc)
|
||
338 | * @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#reProject(org.cresques.cts.ICoordTrans)
|
||
339 | */
|
||
340 | @Override
|
||
341 | public void reProject(ICoordTrans ct) { |
||
342 | super.reProject(ct);
|
||
343 | for (Iterator<Ring> iterator = interiorRings.iterator(); iterator.hasNext();) { |
||
344 | GeometryJTS ring = (GeometryJTS) iterator.next(); |
||
345 | ring.reProject(ct); |
||
346 | } |
||
347 | if (coordinates.size()>=2 && !isClosed()) { |
||
348 | closePrimitive(); |
||
349 | } |
||
350 | } |
||
351 | 42875 | fdiaz | |
352 | @Override
|
||
353 | public boolean equals(Object obj) { |
||
354 | boolean res = super.equals(obj); |
||
355 | if(res && obj instanceof Polygon3DM){ |
||
356 | Polygon3DM other = (Polygon3DM)obj; |
||
357 | if(this.getNumVertices() != other.getNumVertices()){ |
||
358 | return false; |
||
359 | } |
||
360 | for (int i = 0; i < this.getNumVertices(); i++) { |
||
361 | Coordinate coordinate = this.coordinates.get(i);
|
||
362 | Coordinate otherCoordinate = other.coordinates.get(i); |
||
363 | 47432 | fdiaz | if (otherCoordinate.getOrdinate(CoordinateSequence.Z) != coordinate.getOrdinate(CoordinateSequence.Z)) {
|
364 | 42875 | fdiaz | return false; |
365 | } |
||
366 | 47432 | fdiaz | if (otherCoordinate.getOrdinate(CoordinateSequence.M) != coordinate.getOrdinate(CoordinateSequence.M)) {
|
367 | 42875 | fdiaz | return false; |
368 | } |
||
369 | } |
||
370 | if(this.getNumInteriorRings() != other.getNumInteriorRings()){ |
||
371 | return false; |
||
372 | } |
||
373 | for(int i=0; i < this.getNumInteriorRings(); i++){ |
||
374 | if(!other.getInteriorRing(i).equals(this.getInteriorRing(i))){ |
||
375 | return false; |
||
376 | } |
||
377 | } |
||
378 | return true; |
||
379 | } else {
|
||
380 | return false; |
||
381 | } |
||
382 | } |
||
383 | 43244 | jjdelcerro | @Override
|
384 | public Shape getShape(AffineTransform affineTransform) { |
||
385 | return PolygonHelper.getShape(this, affineTransform); |
||
386 | } |
||
387 | 46332 | fdiaz | |
388 | @Override
|
||
389 | public Geometry split(Geometry splitter) {
|
||
390 | SurfaceSplitOperation op = new SurfaceSplitOperation();
|
||
391 | return op.split(this, splitter); |
||
392 | } |
||
393 | 46979 | jjdelcerro | |
394 | @Override
|
||
395 | public Ring createRing() {
|
||
396 | return new Ring3DM(); |
||
397 | } |
||
398 | 42269 | fdiaz | } |