svn-gvsig-desktop / tags / Root_FMap_piloto_CAD_Layout_version / libraries / libFMap / src / com / iver / cit / gvsig / fmap / drivers / dxf / DXFDriver.java @ 1664
History | View | Annotate | Download (9.39 KB)
1 |
/*
|
---|---|
2 |
* @(#)DXFDriver 13-dic-2004
|
3 |
*
|
4 |
* @author jmorell (jose.morell@gmail.com)
|
5 |
*/
|
6 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
7 |
*
|
8 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
9 |
*
|
10 |
* This program is free software; you can redistribute it and/or
|
11 |
* modify it under the terms of the GNU General Public License
|
12 |
* as published by the Free Software Foundation; either version 2
|
13 |
* of the License, or (at your option) any later version.
|
14 |
*
|
15 |
* This program is distributed in the hope that it will be useful,
|
16 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
17 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
18 |
* GNU General Public License for more details.
|
19 |
*
|
20 |
* You should have received a copy of the GNU General Public License
|
21 |
* along with this program; if not, write to the Free Software
|
22 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
23 |
*
|
24 |
* For more information, contact:
|
25 |
*
|
26 |
* Generalitat Valenciana
|
27 |
* Conselleria d'Infraestructures i Transport
|
28 |
* Av. Blasco Ib??ez, 50
|
29 |
* 46010 VALENCIA
|
30 |
* SPAIN
|
31 |
*
|
32 |
* +34 963862235
|
33 |
* gvsig@gva.es
|
34 |
* www.gvsig.gva.es
|
35 |
*
|
36 |
* or
|
37 |
*
|
38 |
* IVER T.I. S.A
|
39 |
* Salamanca 50
|
40 |
* 46005 Valencia
|
41 |
* Spain
|
42 |
*
|
43 |
* +34 963163400
|
44 |
* dac@iver.es
|
45 |
*/
|
46 |
package com.iver.cit.gvsig.fmap.drivers.dxf; |
47 |
|
48 |
import java.awt.geom.Point2D; |
49 |
import java.awt.geom.Rectangle2D; |
50 |
import java.io.File; |
51 |
import java.io.IOException; |
52 |
|
53 |
import org.cresques.cts.IProjection; |
54 |
import org.cresques.cts.ProjectionPool; |
55 |
import org.cresques.io.DxfFile; |
56 |
import org.cresques.px.Extent; |
57 |
import org.cresques.px.IObjList; |
58 |
import org.cresques.px.dxf.DxfFeatureMaker; |
59 |
import org.cresques.px.gml.Feature; |
60 |
import org.cresques.px.gml.Geometry; |
61 |
import org.cresques.px.gml.InsPoint; |
62 |
import org.cresques.px.gml.LineString; |
63 |
import org.cresques.px.gml.Point; |
64 |
import org.cresques.px.gml.Polygon; |
65 |
|
66 |
import com.hardcode.gdbms.engine.data.DriverException; |
67 |
import com.hardcode.gdbms.engine.data.FileDriver; |
68 |
import com.hardcode.gdbms.engine.values.Value; |
69 |
import com.iver.cit.gvsig.fmap.core.FShape; |
70 |
import com.iver.cit.gvsig.fmap.core.GeneralPathX; |
71 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
72 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
73 |
import com.iver.cit.gvsig.fmap.drivers.BoundedShapes; |
74 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
75 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
76 |
import com.iver.cit.gvsig.fmap.drivers.shp.SHP; |
77 |
|
78 |
/**
|
79 |
* @author jmorell (jose.morell@gmail.com)
|
80 |
* @version 13-dic-2004
|
81 |
*/
|
82 |
public class DXFDriver implements VectorialFileDriver, BoundedShapes, FileDriver { |
83 |
|
84 |
private String path; |
85 |
|
86 |
private final int ID_FIELD_ID=0; |
87 |
private final int ID_FIELD_ENTITY=1; |
88 |
private final int ID_FIELD_LAYER=2; |
89 |
private final int ID_FIELD_COLOR=3; |
90 |
private final int ID_FIELD_ELEVATION=4; |
91 |
private final int ID_FIELD_THICKNESS=5; |
92 |
private final int ID_FIELD_TEXT=6; |
93 |
private final int ID_FIELD_HEIGHTTEXT=7; |
94 |
private final int ID_FIELD_ROTATIONTEXT=8; |
95 |
|
96 |
private DxfFile.EntityFactory featureMaker;
|
97 |
private DxfFile dxfFeatureFile;
|
98 |
|
99 |
private IObjList.vector features;
|
100 |
private File dxfFile = null; |
101 |
|
102 |
/* (non-Javadoc)
|
103 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#open(java.io.File)
|
104 |
*/
|
105 |
public void open(File f) throws IOException { |
106 |
dxfFile = f; |
107 |
} |
108 |
|
109 |
/* (non-Javadoc)
|
110 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close()
|
111 |
*/
|
112 |
public void close() throws IOException { |
113 |
// TODO Auto-generated method stub
|
114 |
} |
115 |
|
116 |
/* (non-Javadoc)
|
117 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShape(int)
|
118 |
*/
|
119 |
public IGeometry getShape(int i) throws IOException { |
120 |
Feature fea = (Feature)features.get(i); |
121 |
if (fea.getGeometry() instanceof Point) { |
122 |
Point point = (Point)fea.getGeometry(); |
123 |
Point2D pto = new Point2D.Double(); |
124 |
pto = (Point2D.Double)point.get(0); |
125 |
//DGNElemMultiPoint psLine = new DGNElemMultiPoint();
|
126 |
//return ShapeFactory.createPoint3D(psLine.vertices[0].x, psLine.vertices[0].y,psLine.vertices[0].z);
|
127 |
return ShapeFactory.createPoint3D(pto.getX(),pto.getY(),0); |
128 |
} else if (fea.getGeometry() instanceof InsPoint) { |
129 |
InsPoint insPoint = (InsPoint)fea.getGeometry(); |
130 |
Point2D pto = new Point2D.Double(); |
131 |
pto = (Point2D.Double)insPoint.get(0); |
132 |
//GeneralPathX elShape = new GeneralPathX(GeneralPathX.WIND_EVEN_ODD);
|
133 |
//return ShapeFactory.createPolygon2D(elShape);
|
134 |
return ShapeFactory.createPoint3D(pto.getX(),pto.getY(),0); |
135 |
} else if (fea.getGeometry() instanceof LineString) { |
136 |
GeneralPathX genPathX = new GeneralPathX();
|
137 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr()]; |
138 |
for (int j=0; j<fea.getGeometry().pointNr(); j++) { |
139 |
pts[j] = (Point2D)fea.getGeometry().get(j);
|
140 |
} |
141 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
142 |
for (int j=1; j < pts.length; j++) { |
143 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
144 |
} |
145 |
double[] zs = new double[1]; |
146 |
zs[0] = 0.0; |
147 |
return ShapeFactory.createPolyline3D(genPathX,zs);
|
148 |
} else if (fea.getGeometry() instanceof Polygon) { |
149 |
GeneralPathX genPathX = new GeneralPathX();
|
150 |
Point2D[] pts = new Point2D[fea.getGeometry().pointNr()]; |
151 |
for (int j=0; j<fea.getGeometry().pointNr(); j++) { |
152 |
pts[j] = (Point2D)fea.getGeometry().get(j);
|
153 |
} |
154 |
genPathX.moveTo(pts[0].getX(), pts[0].getY()); |
155 |
for (int j=1; j < pts.length; j++) { |
156 |
genPathX.lineTo(pts[j].getX(), pts[j].getY()); |
157 |
} |
158 |
return ShapeFactory.createPolygon2D(genPathX);
|
159 |
} else {
|
160 |
System.out.println("getShape(): ERROR:Geometr?a desconocida."); |
161 |
return null; |
162 |
} |
163 |
} |
164 |
|
165 |
/* (non-Javadoc)
|
166 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getShapeCount()
|
167 |
*/
|
168 |
public int getShapeCount() throws IOException { |
169 |
return features.size();
|
170 |
} |
171 |
|
172 |
/* (non-Javadoc)
|
173 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFullExtent()
|
174 |
*/
|
175 |
public Rectangle2D getFullExtent() throws IOException { |
176 |
return (Rectangle2D)featureMaker.getExtent().toRectangle2D(); |
177 |
} |
178 |
|
179 |
/* (non-Javadoc)
|
180 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize()
|
181 |
*/
|
182 |
public void initialize() throws IOException { |
183 |
IProjection proj = ProjectionPool.get("EPSG:23030");
|
184 |
featureMaker = new DxfFeatureMaker(proj);
|
185 |
dxfFeatureFile = new DxfFile(proj, dxfFile.getAbsolutePath(), featureMaker);
|
186 |
dxfFeatureFile.load(); |
187 |
features = (IObjList.vector)((DxfFeatureMaker)featureMaker).getObjects(); |
188 |
} |
189 |
|
190 |
/* (non-Javadoc)
|
191 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File)
|
192 |
*/
|
193 |
public boolean accept(File f) { |
194 |
return f.getName().toUpperCase().endsWith("DXF"); |
195 |
} |
196 |
|
197 |
/* (non-Javadoc)
|
198 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getDataDriverName()
|
199 |
*/
|
200 |
public String getDataDriverName() { |
201 |
// TODO Auto-generated method stub
|
202 |
return null; |
203 |
} |
204 |
|
205 |
/* (non-Javadoc)
|
206 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getDataFile(java.io.File)
|
207 |
*/
|
208 |
public File getDataFile(File f) { |
209 |
// TODO Auto-generated method stub
|
210 |
return null; |
211 |
} |
212 |
|
213 |
/* (non-Javadoc)
|
214 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getShapeType()
|
215 |
*/
|
216 |
public int getShapeType() { |
217 |
return 1; |
218 |
} |
219 |
|
220 |
/* (non-Javadoc)
|
221 |
* @see com.hardcode.driverManager.Driver#getName()
|
222 |
*/
|
223 |
public String getName() { |
224 |
return "gvSIG DXF Driver"; |
225 |
} |
226 |
|
227 |
/* (non-Javadoc)
|
228 |
* @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeBounds(int)
|
229 |
*/
|
230 |
public Rectangle2D getShapeBounds(int index) throws IOException { |
231 |
Feature fea = (Feature)features.get(index); |
232 |
Geometry geo = (Geometry)fea.getGeometry(); |
233 |
return ((Extent)(geo.getExtent())).toRectangle2D();
|
234 |
} |
235 |
|
236 |
/* (non-Javadoc)
|
237 |
* @see com.iver.cit.gvsig.fmap.drivers.BoundedShapes#getShapeType(int)
|
238 |
*/
|
239 |
public int getShapeType(int index) { |
240 |
int auxType = 0; |
241 |
Feature fea = (Feature)features.get(index); |
242 |
if (fea.getGeometry() instanceof Point) { |
243 |
auxType = auxType | FShape.POINT; |
244 |
} else if (fea.getGeometry() instanceof InsPoint) { |
245 |
auxType = auxType | FShape.POINT; |
246 |
} else if (fea.getGeometry() instanceof LineString) { |
247 |
auxType = auxType | FShape.LINE; |
248 |
} else if (fea.getGeometry() instanceof Polygon) { |
249 |
auxType = auxType | FShape.POLYGON; |
250 |
} else {
|
251 |
System.out.println("getShape(): ERROR:Geometr?a desconocida."); |
252 |
} |
253 |
return auxType;
|
254 |
} |
255 |
|
256 |
/* (non-Javadoc)
|
257 |
* @see com.hardcode.gdbms.engine.data.FileDriver#fileAccepted(java.io.File)
|
258 |
*/
|
259 |
public boolean fileAccepted(File f) { |
260 |
return f.getName().toUpperCase().endsWith("DXF"); |
261 |
} |
262 |
|
263 |
/* (non-Javadoc)
|
264 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldValue(long, int)
|
265 |
*/
|
266 |
public Value getFieldValue(long arg0, int arg1) throws DriverException { |
267 |
// TODO Auto-generated method stub
|
268 |
return null; |
269 |
} |
270 |
|
271 |
/* (non-Javadoc)
|
272 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldCount()
|
273 |
*/
|
274 |
public int getFieldCount() throws DriverException { |
275 |
// TODO Auto-generated method stub
|
276 |
return 0; |
277 |
} |
278 |
|
279 |
/* (non-Javadoc)
|
280 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getFieldName(int)
|
281 |
*/
|
282 |
public String getFieldName(int arg0) throws DriverException { |
283 |
// TODO Auto-generated method stub
|
284 |
return null; |
285 |
} |
286 |
|
287 |
/* (non-Javadoc)
|
288 |
* @see com.hardcode.gdbms.engine.data.ReadDriver#getRowCount()
|
289 |
*/
|
290 |
public long getRowCount() throws DriverException { |
291 |
try {
|
292 |
return getShapeCount();
|
293 |
} catch (IOException e) { |
294 |
e.printStackTrace(); |
295 |
} |
296 |
return -1; |
297 |
//return 0;
|
298 |
} |
299 |
|
300 |
/* (non-Javadoc)
|
301 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialDriver#getDriverAttributes()
|
302 |
*/
|
303 |
public DriverAttributes getDriverAttributes() {
|
304 |
// TODO Auto-generated method stub
|
305 |
return null; |
306 |
} |
307 |
|
308 |
} |