root / tags / v1_0_2_Build_916 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / core / ShapeFactory.java @ 12327
History | View | Annotate | Download (6.01 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*
|
19 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ib??ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.fmap.core; |
42 |
|
43 |
import java.awt.geom.AffineTransform; |
44 |
import java.awt.geom.Arc2D; |
45 |
import java.awt.geom.Point2D; |
46 |
|
47 |
import com.iver.cit.gvsig.fmap.core.gt2.FLiteShape; |
48 |
import com.iver.cit.gvsig.fmap.edition.UtilFunctions; |
49 |
|
50 |
|
51 |
/**
|
52 |
* Clase que crea las geometr?as, contendra un m?todo create por cada tipo de
|
53 |
* geometria que soporte gvSIG
|
54 |
*/
|
55 |
public class ShapeFactory { |
56 |
/**
|
57 |
* Crea una geometr?a que contiene como shape un punto 2D.
|
58 |
*
|
59 |
* @param x Coordenada x.
|
60 |
* @param y Coordenada y.
|
61 |
*
|
62 |
* @return Geometr?a.
|
63 |
*/
|
64 |
public static IGeometry createPoint2D(double x, double y) { |
65 |
return new FGeometry(new FPoint2D(x, y)); |
66 |
} |
67 |
public static IGeometry createPoint2D(FPoint2D p) { |
68 |
return new FGeometry(p); |
69 |
} |
70 |
|
71 |
|
72 |
/**
|
73 |
* Crea una geometr?a que contiene como shape un Multipunto 2D.
|
74 |
*
|
75 |
* @param x Coordenada x.
|
76 |
* @param y Coordenada y.
|
77 |
*
|
78 |
* @return Geometr?a.
|
79 |
*/
|
80 |
public static IGeometry createMultipoint2D(double[] x, double[] y) { |
81 |
return new FMultiPoint2D(x, y); |
82 |
} |
83 |
|
84 |
/**
|
85 |
* Crea una geometr?a que contiene como shape un punto 3D.
|
86 |
*
|
87 |
* @param x Coordenada x.
|
88 |
* @param y Coordenada y.
|
89 |
* @param z Coordenada z.
|
90 |
*
|
91 |
* @return Geometr?a.
|
92 |
*/
|
93 |
public static IGeometry createPoint3D(double x, double y, double z) { |
94 |
return new FGeometry(new FPoint3D(x, y, z)); |
95 |
} |
96 |
|
97 |
/**
|
98 |
* Crea una geometr?a que contiene como shape un Multipunto 3D.
|
99 |
*
|
100 |
* @param x Coordenada x.
|
101 |
* @param y Coordenada y.
|
102 |
* @param z Coordenada z.
|
103 |
*
|
104 |
* @return Geometr?a.
|
105 |
*/
|
106 |
public static IGeometry createMultipoint3D(double[] x, double[] y, |
107 |
double[] z) { |
108 |
return new FMultipoint3D(x, y, z); |
109 |
} |
110 |
|
111 |
/**
|
112 |
* Crea una geometr?a que contiene como shape un Polil?nea 2D.
|
113 |
*
|
114 |
* @param shape GeneralPathX.
|
115 |
*
|
116 |
* @return Geometr?a.
|
117 |
*/
|
118 |
public static IGeometry createPolyline2D(GeneralPathX shape) { |
119 |
return new FGeometry(new FPolyline2D(shape)); |
120 |
} |
121 |
|
122 |
/**
|
123 |
* Crea una geometr?a que contiene como shape un Polil?nea 3D.
|
124 |
*
|
125 |
* @param shape GeneralPathX.
|
126 |
* @param pZ Vector de Z.
|
127 |
*
|
128 |
* @return Geometr?a.
|
129 |
*/
|
130 |
public static IGeometry createPolyline3D(GeneralPathX shape, double[] pZ) { |
131 |
return new FGeometry(new FPolyline3D(shape, pZ)); |
132 |
} |
133 |
/**
|
134 |
* Crea una geometr?a que contiene como shape un Pol?gono 3D.
|
135 |
*
|
136 |
* @param shape GeneralPathX.
|
137 |
* @param pZ Vector de Z.
|
138 |
*
|
139 |
* @return Geometr?a.
|
140 |
*/
|
141 |
public static IGeometry createPolygon3D(GeneralPathX shape, double[] pZ) { |
142 |
return new FGeometry(new FPolygon3D(shape, pZ)); |
143 |
} |
144 |
|
145 |
/**
|
146 |
* Crea una geometr?a que contiene como shape un Pol?gono 2D.
|
147 |
*
|
148 |
* @param shape GeneralPathX.
|
149 |
*
|
150 |
* @return Geometr?a.
|
151 |
*/
|
152 |
public static IGeometry createPolygon2D(GeneralPathX shape) { |
153 |
return new FGeometry(new FPolygon2D(shape)); |
154 |
} |
155 |
|
156 |
/**
|
157 |
* Crea una geometr?a que contiene como shape un Pol?gono 2D.
|
158 |
*
|
159 |
* @param shape FPolyline2D closed (you must be sure it is really closed).
|
160 |
*
|
161 |
* @return Geometr?a.
|
162 |
*/
|
163 |
public static IGeometry createPolygon2D(FPolyline2D shape) { |
164 |
return new FGeometry(new FPolygon2D(shape.gp)); |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Crea a partir de un FShape una geometr?a.
|
169 |
*
|
170 |
* @param shp FShape.
|
171 |
*
|
172 |
* @return Geometr?a.
|
173 |
*/
|
174 |
public static FGeometry createGeometry(FShape shp) { |
175 |
return new FGeometry(shp); |
176 |
} |
177 |
|
178 |
public static IGeometry createGeometry(FLiteShape gt2geometry) { |
179 |
return new Gt2Geometry(gt2geometry); |
180 |
} |
181 |
public static IGeometry createCircle(Point2D center, Point2D r){ |
182 |
double radio = center.distance(r);
|
183 |
return createCircle(center, radio);
|
184 |
} |
185 |
|
186 |
public static IGeometry createCircle(Point2D center, double radio){ |
187 |
Arc2D.Double arc = new Arc2D.Double(center.getX()-radio, center.getY() - radio, |
188 |
2 * radio, 2 * radio, 0, 360, Arc2D.OPEN); |
189 |
|
190 |
return new FGeometry(new FCircle2D(new GeneralPathX(arc),center,radio)); |
191 |
} |
192 |
public static IGeometry createCircle(Point2D p1, Point2D p2, Point2D p3){ |
193 |
Point2D center = UtilFunctions.getCenter(p1, p2, p3);
|
194 |
if (center!=null) |
195 |
return createCircle(center,p1);
|
196 |
return null; |
197 |
} |
198 |
public static IGeometry createArc(Point2D p1, Point2D p2, Point2D p3){ |
199 |
Arc2D arco = UtilFunctions.createArc(p1, p2, p3);
|
200 |
if (arco == null) return null; |
201 |
FArc2D arc=new FArc2D(new GeneralPathX(arco),p1,p2,p3); |
202 |
IGeometry geom=new FGeometry(arc);
|
203 |
return geom;
|
204 |
} |
205 |
public static IGeometry createEllipse(Point2D axis1Start, Point2D axis1End, double axis2Length){ |
206 |
double xAxis = axis1Start.distance(axis1End);
|
207 |
Arc2D.Double arc = new Arc2D.Double(axis1Start.getX(), |
208 |
axis1Start.getY() - axis2Length, xAxis, 2 * axis2Length, 0, 360, Arc2D.OPEN); |
209 |
Point2D rotationPoint = new Point2D.Double(axis1Start.getX() + xAxis /2, axis1Start.getY()); |
210 |
double angle = UtilFunctions.getAngle(axis1Start, axis1End);
|
211 |
AffineTransform mT = AffineTransform.getRotateInstance(angle, axis1Start.getX(), axis1Start.getY()); |
212 |
GeneralPathX gp = new GeneralPathX(arc);
|
213 |
gp.transform(mT); |
214 |
|
215 |
return new FGeometry(new FEllipse2D(new GeneralPathX(gp),axis1Start,axis1End,axis2Length)); |
216 |
} |
217 |
} |