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