Revision 21049 branches/v2_0_0_prep/libraries/libFMap_geometries/src/org/gvsig/fmap/geom/GeometryFactory.java
GeometryFactory.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
|
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
|
2 | 2 |
* |
3 | 3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
4 | 4 |
* |
... | ... | |
20 | 20 |
* |
21 | 21 |
* Generalitat Valenciana |
22 | 22 |
* Conselleria d'Infraestructures i Transport |
23 |
* Av. Blasco Ib��ez, 50
|
|
23 |
* Av. Blasco Ib??ez, 50
|
|
24 | 24 |
* 46010 VALENCIA |
25 | 25 |
* SPAIN |
26 | 26 |
* |
... | ... | |
60 | 60 |
import org.gvsig.fmap.geom.primitive.Surface3D; |
61 | 61 |
import org.gvsig.fmap.geom.util.UtilFunctions; |
62 | 62 |
|
63 |
|
|
64 |
|
|
65 |
|
|
66 | 63 |
/** |
67 |
* Clase que crea las geometr�as, contendra un m�todo create por cada tipo de
|
|
64 |
* Clase que crea las geometr?as, contendra un m?todo create por cada tipo de
|
|
68 | 65 |
* geometria que soporte gvSIG |
69 | 66 |
*/ |
70 | 67 |
public class GeometryFactory { |
71 |
|
|
68 |
|
|
72 | 69 |
/** |
73 |
* Crea una geometr�a que contiene como shape un punto 2D. |
|
74 |
* |
|
75 |
* @param x Coordenada x. |
|
76 |
* @param y Coordenada y. |
|
77 |
* |
|
78 |
* @return Geometr�a. |
|
70 |
* Crea una geometr?a que contiene como shape un punto 2D. |
|
71 |
* |
|
72 |
* @param x |
|
73 |
* Coordenada x. |
|
74 |
* @param y |
|
75 |
* Coordenada y. |
|
76 |
* |
|
77 |
* @return Geometr?a. |
|
79 | 78 |
*/ |
80 |
public static Geometry createPoint2D(double x, double y) {
|
|
79 |
public Geometry createPoint2D(double x, double y) { |
|
81 | 80 |
return new org.gvsig.fmap.geom.primitive.Point2D(null, null, x, y); |
82 | 81 |
} |
83 |
|
|
84 |
public static Geometry createPoint2D(org.gvsig.fmap.geom.primitive.Point2D p) {
|
|
82 |
|
|
83 |
public Geometry createPoint2D(org.gvsig.fmap.geom.primitive.Point2D p) { |
|
85 | 84 |
return p; |
86 | 85 |
} |
87 | 86 |
|
88 |
|
|
89 | 87 |
/** |
90 |
* Crea una geometr�a que contiene como shape un Multipunto 2D. |
|
91 |
* |
|
92 |
* @param x Coordenada x. |
|
93 |
* @param y Coordenada y. |
|
94 |
* |
|
95 |
* @return Geometr�a. |
|
88 |
* Crea una geometr?a que contiene como shape un Multipunto 2D. |
|
89 |
* |
|
90 |
* @param x |
|
91 |
* Coordenada x. |
|
92 |
* @param y |
|
93 |
* Coordenada y. |
|
94 |
* |
|
95 |
* @return Geometr?a. |
|
96 | 96 |
*/ |
97 |
public static Geometry createMultipoint2D(double[] x, double[] y) {
|
|
97 |
public Geometry createMultipoint2D(double[] x, double[] y) { |
|
98 | 98 |
return new MultiPoint2D(null, null, x, y); |
99 | 99 |
} |
100 | 100 |
|
101 | 101 |
/** |
102 |
* Crea una geometr�a que contiene como shape un punto 3D. |
|
103 |
* |
|
104 |
* @param x Coordenada x. |
|
105 |
* @param y Coordenada y. |
|
106 |
* @param z Coordenada z. |
|
107 |
* |
|
108 |
* @return Geometr�a. |
|
102 |
* Crea una geometr?a que contiene como shape un punto 3D. |
|
103 |
* |
|
104 |
* @param x |
|
105 |
* Coordenada x. |
|
106 |
* @param y |
|
107 |
* Coordenada y. |
|
108 |
* @param z |
|
109 |
* Coordenada z. |
|
110 |
* |
|
111 |
* @return Geometr?a. |
|
109 | 112 |
*/ |
110 |
public static Geometry createPoint3D(double x, double y, double z) {
|
|
113 |
public Geometry createPoint3D(double x, double y, double z) { |
|
111 | 114 |
return new Point3D(null, null, x, y, z); |
112 | 115 |
} |
113 | 116 |
|
114 | 117 |
/** |
115 |
* Crea una geometr�a que contiene como shape un Multipunto 3D. |
|
116 |
* |
|
117 |
* @param x Coordenada x. |
|
118 |
* @param y Coordenada y. |
|
119 |
* @param z Coordenada z. |
|
120 |
* |
|
121 |
* @return Geometr�a. |
|
118 |
* Crea una geometr?a que contiene como shape un Multipunto 3D. |
|
119 |
* |
|
120 |
* @param x |
|
121 |
* Coordenada x. |
|
122 |
* @param y |
|
123 |
* Coordenada y. |
|
124 |
* @param z |
|
125 |
* Coordenada z. |
|
126 |
* |
|
127 |
* @return Geometr?a. |
|
122 | 128 |
*/ |
123 |
public static Geometry createMultipoint3D(double[] x, double[] y, |
|
124 |
double[] z) { |
|
129 |
public Geometry createMultipoint3D(double[] x, double[] y, double[] z) { |
|
125 | 130 |
return new MultiPoint3D(null, null, x, y, z); |
126 | 131 |
} |
127 | 132 |
|
128 | 133 |
/** |
129 |
* Crea una geometr�a que contiene como shape un Polil�nea 2D. |
|
130 |
* |
|
131 |
* @param shape GeneralPathX. |
|
132 |
* |
|
133 |
* @return Geometr�a. |
|
134 |
* Crea una geometr?a que contiene como shape un Polil?nea 2D. |
|
135 |
* |
|
136 |
* @param shape |
|
137 |
* GeneralPathX. |
|
138 |
* |
|
139 |
* @return Geometr?a. |
|
134 | 140 |
*/ |
135 |
public static Geometry createPolyline2D(GeneralPathX shape) {
|
|
141 |
public Geometry createPolyline2D(GeneralPathX shape) { |
|
136 | 142 |
return new Curve2D(null, null, shape); |
137 | 143 |
} |
138 | 144 |
|
139 | 145 |
/** |
140 |
* Crea una geometr�a que contiene como shape un Polil�nea 3D. |
|
141 |
* |
|
142 |
* @param shape GeneralPathX. |
|
143 |
* @param pZ Vector de Z. |
|
144 |
* |
|
145 |
* @return Geometr�a. |
|
146 |
* Crea una geometr?a que contiene como shape un Polil?nea 3D. |
|
147 |
* |
|
148 |
* @param shape |
|
149 |
* GeneralPathX. |
|
150 |
* @param pZ |
|
151 |
* Vector de Z. |
|
152 |
* |
|
153 |
* @return Geometr?a. |
|
146 | 154 |
*/ |
147 |
public static Geometry createPolyline3D(GeneralPathX shape, double[] pZ) {
|
|
155 |
public Geometry createPolyline3D(GeneralPathX shape, double[] pZ) { |
|
148 | 156 |
return new Curve3D(null, null, shape, pZ); |
149 | 157 |
} |
150 |
|
|
158 |
|
|
151 | 159 |
/** |
152 | 160 |
* Creates a multiline form a set of lines |
161 |
* |
|
153 | 162 |
* @param polylines |
154 |
* The lines |
|
155 |
* @return |
|
156 |
* A multiline |
|
163 |
* The lines |
|
164 |
* @return A multiline |
|
157 | 165 |
*/ |
158 |
public static Geometry createMultiPolyline(Curve2D[] polylines) {
|
|
166 |
public Geometry createMultiPolyline(Curve2D[] polylines) { |
|
159 | 167 |
return new MultiCurve2D(null, null, polylines); |
160 | 168 |
} |
161 |
|
|
169 |
|
|
162 | 170 |
/** |
163 | 171 |
* Creates a multiline form a set of lines |
172 |
* |
|
164 | 173 |
* @param polylines |
165 |
* The lines |
|
166 |
* @return |
|
167 |
* A multiline |
|
174 |
* The lines |
|
175 |
* @return A multiline |
|
168 | 176 |
*/ |
169 |
public static Geometry createMultiPolygon(Surface2D[] polygons) {
|
|
177 |
public Geometry createMultiPolygon(Surface2D[] polygons) { |
|
170 | 178 |
return new MultiSurface2D(null, null, polygons); |
171 | 179 |
} |
172 |
|
|
180 |
|
|
173 | 181 |
/** |
174 | 182 |
* Creates a multigeometry form a set of geometries |
183 |
* |
|
175 | 184 |
* @param geometries |
176 |
* The geometries |
|
177 |
* @return |
|
178 |
* A multigeometry |
|
185 |
* The geometries |
|
186 |
* @return A multigeometry |
|
179 | 187 |
*/ |
180 |
public static Geometry createMultiGeometry(Geometry[] geometries) {
|
|
188 |
public Geometry createMultiGeometry(Geometry[] geometries) { |
|
181 | 189 |
return new BaseMultiPrimitive(null, null, geometries); |
182 | 190 |
} |
183 |
|
|
191 |
|
|
184 | 192 |
/** |
185 |
* Crea una geometr�a que contiene como shape un Pol�gono 3D. |
|
186 |
* |
|
187 |
* @param shape GeneralPathX. |
|
188 |
* @param pZ Vector de Z. |
|
189 |
* |
|
190 |
* @return Geometr�a. |
|
193 |
* Crea una geometr?a que contiene como shape un Pol?gono 3D. |
|
194 |
* |
|
195 |
* @param shape |
|
196 |
* GeneralPathX. |
|
197 |
* @param pZ |
|
198 |
* Vector de Z. |
|
199 |
* |
|
200 |
* @return Geometr?a. |
|
191 | 201 |
*/ |
192 |
public static Geometry createPolygon3D(GeneralPathX shape, double[] pZ) {
|
|
202 |
public Geometry createPolygon3D(GeneralPathX shape, double[] pZ) { |
|
193 | 203 |
return new Surface3D(null, null, shape, pZ); |
194 | 204 |
} |
195 | 205 |
|
196 | 206 |
/** |
197 |
* Crea una geometr�a que contiene como shape un Pol�gono 2D. |
|
198 |
* |
|
199 |
* @param shape GeneralPathX. |
|
200 |
* |
|
201 |
* @return Geometr�a. |
|
207 |
* Crea una geometr?a que contiene como shape un Pol?gono 2D. |
|
208 |
* |
|
209 |
* @param shape |
|
210 |
* GeneralPathX. |
|
211 |
* |
|
212 |
* @return Geometr?a. |
|
202 | 213 |
*/ |
203 |
public static Geometry createPolygon2D(GeneralPathX shape) {
|
|
214 |
public Geometry createPolygon2D(GeneralPathX shape) { |
|
204 | 215 |
return new Surface2D(null, null, shape); |
205 | 216 |
} |
206 | 217 |
|
207 | 218 |
/** |
208 |
* Crea una geometr�a que contiene como shape un Pol�gono 2D. |
|
209 |
* |
|
210 |
* @param shape FPolyline2D closed (you must be sure it is really closed). |
|
211 |
* |
|
212 |
* @return Geometr�a. |
|
219 |
* Crea una geometr?a que contiene como shape un Pol?gono 2D. |
|
220 |
* |
|
221 |
* @param shape |
|
222 |
* FPolyline2D closed (you must be sure it is really closed). |
|
223 |
* |
|
224 |
* @return Geometr?a. |
|
213 | 225 |
*/ |
214 |
public static Geometry createPolygon2D(Curve2D shape) {
|
|
226 |
public Geometry createPolygon2D(Curve2D shape) { |
|
215 | 227 |
return new Surface2D(null, null, shape.getGeneralPathX()); |
216 | 228 |
} |
217 | 229 |
|
218 | 230 |
/** |
219 |
* Crea a partir de un FShape una geometr�a. |
|
220 |
* |
|
221 |
* @param shp FShape. |
|
222 |
* |
|
223 |
* @return Geometr�a. |
|
231 |
* Crea a partir de un FShape una geometr?a. |
|
232 |
* |
|
233 |
* @param shp |
|
234 |
* FShape. |
|
235 |
* |
|
236 |
* @return Geometr?a. |
|
224 | 237 |
*/ |
225 |
public static Geometry createGeometry(FShape shp) {
|
|
238 |
public Geometry createGeometry(FShape shp) { |
|
226 | 239 |
return (Geometry) shp; |
227 | 240 |
} |
228 |
|
|
229 |
public static Geometry createCircle(java.awt.geom.Point2D center, java.awt.geom.Point2D r){ |
|
241 |
|
|
242 |
public Geometry createCircle(java.awt.geom.Point2D center, |
|
243 |
java.awt.geom.Point2D r) { |
|
230 | 244 |
double radio = center.distance(r); |
231 | 245 |
return createCircle(center, radio); |
232 | 246 |
} |
233 | 247 |
|
234 |
public static Geometry createCircle(Point2D center, double radio){ |
|
235 |
Arc2D.Double arc = new Arc2D.Double(center.getX()-radio, center.getY() - radio, |
|
236 |
2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
|
248 |
public Geometry createCircle(Point2D center, double radio) { |
|
249 |
Arc2D.Double arc = new Arc2D.Double(center.getX() - radio, center |
|
250 |
.getY() |
|
251 |
- radio, 2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
|
237 | 252 |
|
238 |
return new Circle2D(null, null, new GeneralPathX(arc),center,radio);
|
|
253 |
return new Circle2D(null, null, new GeneralPathX(arc), center, radio);
|
|
239 | 254 |
} |
240 |
public static Geometry createCircle(Point2D p1, Point2D p2, Point2D p3){ |
|
255 |
|
|
256 |
public Geometry createCircle(Point2D p1, Point2D p2, Point2D p3) { |
|
241 | 257 |
Point2D center = UtilFunctions.getCenter(p1, p2, p3); |
242 |
if (center!=null)
|
|
243 |
return createCircle(center,p1);
|
|
258 |
if (center != null)
|
|
259 |
return createCircle(center, p1);
|
|
244 | 260 |
return null; |
245 | 261 |
} |
246 |
|
|
247 |
public static Geometry createArc(Point2D p1, Point2D p2, Point2D p3){
|
|
262 |
|
|
263 |
public Geometry createArc(Point2D p1, Point2D p2, Point2D p3) {
|
|
248 | 264 |
Arc2D arco = UtilFunctions.createArc(p1, p2, p3); |
249 |
if (arco == null) return null; |
|
250 |
return new org.gvsig.fmap.geom.primitive.Arc2D(null, null, new GeneralPathX(arco),p1,p2,p3); |
|
265 |
if (arco == null) |
|
266 |
return null; |
|
267 |
return new org.gvsig.fmap.geom.primitive.Arc2D(null, null, |
|
268 |
new GeneralPathX(arco), p1, p2, p3); |
|
251 | 269 |
} |
252 |
|
|
253 |
public static Geometry createEllipse(Point2D axis1Start, Point2D axis1End, double axis2Length){ |
|
270 |
|
|
271 |
public Geometry createEllipse(Point2D axis1Start, Point2D axis1End, |
|
272 |
double axis2Length) { |
|
254 | 273 |
double xAxis = axis1Start.distance(axis1End); |
255 |
Arc2D.Double arc = new Arc2D.Double(axis1Start.getX(), |
|
256 |
axis1Start.getY() - axis2Length, xAxis, 2 * axis2Length, 0, 360, Arc2D.OPEN); |
|
257 |
// TODO Línea comentada para quitar warning: Point2D rotationPoint = new Point2D.Double(axis1Start.getX() + xAxis /2, axis1Start.getY()); |
|
274 |
Arc2D.Double arc = new Arc2D.Double(axis1Start.getX(), axis1Start |
|
275 |
.getY() |
|
276 |
- axis2Length, xAxis, 2 * axis2Length, 0, 360, Arc2D.OPEN); |
|
277 |
// TODO L?nea comentada para quitar warning: Point2D rotationPoint = new |
|
278 |
// Point2D.Double(axis1Start.getX() + xAxis /2, axis1Start.getY()); |
|
258 | 279 |
double angle = UtilFunctions.getAngle(axis1Start, axis1End); |
259 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, axis1Start.getX(), axis1Start.getY()); |
|
280 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, |
|
281 |
axis1Start.getX(), axis1Start.getY()); |
|
260 | 282 |
GeneralPathX gp = new GeneralPathX(arc); |
261 | 283 |
gp.transform(mT); |
262 | 284 |
|
263 |
return new org.gvsig.fmap.geom.primitive.Ellipse2D(null, null, new GeneralPathX(gp),axis1Start,axis1End,axis2Length); |
|
285 |
return new org.gvsig.fmap.geom.primitive.Ellipse2D(null, null, |
|
286 |
new GeneralPathX(gp), axis1Start, axis1End, axis2Length); |
|
264 | 287 |
} |
265 |
public static Geometry createSpline2D(Point2D[] points) { |
|
288 |
|
|
289 |
public Geometry createSpline2D(Point2D[] points) { |
|
266 | 290 |
return new Spline2D(null, null, points); |
267 | 291 |
} |
268 | 292 |
} |
Also available in: Unified diff