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