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 / ring / Ring3D.java @ 47432
History | View | Annotate | Download (8.3 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.ring; |
24 |
|
25 |
import com.vividsolutions.jts.geom.Coordinate; |
26 |
import com.vividsolutions.jts.geom.GeometryFactory; |
27 |
import com.vividsolutions.jts.geom.LinearRing; |
28 |
import com.vividsolutions.jts.geomgraph.Position; |
29 |
import com.vividsolutions.jts.operation.buffer.BufferParameters; |
30 |
import com.vividsolutions.jts.operation.buffer.OffsetCurveBuilder; |
31 |
import org.cresques.cts.ICoordTrans; |
32 |
import org.gvsig.fmap.geom.Geometry; |
33 |
import org.gvsig.fmap.geom.GeometryException; |
34 |
import org.gvsig.fmap.geom.aggregate.MultiLine; |
35 |
import org.gvsig.fmap.geom.aggregate.MultiPolygon; |
36 |
import org.gvsig.fmap.geom.jts.aggregate.MultiLine3D; |
37 |
import org.gvsig.fmap.geom.jts.aggregate.MultiPolygon2D; |
38 |
import org.gvsig.fmap.geom.jts.mgeom.MCoordinate; |
39 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.BaseLine3D; |
40 |
import org.gvsig.fmap.geom.jts.primitive.curve.line.Line3D; |
41 |
import org.gvsig.fmap.geom.jts.primitive.surface.polygon.Polygon3D; |
42 |
import org.gvsig.fmap.geom.jts.util.ArrayListCoordinateSequence; |
43 |
import org.gvsig.fmap.geom.jts.util.JTSUtils; |
44 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
45 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
46 |
import org.gvsig.fmap.geom.primitive.Ring; |
47 |
|
48 |
|
49 |
/**
|
50 |
* @author fdiaz
|
51 |
*
|
52 |
*/
|
53 |
public class Ring3D extends BaseLine3D implements Ring { |
54 |
|
55 |
/**
|
56 |
*
|
57 |
*/
|
58 |
private static final long serialVersionUID = 9116088317343114306L; |
59 |
|
60 |
/**
|
61 |
*/
|
62 |
public Ring3D() {
|
63 |
super(Geometry.TYPES.RING);
|
64 |
} |
65 |
|
66 |
/**
|
67 |
* @param coordinates
|
68 |
*/
|
69 |
public Ring3D(Coordinate[] coordinates) { |
70 |
super(Geometry.TYPES.RING, coordinates);
|
71 |
closePrimitive(); |
72 |
} |
73 |
|
74 |
public Ring3D(ArrayListCoordinateSequence coordinates) {
|
75 |
super(Geometry.TYPES.RING, coordinates);
|
76 |
} |
77 |
|
78 |
/* (non-Javadoc)
|
79 |
* @see org.gvsig.fmap.geom.Geometry#cloneGeometry()
|
80 |
*/
|
81 |
@Override
|
82 |
public Geometry cloneGeometry() {
|
83 |
Ring3D clone = new Ring3D(cloneCoordinates().toCoordinateArray());
|
84 |
clone.setProjection(this.getProjection());
|
85 |
return clone;
|
86 |
} |
87 |
|
88 |
|
89 |
/* (non-Javadoc)
|
90 |
* @see org.gvsig.fmap.geom.primitive.Line#toLines()
|
91 |
*/
|
92 |
public MultiLine toLines() throws GeometryException { |
93 |
MultiLine multiLine = new MultiLine3D();
|
94 |
multiLine.addPrimitive(new Line3D(coordinates.toCoordinateArray()));
|
95 |
return multiLine;
|
96 |
} |
97 |
|
98 |
/* (non-Javadoc)
|
99 |
* @see org.gvsig.fmap.geom.primitive.Line#toPolygons()
|
100 |
*/
|
101 |
public MultiPolygon toPolygons() throws GeometryException { |
102 |
MultiPolygon multiPolygon = new MultiPolygon2D();
|
103 |
multiPolygon.addPrimitive(new Polygon3D(coordinates.toCoordinateArray()));
|
104 |
return multiPolygon;
|
105 |
} |
106 |
|
107 |
/*
|
108 |
* (non-Javadoc)
|
109 |
*
|
110 |
* @see org.gvsig.fmap.geom.jts.GeometryJTS#getJTS()
|
111 |
*/
|
112 |
public com.vividsolutions.jts.geom.Geometry getJTS() {
|
113 |
return JTSUtils.createJTSLinearRing(coordinates);
|
114 |
} |
115 |
|
116 |
/* (non-Javadoc)
|
117 |
* @see org.gvsig.fmap.geom.Geometry#offset(double)
|
118 |
*/
|
119 |
public Geometry offset(double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
120 |
com.vividsolutions.jts.geom.LinearRing jtsRing = (LinearRing) getJTS(); |
121 |
GeometryFactory factory = jtsRing.getFactory(); |
122 |
BufferParameters bufParams = JTSUtils.getBufferParameters(); |
123 |
|
124 |
OffsetCurveBuilder ocb = new OffsetCurveBuilder(factory.getPrecisionModel(), bufParams);
|
125 |
|
126 |
Coordinate[] coordinates = jtsRing.getCoordinates();
|
127 |
Coordinate[] coords = ocb.getRingCurve(coordinates, Position.LEFT, distance); // .getOffsetCurve(coordinates, |
128 |
|
129 |
return new Ring3D(coords); |
130 |
} |
131 |
|
132 |
public Geometry offset(int joinStyle, double distance) throws GeometryOperationNotSupportedException, GeometryOperationException { |
133 |
com.vividsolutions.jts.geom.LinearRing jtsRing = (LinearRing) getJTS(); |
134 |
GeometryFactory factory = jtsRing.getFactory(); |
135 |
BufferParameters bufParams = JTSUtils.getBufferParameters(joinStyle, BufferParameters.CAP_FLAT); |
136 |
|
137 |
OffsetCurveBuilder ocb = new OffsetCurveBuilder(factory.getPrecisionModel(), bufParams);
|
138 |
|
139 |
Coordinate[] coordinates = jtsRing.getCoordinates();
|
140 |
Coordinate[] coords = ocb.getRingCurve(coordinates, Position.LEFT, distance); // .getOffsetCurve(coordinates, |
141 |
|
142 |
return new Ring3D(coords); |
143 |
} |
144 |
|
145 |
|
146 |
/* (non-Javadoc)
|
147 |
* @see org.gvsig.fmap.geom.jts.primitive.curve.line.AbstractLine#reProject(org.cresques.cts.ICoordTrans)
|
148 |
*/
|
149 |
@Override
|
150 |
public void reProject(ICoordTrans ct) { |
151 |
super.reProject(ct);
|
152 |
if (coordinates.size()>=2 && !isClosed()) { |
153 |
closePrimitive(); |
154 |
} |
155 |
} |
156 |
|
157 |
@Override
|
158 |
public boolean equals(Object obj) { |
159 |
boolean res = super.equals(obj); |
160 |
if(res && obj instanceof Ring3D){ |
161 |
Ring3D other = (Ring3D)obj; |
162 |
if(this.getNumVertices() != other.getNumVertices()){ |
163 |
return false; |
164 |
} |
165 |
for(int i=0; i < this.getNumVertices(); i++){ |
166 |
Coordinate coordinate = this.coordinates.get(i);
|
167 |
Coordinate otherCoordinate = other.coordinates.get(i); |
168 |
if (otherCoordinate.getOrdinate(2) != coordinate.getOrdinate(2)) { |
169 |
return false; |
170 |
} |
171 |
} |
172 |
return true; |
173 |
} else {
|
174 |
return false; |
175 |
} |
176 |
} |
177 |
|
178 |
@Override
|
179 |
public Geometry force2D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
180 |
ArrayListCoordinateSequence coordinates2D = new ArrayListCoordinateSequence(coordinates.size());
|
181 |
for (Coordinate coordinate : this.coordinates) { |
182 |
coordinates2D.add(new Coordinate(coordinate.x, coordinate.y));
|
183 |
} |
184 |
Ring2D ring = new Ring2D(coordinates2D);
|
185 |
ring.setProjection(this.getProjection());
|
186 |
return ring;
|
187 |
} |
188 |
|
189 |
@Override
|
190 |
public Geometry force2DM() throws GeometryOperationNotSupportedException, GeometryOperationException { |
191 |
ArrayListCoordinateSequence coordinates2DM = new ArrayListCoordinateSequence(coordinates.size());
|
192 |
for (Coordinate coordinate : this.coordinates) { |
193 |
coordinates2DM.add(MCoordinate.create2dWithMeasure(coordinate.x, coordinate.y, 0));
|
194 |
} |
195 |
Ring2DM ring = new Ring2DM(coordinates2DM);
|
196 |
ring.setProjection(this.getProjection());
|
197 |
return ring;
|
198 |
} |
199 |
|
200 |
@Override
|
201 |
public Geometry force3D() throws GeometryOperationNotSupportedException, GeometryOperationException { |
202 |
ArrayListCoordinateSequence coordinates3D = new ArrayListCoordinateSequence(coordinates.size());
|
203 |
for (Coordinate coordinate : this.coordinates) { |
204 |
coordinates3D.add(new Coordinate(coordinate.x, coordinate.y, 0)); |
205 |
} |
206 |
Ring3D ring = new Ring3D(coordinates3D);
|
207 |
ring.setProjection(this.getProjection());
|
208 |
return ring;
|
209 |
} |
210 |
|
211 |
@Override
|
212 |
public Geometry force3DM() throws GeometryOperationNotSupportedException, GeometryOperationException { |
213 |
ArrayListCoordinateSequence coordinates3DM = new ArrayListCoordinateSequence(coordinates.size());
|
214 |
for (Coordinate coordinate : this.coordinates) { |
215 |
coordinates3DM.add(MCoordinate.create3dWithMeasure(coordinate.x, coordinate.y, 0, 0)); |
216 |
} |
217 |
Ring3DM ring = new Ring3DM(coordinates3DM);
|
218 |
ring.setProjection(this.getProjection());
|
219 |
return ring;
|
220 |
} |
221 |
|
222 |
} |