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