Revision 6433
trunk/extensions/extCAD/src/com/iver/cit/gvsig/ExportTo.java | ||
---|---|---|
41 | 41 |
import com.iver.cit.gvsig.fmap.edition.IWriter; |
42 | 42 |
import com.iver.cit.gvsig.fmap.edition.writers.dxf.DxfFieldsMapping; |
43 | 43 |
import com.iver.cit.gvsig.fmap.edition.writers.dxf.DxfWriter; |
44 |
import com.iver.cit.gvsig.fmap.edition.writers.gml.GMLWriter; |
|
44 | 45 |
import com.iver.cit.gvsig.fmap.edition.writers.shp.ShpWriter; |
45 | 46 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
46 | 47 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
... | ... | |
230 | 231 |
if (actionCommand.equals("POSTGIS")) { |
231 | 232 |
saveToPostGIS(mapa, lv); |
232 | 233 |
} |
234 |
if (actionCommand.equals("GML")) { |
|
235 |
saveToGml(mapa, lv); |
|
236 |
} |
|
233 | 237 |
} // actives[i] |
234 | 238 |
} // for |
235 | 239 |
} catch (EditionException e) { |
... | ... | |
530 | 534 |
// } |
531 | 535 |
|
532 | 536 |
} |
537 |
|
|
538 |
/** |
|
539 |
* This method saves a layer to GML |
|
540 |
* @param mapContext |
|
541 |
* @param layer |
|
542 |
* @throws EditionException |
|
543 |
* @throws DriverIOException |
|
544 |
*/ |
|
545 |
public void saveToGml(FMap mapContext, FLyrVect layer) throws EditionException, DriverIOException { |
|
546 |
try { |
|
547 |
JFileChooser jfc = new JFileChooser(); |
|
548 |
SimpleFileFilter filterShp = new SimpleFileFilter("gml", |
|
549 |
PluginServices.getText(this, "gml_files")); |
|
550 |
jfc.setFileFilter(filterShp); |
|
551 |
if (jfc.showSaveDialog((Component) PluginServices.getMainFrame()) == JFileChooser.APPROVE_OPTION) { |
|
552 |
File newFile = jfc.getSelectedFile(); |
|
553 |
String path = newFile.getAbsolutePath(); |
|
554 |
if (!(path.toLowerCase().endsWith(".gml"))) { |
|
555 |
path = path + ".gml"; |
|
556 |
} |
|
557 |
newFile = new File(path); |
|
558 |
|
|
559 |
GMLWriter writer = (GMLWriter)LayerFactory.getWM().getWriter("GML Writer"); |
|
560 |
|
|
561 |
SHPLayerDefinition lyrDef = new SHPLayerDefinition(); |
|
562 |
SelectableDataSource sds = layer.getRecordset(); |
|
563 |
FieldDescription[] fieldsDescrip = sds.getFieldsDescription(); |
|
564 |
lyrDef.setFieldsDesc(fieldsDescrip); |
|
565 |
lyrDef.setName(layer.getName()); |
|
566 |
lyrDef.setShapeType(layer.getShapeType()); |
|
567 |
|
|
568 |
writer.setFile(newFile); |
|
569 |
writer.setSchema(lyrDef); |
|
570 |
writer.setBoundedBy(layer.getFullExtent(),layer.getProjection()); |
|
571 |
|
|
572 |
writeFeatures(mapContext, layer, writer, null); |
|
573 |
} |
|
533 | 574 |
|
575 |
} catch (DriverException e) { |
|
576 |
e.printStackTrace(); |
|
577 |
throw new EditionException(e); |
|
578 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) { |
|
579 |
e.printStackTrace(); |
|
580 |
throw new EditionException(e); |
|
581 |
} |
|
582 |
// catch (IOException e) { |
|
583 |
// e.printStackTrace(); |
|
584 |
// throw new EditionException(e); |
|
585 |
// } |
|
586 |
|
|
587 |
} |
|
588 |
|
|
534 | 589 |
/** |
535 | 590 |
* @see com.iver.andami.plugins.IExtension#isEnabled() |
536 | 591 |
*/ |
trunk/extensions/extCAD/config/text.properties | ||
---|---|---|
51 | 51 |
file=Archivo |
52 | 52 |
final_point=Punto Final |
53 | 53 |
geometry=Geometr\u00EDa |
54 |
gml_files=Ficheros gml |
|
54 | 55 |
guardar=Guardar |
55 | 56 |
hide_grid=Ocultar rejilla |
56 | 57 |
incorrect_option=Opci\u00F3n incorrecta |
trunk/extensions/extCAD/config/text_en.properties | ||
---|---|---|
39 | 39 |
field=Field |
40 | 40 |
file=File |
41 | 41 |
final_point=Final Point |
42 |
gml_files=GML Files |
|
42 | 43 |
incorrect_option=Incorrect option |
43 | 44 |
incorrect_point=Incorrect point |
44 | 45 |
incorrect_value=Incorrect value |
trunk/libraries/libFMap/build.xml | ||
---|---|---|
29 | 29 |
</target> |
30 | 30 |
|
31 | 31 |
|
32 |
<target name="generar-todos" depends="init, shp, dbf, dgn, dxf, raster, shpwriter, dxfwriter, dbfwriter" description="Genera los jars de todos los drivers ">
|
|
32 |
<target name="generar-todos" depends="init, shp, dbf, dgn, dxf, raster, gml, shpwriter, dxfwriter, dbfwriter, gmlwriter" description="Genera los jars de todos los drivers ">
|
|
33 | 33 |
</target> |
34 | 34 |
|
35 | 35 |
<target name="shp" depends="" description="Genera el jar de shp"> |
... | ... | |
61 | 61 |
<mkdir dir="${drivers-dir}/raster" /> |
62 | 62 |
<jar jarfile="${drivers-dir}/raster/raster.jar" basedir="./bin" includes="com/iver/cit/gvsig/fmap/drivers/raster/**" /> |
63 | 63 |
</target> |
64 |
|
|
65 |
<target name="gml" depends="" description="Genera el jar de gml"> |
|
66 |
<mkdir dir="${drivers-dir}/gml" /> |
|
67 |
<jar jarfile="${drivers-dir}/gml/gml.jar" basedir="./bin" includes="com/iver/cit/gvsig/fmap/drivers/gml/**" /> |
|
68 |
</target> |
|
69 |
|
|
64 | 70 |
<target name="jdbc" depends="" description="Genera el jar jdbc"> |
65 | 71 |
<mkdir dir="${drivers-dir}/jdbc" /> |
66 | 72 |
<jar jarfile="${drivers-dir}/jdbc/jdbc.jar" basedir="./bin" includes="com/iver/cit/gvsig/fmap/drivers/jdbc/**" /> |
... | ... | |
82 | 88 |
<mkdir dir="${writers-dir}/dbf" /> |
83 | 89 |
<jar jarfile="${writers-dir}/dbf/dbfWriter.jar" basedir="./bin" includes="com/iver/cit/gvsig/fmap/edition/writers/dbf/**" /> |
84 | 90 |
</target> |
91 |
|
|
92 |
<target name="gmlwriter" depends="" description="Genera el jar de gml writer"> |
|
93 |
<mkdir dir="${writers-dir}/gml" /> |
|
94 |
<jar jarfile="${writers-dir}/gml/gmlWriter.jar" basedir="./bin" includes="com/iver/cit/gvsig/fmap/edition/writers/gml/**" /> |
|
95 |
</target> |
|
85 | 96 |
|
86 | 97 |
<target name="batch-build" |
87 | 98 |
description="compile the sources, create the jar file" |
trunk/libraries/libFMap/.classpath | ||
---|---|---|
22 | 22 |
<classpathentry kind="lib" path="lib/trove-0.1.8.jar"/> |
23 | 23 |
<classpathentry kind="lib" path="lib/gt2sidx.jar"/> |
24 | 24 |
<classpathentry sourcepath="/libIverUtiles" kind="lib" path="/_fwAndami/lib/iver-utiles.jar"/> |
25 |
<classpathentry kind="src" path="src-test"/> |
|
26 |
<classpathentry sourcepath="ECLIPSE_HOME/plugins/org.eclipse.jdt.source_3.1.1/src/org.junit_3.8.1/junitsrc.zip" kind="var" path="JUNIT_HOME/junit.jar"/> |
|
27 |
<classpathentry kind="lib" path="lib/gt2-wfs.jar"/> |
|
28 |
<classpathentry kind="lib" path="lib/gt2-gml.jar"/> |
|
25 | 29 |
<classpathentry kind="output" path="bin"/> |
26 | 30 |
</classpath> |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/gml/GMLFileCreator.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.edition.writers.gml; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileWriter; |
|
6 |
import java.io.IOException; |
|
7 |
import java.io.Writer; |
|
8 |
|
|
9 |
import org.cresques.cts.IProjection; |
|
10 |
import org.geotools.xml.gml.GMLSchema; |
|
11 |
|
|
12 |
import com.hardcode.gdbms.engine.values.Value; |
|
13 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
14 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
15 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
16 |
import com.vividsolutions.jts.geom.Geometry; |
|
17 |
|
|
18 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
19 |
* |
|
20 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
21 |
* |
|
22 |
* This program is free software; you can redistribute it and/or |
|
23 |
* modify it under the terms of the GNU General Public License |
|
24 |
* as published by the Free Software Foundation; either version 2 |
|
25 |
* of the License, or (at your option) any later version. |
|
26 |
* |
|
27 |
* This program is distributed in the hope that it will be useful, |
|
28 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
29 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
30 |
* GNU General Public License for more details. |
|
31 |
* |
|
32 |
* You should have received a copy of the GNU General Public License |
|
33 |
* along with this program; if not, write to the Free Software |
|
34 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
35 |
* |
|
36 |
* For more information, contact: |
|
37 |
* |
|
38 |
* Generalitat Valenciana |
|
39 |
* Conselleria d'Infraestructures i Transport |
|
40 |
* Av. Blasco Ib??ez, 50 |
|
41 |
* 46010 VALENCIA |
|
42 |
* SPAIN |
|
43 |
* |
|
44 |
* +34 963862235 |
|
45 |
* gvsig@gva.es |
|
46 |
* www.gvsig.gva.es |
|
47 |
* |
|
48 |
* or |
|
49 |
* |
|
50 |
* IVER T.I. S.A |
|
51 |
* Salamanca 50 |
|
52 |
* 46005 Valencia |
|
53 |
* Spain |
|
54 |
* |
|
55 |
* +34 963163400 |
|
56 |
* dac@iver.es |
|
57 |
*/ |
|
58 |
/* CVS MESSAGES: |
|
59 |
* |
|
60 |
* $Id$ |
|
61 |
* $Log$ |
|
62 |
* Revision 1.1 2006-07-19 12:29:39 jorpiell |
|
63 |
* A?adido el driver de GML |
|
64 |
* |
|
65 |
* |
|
66 |
*/ |
|
67 |
/** |
|
68 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
69 |
*/ |
|
70 |
public class GMLFileCreator { |
|
71 |
private String schemaFileName = null; |
|
72 |
private Writer writer = null; |
|
73 |
private com.vividsolutions.jts.io.gml2.GMLWriter featureWriter = null; |
|
74 |
private IProjection projection = null; |
|
75 |
private String srsName = null; |
|
76 |
private Rectangle2D extent = null; |
|
77 |
private File m_File = null; |
|
78 |
private FieldDescription[] attributes = null; |
|
79 |
|
|
80 |
public GMLFileCreator(File file,String schemaFileName) throws IOException{ |
|
81 |
this.m_File = file; |
|
82 |
this.schemaFileName = schemaFileName; |
|
83 |
} |
|
84 |
|
|
85 |
/** |
|
86 |
* This method creates the GML head file. It must be |
|
87 |
* called before start to add geometries. |
|
88 |
* @throws IOException |
|
89 |
*/ |
|
90 |
public void initialize() throws IOException{ |
|
91 |
writer = new FileWriter(m_File); |
|
92 |
writer.write(getInitFile()); |
|
93 |
writer.write(getBoundedBy()); |
|
94 |
featureWriter = new com.vividsolutions.jts.io.gml2.GMLWriter(); |
|
95 |
featureWriter.setPrefix("gml"); |
|
96 |
} |
|
97 |
|
|
98 |
/** |
|
99 |
* Intert a new Feature |
|
100 |
* @param geom |
|
101 |
* @throws IOException |
|
102 |
*/ |
|
103 |
public void insertFeature(Geometry geom,Value[] attributes) throws IOException{ |
|
104 |
writer.write(getInitfeature()); |
|
105 |
writer.write(getInitGeomAttribute()); |
|
106 |
featureWriter.write(geom,writer); |
|
107 |
writer.write(getEndGeomAttribute()); |
|
108 |
|
|
109 |
for (int i=0 ; i<attributes.length ; i++){ |
|
110 |
String attributeName = this.attributes[i].getFieldName(); |
|
111 |
String attibuteValue = attributes[i].toString(); |
|
112 |
writer.write(getAttribute(attributeName,attibuteValue)); |
|
113 |
} |
|
114 |
|
|
115 |
writer.write(getEndFeature()); |
|
116 |
} |
|
117 |
|
|
118 |
|
|
119 |
|
|
120 |
/** |
|
121 |
* Writes the GML file |
|
122 |
* @throws IOException |
|
123 |
* |
|
124 |
*/ |
|
125 |
public void writeFile() throws IOException { |
|
126 |
writer.write(getEndFile()); |
|
127 |
writer.close(); |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Sets the projection |
|
132 |
* @param extent |
|
133 |
* @param proj |
|
134 |
*/ |
|
135 |
public void setBoundedBy(Rectangle2D extent, IProjection proj) { |
|
136 |
this.extent = extent; |
|
137 |
this.projection = proj; |
|
138 |
} |
|
139 |
|
|
140 |
/** |
|
141 |
* Sets the attributes collection |
|
142 |
* @param attributes |
|
143 |
*/ |
|
144 |
public void setAttibutes(FieldDescription[] attributes){ |
|
145 |
this.attributes = attributes; |
|
146 |
} |
|
147 |
|
|
148 |
/** |
|
149 |
* Creates an init Tag for a feature member |
|
150 |
* @return |
|
151 |
*/ |
|
152 |
private String getInitfeature(){ |
|
153 |
StringBuffer string = new StringBuffer(); |
|
154 |
string.append("<gml:featureMember>\n"); |
|
155 |
string.append("<" + GMLSchemaCreator.NAMESPACE + ":" + GMLSchemaCreator.getFeatureName() + ">"); |
|
156 |
return string.toString(); |
|
157 |
|
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Creates an end Tag for a feature member |
|
162 |
* @return |
|
163 |
*/ |
|
164 |
private String getEndFeature(){ |
|
165 |
StringBuffer string = new StringBuffer(); |
|
166 |
string.append("</" + GMLSchemaCreator.NAMESPACE + ":" + GMLSchemaCreator.getFeatureName() + ">"); |
|
167 |
string.append("</gml:featureMember>"); |
|
168 |
return string.toString(); |
|
169 |
} |
|
170 |
|
|
171 |
/** |
|
172 |
* Creates the GML File first line |
|
173 |
* @param fileName |
|
174 |
* GML file name used to create the schema name |
|
175 |
* @return |
|
176 |
*/ |
|
177 |
private String getInitFile(){ |
|
178 |
StringBuffer string = new StringBuffer(); |
|
179 |
string.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); |
|
180 |
string.append("<gml:FeatureCollection "); |
|
181 |
string.append("xmlns:" + GMLSchemaCreator.NAMESPACE + "=\"" + GMLSchemaCreator.TARGET_NAMESPACE + "\" "); |
|
182 |
string.append("xmlns:gml=\"http://www.opengis.net/gml\" "); |
|
183 |
string.append("xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" "); |
|
184 |
string.append("xsi:schemaLocation=\"" + GMLSchemaCreator.TARGET_NAMESPACE + " " + schemaFileName + "\""); |
|
185 |
string.append(">"); |
|
186 |
return string.toString(); |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* Creates the GML Attributes description |
|
191 |
* @return |
|
192 |
*/ |
|
193 |
private String getInitGeomAttribute(){ |
|
194 |
StringBuffer string = new StringBuffer(); |
|
195 |
string.append("<" + GMLSchemaCreator.NAMESPACE + ":" + GMLSchemaCreator.GML_GEOMETRY + ">"); |
|
196 |
return string.toString(); |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Creates the GML attribute code |
|
201 |
* @param attributeName |
|
202 |
* @param attributeValue |
|
203 |
* @return |
|
204 |
*/ |
|
205 |
private String getAttribute(String attributeName, String attributeValue){ |
|
206 |
StringBuffer string = new StringBuffer(); |
|
207 |
string.append("<" + GMLSchemaCreator.NAMESPACE + ":" + attributeName + ">"); |
|
208 |
string.append(attributeValue); |
|
209 |
string.append("</" + GMLSchemaCreator.NAMESPACE + ":" + attributeName + ">\n"); |
|
210 |
return string.toString(); |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Creates the GML Attributes description |
|
215 |
*/ |
|
216 |
private String getEndGeomAttribute(){ |
|
217 |
StringBuffer string = new StringBuffer(); |
|
218 |
string.append("</" + GMLSchemaCreator.NAMESPACE + ":" + GMLSchemaCreator.GML_GEOMETRY + ">\n"); |
|
219 |
return string.toString(); |
|
220 |
} |
|
221 |
|
|
222 |
/** |
|
223 |
* Creates the GML File last line |
|
224 |
* @return |
|
225 |
*/ |
|
226 |
private String getEndFile(){ |
|
227 |
StringBuffer string = new StringBuffer(); |
|
228 |
string.append("</gml:FeatureCollection>"); |
|
229 |
return string.toString(); |
|
230 |
} |
|
231 |
|
|
232 |
/** |
|
233 |
* Creates the boundedBy param |
|
234 |
* @return |
|
235 |
*/ |
|
236 |
private String getBoundedBy(){ |
|
237 |
srsName = GMLBoundedBy.getTag(projection); |
|
238 |
StringBuffer string = new StringBuffer(); |
|
239 |
string.append("<gml:boundedBy>"); |
|
240 |
string.append("<gml:Box srsName=\"" + srsName + "\">"); |
|
241 |
string.append("<gml:coordinates decimal=\".\" cs=\",\" "); |
|
242 |
string.append("ts=\" \">" + extent.getMinX() + "," + extent.getMinY() + " "); |
|
243 |
string.append(extent.getMaxX() + "," + extent.getMaxY() + "</gml:coordinates>"); |
|
244 |
string.append("</gml:Box>"); |
|
245 |
string.append("</gml:boundedBy>"); |
|
246 |
return string.toString(); |
|
247 |
} |
|
248 |
|
|
249 |
|
|
250 |
|
|
251 |
} |
|
0 | 252 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/gml/GMLSchemaCreator.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.edition.writers.gml; |
|
2 |
|
|
3 |
import java.io.File; |
|
4 |
import java.io.FileWriter; |
|
5 |
import java.io.IOException; |
|
6 |
import java.io.Writer; |
|
7 |
|
|
8 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
|
9 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
|
10 |
import com.iver.cit.gvsig.fmap.drivers.gml.GMLTypesConversor; |
|
11 |
|
|
12 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
13 |
* |
|
14 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
15 |
* |
|
16 |
* This program is free software; you can redistribute it and/or |
|
17 |
* modify it under the terms of the GNU General Public License |
|
18 |
* as published by the Free Software Foundation; either version 2 |
|
19 |
* of the License, or (at your option) any later version. |
|
20 |
* |
|
21 |
* This program is distributed in the hope that it will be useful, |
|
22 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
23 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
24 |
* GNU General Public License for more details. |
|
25 |
* |
|
26 |
* You should have received a copy of the GNU General Public License |
|
27 |
* along with this program; if not, write to the Free Software |
|
28 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
29 |
* |
|
30 |
* For more information, contact: |
|
31 |
* |
|
32 |
* Generalitat Valenciana |
|
33 |
* Conselleria d'Infraestructures i Transport |
|
34 |
* Av. Blasco Ib??ez, 50 |
|
35 |
* 46010 VALENCIA |
|
36 |
* SPAIN |
|
37 |
* |
|
38 |
* +34 963862235 |
|
39 |
* gvsig@gva.es |
|
40 |
* www.gvsig.gva.es |
|
41 |
* |
|
42 |
* or |
|
43 |
* |
|
44 |
* IVER T.I. S.A |
|
45 |
* Salamanca 50 |
|
46 |
* 46005 Valencia |
|
47 |
* Spain |
|
48 |
* |
|
49 |
* +34 963163400 |
|
50 |
* dac@iver.es |
|
51 |
*/ |
|
52 |
/* CVS MESSAGES: |
|
53 |
* |
|
54 |
* $Id$ |
|
55 |
* $Log$ |
|
56 |
* Revision 1.1 2006-07-19 12:29:39 jorpiell |
|
57 |
* A?adido el driver de GML |
|
58 |
* |
|
59 |
* |
|
60 |
*/ |
|
61 |
/** |
|
62 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
63 |
*/ |
|
64 |
public class GMLSchemaCreator { |
|
65 |
public final static String GML_SUBSTITUTION_GROUP = "gml:_Feature"; |
|
66 |
public final static String GML_GEOMETRY = "the_geom"; |
|
67 |
public final static String NAMESPACE = "cit"; |
|
68 |
public final static String TARGET_NAMESPACE = "http://www.gvsig.com/cit"; |
|
69 |
|
|
70 |
private static String featureName = null; |
|
71 |
private static String featureType = null; |
|
72 |
|
|
73 |
private Writer writer = null; |
|
74 |
|
|
75 |
|
|
76 |
public GMLSchemaCreator(File m_File) throws IOException { |
|
77 |
super(); |
|
78 |
writer = new FileWriter(m_File); |
|
79 |
featureName = m_File.getName().replaceAll("\\.xsd",""); |
|
80 |
featureType = featureName + "_Type"; |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
public void createFile(LayerDefinition lyrDef) throws IOException{ |
|
85 |
writer.write(getInitFile()); |
|
86 |
writer.write(getInitComplexTypes()); |
|
87 |
|
|
88 |
writer.write(getAttribute(GML_GEOMETRY, |
|
89 |
GMLTypesConversor.gvSIGToSchemaShapeTypesConversion(lyrDef.getShapeType()))); |
|
90 |
FieldDescription[] fieldDescription = lyrDef.getFieldsDesc(); |
|
91 |
for (int i=0 ; i<fieldDescription.length ; i++){ |
|
92 |
writer.write(getAttribute(fieldDescription[i])); |
|
93 |
} |
|
94 |
|
|
95 |
writer.write(getEndComplexTypes()); |
|
96 |
writer.write(getEndFile()); |
|
97 |
} |
|
98 |
|
|
99 |
/** |
|
100 |
* Writes the schema file |
|
101 |
* @throws IOException |
|
102 |
* |
|
103 |
*/ |
|
104 |
public void writeFile() throws IOException { |
|
105 |
writer.close(); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* Creates the schema header File |
|
110 |
* @return |
|
111 |
*/ |
|
112 |
private String getInitFile(){ |
|
113 |
StringBuffer string = new StringBuffer(); |
|
114 |
string.append("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"); |
|
115 |
string.append("<xs:schema targetNamespace=\"" + TARGET_NAMESPACE + "\" "); |
|
116 |
string.append("xmlns:" + NAMESPACE + "=\"" + TARGET_NAMESPACE + "\" "); |
|
117 |
string.append("xmlns:gml=\"http://www.opengis.net/gml\" "); |
|
118 |
string.append("xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "); |
|
119 |
string.append("elementFormDefault=\"qualified\" "); |
|
120 |
string.append("attributeFormDefault=\"unqualified\" version=\"1.0\">"); |
|
121 |
string.append("<xs:import namespace=\"http://www.opengis.net/gml\" "); |
|
122 |
string.append("schemaLocation=\"http://schemas.opengeospatial.net/gml/2.1.2/feature.xsd\"/"); |
|
123 |
string.append(">"); |
|
124 |
return string.toString(); |
|
125 |
} |
|
126 |
|
|
127 |
|
|
128 |
/** |
|
129 |
* Creates the GML File last line |
|
130 |
* @return |
|
131 |
*/ |
|
132 |
private String getEndFile(){ |
|
133 |
StringBuffer string = new StringBuffer(); |
|
134 |
string.append("</xs:schema>"); |
|
135 |
return string.toString(); |
|
136 |
} |
|
137 |
|
|
138 |
/** |
|
139 |
* Creates the complex types header |
|
140 |
* @return |
|
141 |
*/ |
|
142 |
private String getInitComplexTypes(){ |
|
143 |
StringBuffer string = new StringBuffer(); |
|
144 |
string.append("<xs:complexType xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" "); |
|
145 |
string.append("name=\"" + getFeatureType() + "\">"); |
|
146 |
string.append("<xs:complexContent>"); |
|
147 |
string.append("<xs:extension base=\"gml:AbstractFeatureType\">"); |
|
148 |
string.append("<xs:sequence>"); |
|
149 |
return string.toString(); |
|
150 |
} |
|
151 |
|
|
152 |
/** |
|
153 |
* Creates the complex types end tag |
|
154 |
* @return |
|
155 |
*/ |
|
156 |
private String getEndComplexTypes(){ |
|
157 |
StringBuffer string = new StringBuffer(); |
|
158 |
string.append("</xs:sequence>"); |
|
159 |
string.append("</xs:extension>"); |
|
160 |
string.append("</xs:complexContent>"); |
|
161 |
string.append("</xs:complexType>"); |
|
162 |
string.append("<xs:element name=\"" + getFeatureName() + "\" "); |
|
163 |
string.append("type=\"" + NAMESPACE + ":" + getFeatureType() + "\" "); |
|
164 |
string.append("substitutionGroup=\"" + GML_SUBSTITUTION_GROUP + "\"/>"); |
|
165 |
return string.toString(); |
|
166 |
} |
|
167 |
|
|
168 |
/** |
|
169 |
* Creates the attribute description |
|
170 |
* @param fieldDescription |
|
171 |
* @return |
|
172 |
*/ |
|
173 |
private String getAttribute(FieldDescription fieldDescription){ |
|
174 |
return getAttribute(fieldDescription.getFieldName(), |
|
175 |
GMLTypesConversor.gvSIGToSchemaTypesConversion(fieldDescription.getFieldType())); |
|
176 |
} |
|
177 |
|
|
178 |
/** |
|
179 |
* Creates the attribute description |
|
180 |
* @param attributeName |
|
181 |
* Attribute name |
|
182 |
* @param attributeType |
|
183 |
* Attribute Type |
|
184 |
* @return |
|
185 |
*/ |
|
186 |
private String getAttribute(String attributeName, String attributeType){ |
|
187 |
StringBuffer string = new StringBuffer(); |
|
188 |
string.append("<xs:element name=\"" + attributeName + "\" "); |
|
189 |
string.append("minOccurs=\"0\" "); |
|
190 |
string.append("nillable=\"true\" "); |
|
191 |
string.append("type=\"" + attributeType + "\"/>"); |
|
192 |
return string.toString(); |
|
193 |
} |
|
194 |
|
|
195 |
/** |
|
196 |
* @return Returns the featureName. |
|
197 |
*/ |
|
198 |
public static String getFeatureName() { |
|
199 |
return featureName; |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* @return Returns the featureType. |
|
204 |
*/ |
|
205 |
public static String getFeatureType() { |
|
206 |
return featureType; |
|
207 |
} |
|
208 |
|
|
209 |
|
|
210 |
|
|
211 |
|
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
} |
|
0 | 216 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/gml/GMLBoundedBy.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.edition.writers.gml; |
|
2 |
|
|
3 |
import org.cresques.cts.IProjection; |
|
4 |
|
|
5 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
6 |
* |
|
7 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
8 |
* |
|
9 |
* This program is free software; you can redistribute it and/or |
|
10 |
* modify it under the terms of the GNU General Public License |
|
11 |
* as published by the Free Software Foundation; either version 2 |
|
12 |
* of the License, or (at your option) any later version. |
|
13 |
* |
|
14 |
* This program is distributed in the hope that it will be useful, |
|
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
17 |
* GNU General Public License for more details. |
|
18 |
* |
|
19 |
* You should have received a copy of the GNU General Public License |
|
20 |
* along with this program; if not, write to the Free Software |
|
21 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
22 |
* |
|
23 |
* For more information, contact: |
|
24 |
* |
|
25 |
* Generalitat Valenciana |
|
26 |
* Conselleria d'Infraestructures i Transport |
|
27 |
* Av. Blasco Ib??ez, 50 |
|
28 |
* 46010 VALENCIA |
|
29 |
* SPAIN |
|
30 |
* |
|
31 |
* +34 963862235 |
|
32 |
* gvsig@gva.es |
|
33 |
* www.gvsig.gva.es |
|
34 |
* |
|
35 |
* or |
|
36 |
* |
|
37 |
* IVER T.I. S.A |
|
38 |
* Salamanca 50 |
|
39 |
* 46005 Valencia |
|
40 |
* Spain |
|
41 |
* |
|
42 |
* +34 963163400 |
|
43 |
* dac@iver.es |
|
44 |
*/ |
|
45 |
/* CVS MESSAGES: |
|
46 |
* |
|
47 |
* $Id$ |
|
48 |
* $Log$ |
|
49 |
* Revision 1.1 2006-07-19 12:29:39 jorpiell |
|
50 |
* A?adido el driver de GML |
|
51 |
* |
|
52 |
* |
|
53 |
*/ |
|
54 |
/** |
|
55 |
* This class is used to get a GML projection tag |
|
56 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
57 |
*/ |
|
58 |
public class GMLBoundedBy { |
|
59 |
|
|
60 |
public static String getTag(IProjection proj){ |
|
61 |
if (proj == null){ |
|
62 |
return "http://www.opengis.net/gml/srs/epsg.xml#23030"; |
|
63 |
} |
|
64 |
|
|
65 |
String srs = proj.getAbrev(); |
|
66 |
if (srs.compareTo("EPSG") == 0){ |
|
67 |
if (srs.split(":").length > 1){ |
|
68 |
return "http://www.opengis.net/gml/srs/epsg.xml#" + srs.split(":")[1]; |
|
69 |
} |
|
70 |
} |
|
71 |
return "http://www.opengis.net/gml/srs/epsg.xml#23030"; |
|
72 |
} |
|
73 |
|
|
74 |
} |
|
0 | 75 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/edition/writers/gml/GMLWriter.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.edition.writers.gml; |
|
2 |
|
|
3 |
import java.awt.geom.Rectangle2D; |
|
4 |
import java.io.File; |
|
5 |
import java.io.FileWriter; |
|
6 |
import java.io.IOException; |
|
7 |
|
|
8 |
import org.cresques.cts.IProjection; |
|
9 |
import org.geotools.feature.FeatureType; |
|
10 |
|
|
11 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
12 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
|
13 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
|
14 |
import com.iver.cit.gvsig.fmap.drivers.gml.GMLTypesConversor; |
|
15 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
|
16 |
import com.iver.cit.gvsig.fmap.edition.IRowEdited; |
|
17 |
import com.iver.cit.gvsig.fmap.edition.ISpatialWriter; |
|
18 |
import com.iver.cit.gvsig.fmap.edition.writers.AbstractWriter; |
|
19 |
import com.iver.utiles.StringUtilities; |
|
20 |
import com.vividsolutions.jts.geom.Geometry; |
|
21 |
|
|
22 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
23 |
* |
|
24 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
25 |
* |
|
26 |
* This program is free software; you can redistribute it and/or |
|
27 |
* modify it under the terms of the GNU General Public License |
|
28 |
* as published by the Free Software Foundation; either version 2 |
|
29 |
* of the License, or (at your option) any later version. |
|
30 |
* |
|
31 |
* This program is distributed in the hope that it will be useful, |
|
32 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
33 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
34 |
* GNU General Public License for more details. |
|
35 |
* |
|
36 |
* You should have received a copy of the GNU General Public License |
|
37 |
* along with this program; if not, write to the Free Software |
|
38 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
39 |
* |
|
40 |
* For more information, contact: |
|
41 |
* |
|
42 |
* Generalitat Valenciana |
|
43 |
* Conselleria d'Infraestructures i Transport |
|
44 |
* Av. Blasco Ib??ez, 50 |
|
45 |
* 46010 VALENCIA |
|
46 |
* SPAIN |
|
47 |
* |
|
48 |
* +34 963862235 |
|
49 |
* gvsig@gva.es |
|
50 |
* www.gvsig.gva.es |
|
51 |
* |
|
52 |
* or |
|
53 |
* |
|
54 |
* IVER T.I. S.A |
|
55 |
* Salamanca 50 |
|
56 |
* 46005 Valencia |
|
57 |
* Spain |
|
58 |
* |
|
59 |
* +34 963163400 |
|
60 |
* dac@iver.es |
|
61 |
*/ |
|
62 |
/* CVS MESSAGES: |
|
63 |
* |
|
64 |
* $Id$ |
|
65 |
* $Log$ |
|
66 |
* Revision 1.1 2006-07-19 12:29:39 jorpiell |
|
67 |
* A?adido el driver de GML |
|
68 |
* |
|
69 |
* |
|
70 |
*/ |
|
71 |
/** |
|
72 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
73 |
*/ |
|
74 |
public class GMLWriter extends AbstractWriter implements ISpatialWriter{ |
|
75 |
private File m_File = null; |
|
76 |
private FeatureType featureType = null; |
|
77 |
private GMLFileCreator gmlFile = null; |
|
78 |
private GMLSchemaCreator gmlSchemaFileCreator = null; |
|
79 |
|
|
80 |
/** |
|
81 |
* Sets the output file |
|
82 |
* @param f |
|
83 |
*/ |
|
84 |
public void setFile(File f) { |
|
85 |
m_File = f; |
|
86 |
} |
|
87 |
|
|
88 |
/** |
|
89 |
* Sets the schema definition |
|
90 |
* @param lyrDef |
|
91 |
* @throws EditionException |
|
92 |
* @throws Exception |
|
93 |
*/ |
|
94 |
public void setSchema(LayerDefinition lyrDef) throws EditionException{ |
|
95 |
try { |
|
96 |
featureType = GMLTypesConversor.featureTypefromGvSIGToGeotools(lyrDef); |
|
97 |
|
|
98 |
String schemaPath = m_File.toURI().getPath().toLowerCase().replaceAll("\\.gml", ".xsd"); |
|
99 |
|
|
100 |
gmlFile = new GMLFileCreator(m_File,schemaPath); |
|
101 |
gmlFile.setAttibutes(lyrDef.getFieldsDesc()); |
|
102 |
|
|
103 |
schemaPath = m_File.getAbsolutePath().toLowerCase().replaceAll("\\.gml", ".xsd"); |
|
104 |
|
|
105 |
gmlSchemaFileCreator = new GMLSchemaCreator(new File(schemaPath)); |
|
106 |
gmlSchemaFileCreator.createFile(lyrDef); |
|
107 |
} catch (Exception e) { |
|
108 |
// TODO Auto-generated catch block |
|
109 |
e.printStackTrace(); |
|
110 |
throw new EditionException(e.toString()); |
|
111 |
} |
|
112 |
} |
|
113 |
|
|
114 |
/** |
|
115 |
* Sets the geometry extend |
|
116 |
* @param extend |
|
117 |
* @param proj |
|
118 |
*/ |
|
119 |
public void setBoundedBy(Rectangle2D extend,IProjection proj){ |
|
120 |
gmlFile.setBoundedBy(extend,proj); |
|
121 |
} |
|
122 |
|
|
123 |
/* |
|
124 |
* (non-Javadoc) |
|
125 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#canWriteAttribute(int) |
|
126 |
*/ |
|
127 |
public boolean canWriteAttribute(int sqlType) { |
|
128 |
return true; |
|
129 |
} |
|
130 |
|
|
131 |
/* |
|
132 |
* (non-Javadoc) |
|
133 |
* @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#canWriteGeometry(int) |
|
134 |
*/ |
|
135 |
public boolean canWriteGeometry(int gvSIGgeometryType) { |
|
136 |
return true; |
|
137 |
} |
|
138 |
|
|
139 |
/* |
|
140 |
* (non-Javadoc) |
|
141 |
* @see com.iver.cit.gvsig.fmap.edition.ISpatialWriter#setFlatness(double) |
|
142 |
*/ |
|
143 |
public void setFlatness(double flatness) { |
|
144 |
// TODO Auto-generated method stub |
|
145 |
|
|
146 |
} |
|
147 |
|
|
148 |
/* |
|
149 |
* (non-Javadoc) |
|
150 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#preProcess() |
|
151 |
*/ |
|
152 |
public void preProcess() throws EditionException { |
|
153 |
if (gmlFile == null){ |
|
154 |
new EditionException("The driver must be initialized using the setSchema method"); |
|
155 |
} |
|
156 |
try { |
|
157 |
gmlFile.initialize(); |
|
158 |
|
|
159 |
} catch (IOException e) { |
|
160 |
// TODO Auto-generated catch block |
|
161 |
e.printStackTrace(); |
|
162 |
new EditionException(e.toString()); |
|
163 |
} |
|
164 |
} |
|
165 |
|
|
166 |
/* |
|
167 |
* (non-Javadoc) |
|
168 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#process(com.iver.cit.gvsig.fmap.edition.IRowEdited) |
|
169 |
*/ |
|
170 |
public void process(IRowEdited row) throws EditionException { |
|
171 |
Geometry geom = ((IFeature)row.getLinkedRow()).getGeometry().toJTSGeometry(); |
|
172 |
try { |
|
173 |
gmlFile.insertFeature(geom,row.getAttributes()); |
|
174 |
} catch (IOException e) { |
|
175 |
// TODO Auto-generated catch block |
|
176 |
e.printStackTrace(); |
|
177 |
throw new EditionException(e.toString()); |
|
178 |
} |
|
179 |
} |
|
180 |
|
|
181 |
/* |
|
182 |
* (non-Javadoc) |
|
183 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#postProcess() |
|
184 |
*/ |
|
185 |
public void postProcess() throws EditionException { |
|
186 |
try { |
|
187 |
gmlFile.writeFile(); |
|
188 |
gmlSchemaFileCreator.writeFile(); |
|
189 |
} catch (IOException e) { |
|
190 |
// TODO Auto-generated catch block |
|
191 |
e.printStackTrace(); |
|
192 |
throw new EditionException(e.toString()); |
|
193 |
} |
|
194 |
} |
|
195 |
|
|
196 |
/* |
|
197 |
* (non-Javadoc) |
|
198 |
* @see com.iver.cit.gvsig.fmap.edition.IWriter#initialize(com.iver.cit.gvsig.fmap.drivers.ITableDefinition) |
|
199 |
*/ |
|
200 |
public void initialize(ITableDefinition tableDefinition) throws EditionException { |
|
201 |
// TODO Auto-generated method stub |
|
202 |
|
|
203 |
} |
|
204 |
|
|
205 |
/* |
|
206 |
* (non-Javadoc) |
|
207 |
* @see com.hardcode.driverManager.Driver#getName() |
|
208 |
*/ |
|
209 |
public String getName() { |
|
210 |
return "GML Writer"; |
|
211 |
} |
|
212 |
|
|
213 |
|
|
214 |
|
|
215 |
|
|
216 |
} |
|
0 | 217 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/gml/GMLFeaturesIterator.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.gml; |
|
2 |
|
|
3 |
import java.awt.geom.Point2D; |
|
4 |
import java.io.IOException; |
|
5 |
import java.util.ArrayList; |
|
6 |
import java.util.Date; |
|
7 |
import java.util.NoSuchElementException; |
|
8 |
import java.util.Vector; |
|
9 |
|
|
10 |
import org.cresques.cts.ICoordTrans; |
|
11 |
import org.geotools.data.FeatureReader; |
|
12 |
import org.geotools.feature.AttributeType; |
|
13 |
import org.geotools.feature.Feature; |
|
14 |
import org.geotools.feature.IllegalAttributeException; |
|
15 |
|
|
16 |
import com.hardcode.gdbms.engine.values.Value; |
|
17 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
18 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
19 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
|
20 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
21 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
22 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
23 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
|
24 |
|
|
25 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
26 |
* |
|
27 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
28 |
* |
|
29 |
* This program is free software; you can redistribute it and/or |
|
30 |
* modify it under the terms of the GNU General Public License |
|
31 |
* as published by the Free Software Foundation; either version 2 |
|
32 |
* of the License, or (at your option) any later version. |
|
33 |
* |
|
34 |
* This program is distributed in the hope that it will be useful, |
|
35 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
36 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
37 |
* GNU General Public License for more details. |
|
38 |
* |
|
39 |
* You should have received a copy of the GNU General Public License |
|
40 |
* along with this program; if not, write to the Free Software |
|
41 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
42 |
* |
|
43 |
* For more information, contact: |
|
44 |
* |
|
45 |
* Generalitat Valenciana |
|
46 |
* Conselleria d'Infraestructures i Transport |
|
47 |
* Av. Blasco Ib??ez, 50 |
|
48 |
* 46010 VALENCIA |
|
49 |
* SPAIN |
|
50 |
* |
|
51 |
* +34 963862235 |
|
52 |
* gvsig@gva.es |
|
53 |
* www.gvsig.gva.es |
|
54 |
* |
|
55 |
* or |
|
56 |
* |
|
57 |
* IVER T.I. S.A |
|
58 |
* Salamanca 50 |
|
59 |
* 46005 Valencia |
|
60 |
* Spain |
|
61 |
* |
|
62 |
* +34 963163400 |
|
63 |
* dac@iver.es |
|
64 |
*/ |
|
65 |
/* CVS MESSAGES: |
|
66 |
* |
|
67 |
* $Id$ |
|
68 |
* $Log$ |
|
69 |
* Revision 1.1 2006-07-19 12:29:39 jorpiell |
|
70 |
* A?adido el driver de GML |
|
71 |
* |
|
72 |
* |
|
73 |
*/ |
|
74 |
/** |
|
75 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
76 |
*/ |
|
77 |
public class GMLFeaturesIterator { |
|
78 |
private FeatureReader featureReader = null; |
|
79 |
private Vector featureVector = new Vector(); |
|
80 |
private boolean parserException = false; |
|
81 |
private boolean finished = false; |
|
82 |
private int position = -1; |
|
83 |
private int length = -2; |
|
84 |
private ICoordTrans coordTrans; |
|
85 |
|
|
86 |
public GMLFeaturesIterator(FeatureReader featureReader){ |
|
87 |
this.featureReader = featureReader; |
|
88 |
} |
|
89 |
|
|
90 |
/** |
|
91 |
* Gets the next feature |
|
92 |
* @return |
|
93 |
* @throws DriverException |
|
94 |
*/ |
|
95 |
public IFeature next() throws DriverException { |
|
96 |
if (!finished){ |
|
97 |
Feature feature = null; |
|
98 |
try { |
|
99 |
feature = featureReader.next(); |
|
100 |
} catch (NoSuchElementException e) { |
|
101 |
e.printStackTrace(); |
|
102 |
} catch (IOException e) { |
|
103 |
e.printStackTrace(); |
|
104 |
} catch (IllegalAttributeException e) { |
|
105 |
e.printStackTrace(); |
|
106 |
} |
|
107 |
Object[] attr = null; |
|
108 |
attr = feature.getAttributes(attr); |
|
109 |
Value[] values = getValues(attr); |
|
110 |
|
|
111 |
try{ |
|
112 |
IGeometry g = ShapeFactory.createGeometry(FConverter.jts_to_java2d(feature.getDefaultGeometry())); |
|
113 |
if (coordTrans != null){ |
|
114 |
g.reProject(coordTrans); |
|
115 |
} |
|
116 |
IFeature outPutFeature = new DefaultFeature(g,values,feature.getID()); |
|
117 |
featureVector.add(outPutFeature); |
|
118 |
return outPutFeature; |
|
119 |
}catch (NullPointerException e){ |
|
120 |
//The geometry can't be created |
|
121 |
} |
|
122 |
}else{ |
|
123 |
return (DefaultFeature)featureVector.get(position); |
|
124 |
} |
|
125 |
return null; |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Returns if there is a new feature to retrieve |
|
130 |
* @return |
|
131 |
*/ |
|
132 |
public boolean hasNext(){ |
|
133 |
if (length == -2){ |
|
134 |
try { |
|
135 |
if (featureReader.hasNext()){ |
|
136 |
position++; |
|
137 |
return true; |
|
138 |
}else{ |
|
139 |
featureReader.close(); |
|
140 |
finished = true; |
|
141 |
length = featureVector.size() - 1; |
|
142 |
return false; |
|
143 |
} |
|
144 |
} catch (IOException e) { |
|
145 |
e.printStackTrace(); |
|
146 |
} |
|
147 |
}else{ |
|
148 |
if (position != length){ |
|
149 |
position++; |
|
150 |
return true; |
|
151 |
}else{ |
|
152 |
return false; |
|
153 |
} |
|
154 |
} |
|
155 |
return false; |
|
156 |
} |
|
157 |
|
|
158 |
/** |
|
159 |
* Gets the attributes |
|
160 |
* @param attr |
|
161 |
* @return |
|
162 |
*/ |
|
163 |
private Value[] getValues(Object[] attr) { |
|
164 |
Value[] values = null; |
|
165 |
if (attr.length - 1 > 0){ |
|
166 |
values = new Value[attr.length - 1]; |
|
167 |
}else{ |
|
168 |
values = new Value[0]; |
|
169 |
} |
|
170 |
for (int i=1;i<attr.length;i++){ |
|
171 |
if (attr[i]!=null){ |
|
172 |
if (attr[i] instanceof Double){ |
|
173 |
values[i-1]=ValueFactory.createValue(((Double)attr[i]).doubleValue()); |
|
174 |
}else if (attr[i] instanceof String){ |
|
175 |
values[i-1]=ValueFactory.createValue(String.valueOf(attr[i])); |
|
176 |
}else if (attr[i] instanceof Long){ |
|
177 |
values[i-1]=ValueFactory.createValue(((Long)attr[i]).longValue()); |
|
178 |
}else if (attr[i] instanceof Integer){ |
|
179 |
values[i-1]=ValueFactory.createValue(((Integer)attr[i]).intValue()); |
|
180 |
}else if (attr[i] instanceof Float){ |
|
181 |
values[i-1]=ValueFactory.createValue(((Float)attr[i]).floatValue()); |
|
182 |
}else if (attr[i] instanceof Short){ |
|
183 |
values[i-1]=ValueFactory.createValue(((Short)attr[i]).shortValue()); |
|
184 |
}else if (attr[i] instanceof Boolean){ |
|
185 |
values[i-1]=ValueFactory.createValue(((Boolean)attr[i]).booleanValue()); |
|
186 |
}else if (attr[i] instanceof Date){ |
|
187 |
values[i-1]=ValueFactory.createValue(((Date)attr[i])); |
|
188 |
} |
|
189 |
}else{ |
|
190 |
values[i-1]=ValueFactory.createValue(""); |
|
191 |
} |
|
192 |
} |
|
193 |
return values; |
|
194 |
} |
|
195 |
|
|
196 |
/* |
|
197 |
* (non-Javadoc) |
|
198 |
* @see com.iver.cit.gvsig.fmap.drivers.IFeatureIterator#closeIterator() |
|
199 |
*/ |
|
200 |
public void closeIterator() throws DriverException { |
|
201 |
// TODO Auto-generated method stub |
|
202 |
} |
|
203 |
|
|
204 |
/** |
|
205 |
* This method must be executed before to start an iteration |
|
206 |
* process |
|
207 |
*/ |
|
208 |
public void startIteration(){ |
|
209 |
position = -1; |
|
210 |
} |
|
211 |
|
|
212 |
/** |
|
213 |
* Reprojects the new point |
|
214 |
* @param ptOrig |
|
215 |
* Origin point |
|
216 |
* @return |
|
217 |
* FPoint2D |
|
218 |
*/ |
|
219 |
private Point2D getReprojectedPoint(Point2D ptOrigin){ |
|
220 |
Point2D ptDest = null; |
|
221 |
return getCoordTrans().convert(ptOrigin, ptDest); |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
225 |
* @return the coordTrans |
|
226 |
*/ |
|
227 |
public ICoordTrans getCoordTrans() { |
|
228 |
return coordTrans; |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* @return Returns the parserException. |
|
233 |
*/ |
|
234 |
public boolean isParserException() { |
|
235 |
return parserException; |
|
236 |
} |
|
237 |
|
|
238 |
/** |
|
239 |
* @param parserException The parserException to set. |
|
240 |
*/ |
|
241 |
public void setParserException(boolean parserException) { |
|
242 |
this.parserException = parserException; |
|
243 |
} |
|
244 |
|
|
245 |
/** |
|
246 |
* Return the attributes type |
|
247 |
* |
|
248 |
*/ |
|
249 |
public AttributeType[] getAttributeTypes(){ |
|
250 |
try{ |
|
251 |
return featureReader.getFeatureType().getAttributeTypes(); |
|
252 |
}catch(NullPointerException e){ |
|
253 |
return new AttributeType[0]; |
|
254 |
} |
|
255 |
} |
|
256 |
|
|
257 |
/** |
|
258 |
* Returns the attributes name |
|
259 |
* @return |
|
260 |
*/ |
|
261 |
public ArrayList getAttributeNames(){ |
|
262 |
AttributeType[] attr = getAttributeTypes(); |
|
263 |
ArrayList arrayFields = new ArrayList(); |
|
264 |
for (int i=0 ; i<attr.length ; i++){ |
|
265 |
if (!(GMLUtils.isGeometry(attr[i].getType()))){ |
|
266 |
arrayFields.add(attr[i].getName()); |
|
267 |
} |
|
268 |
} |
|
269 |
return arrayFields; |
|
270 |
} |
|
271 |
|
|
272 |
} |
|
0 | 273 |
trunk/libraries/libFMap/src/com/iver/cit/gvsig/fmap/drivers/gml/GMLDriver.java | ||
---|---|---|
1 |
package com.iver.cit.gvsig.fmap.drivers.gml; |
|
2 |
|
|
3 |
import java.awt.Color; |
|
4 |
import java.awt.Font; |
|
5 |
import java.io.File; |
|
6 |
import java.io.IOException; |
|
7 |
import java.net.URI; |
|
8 |
import java.util.ArrayList; |
|
9 |
import java.util.NoSuchElementException; |
|
10 |
|
|
11 |
import org.apache.log4j.Logger; |
|
12 |
import org.cresques.px.dxf.AcadColor; |
|
13 |
import org.geotools.data.DefaultQuery; |
|
14 |
import org.geotools.data.FeatureReader; |
|
15 |
import org.geotools.data.Transaction; |
|
16 |
import org.geotools.feature.AttributeType; |
|
17 |
import org.geotools.feature.IllegalAttributeException; |
|
18 |
|
|
19 |
import sun.print.PSPrinterJob.PluginPrinter; |
|
20 |
|
|
21 |
import com.hardcode.gdbms.engine.data.driver.ObjectDriver; |
|
22 |
import com.hardcode.gdbms.engine.values.IntValue; |
|
23 |
import com.hardcode.gdbms.engine.values.Value; |
|
24 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
|
25 |
import com.iver.cit.gvsig.fmap.DriverException; |
|
26 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
|
27 |
import com.iver.cit.gvsig.fmap.core.FShape; |
|
28 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
29 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
30 |
import com.iver.cit.gvsig.fmap.core.ShapeFactory; |
|
31 |
import com.iver.cit.gvsig.fmap.core.v02.FConstant; |
|
32 |
import com.iver.cit.gvsig.fmap.core.v02.FConverter; |
|
33 |
import com.iver.cit.gvsig.fmap.core.v02.FSymbol; |
|
34 |
import com.iver.cit.gvsig.fmap.drivers.ConcreteMemoryDriver; |
|
35 |
import com.iver.cit.gvsig.fmap.drivers.DriverAttributes; |
|
36 |
import com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver; |
|
37 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
|
38 |
import com.iver.cit.gvsig.fmap.rendering.LegendFactory; |
|
39 |
import com.iver.cit.gvsig.fmap.rendering.VectorialUniqueValueLegend; |
|
40 |
|
|
41 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
42 |
* |
|
43 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
44 |
* |
|
45 |
* This program is free software; you can redistribute it and/or |
|
46 |
* modify it under the terms of the GNU General Public License |
|
47 |
* as published by the Free Software Foundation; either version 2 |
|
48 |
* of the License, or (at your option) any later version. |
|
49 |
* |
|
50 |
* This program is distributed in the hope that it will be useful, |
|
51 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
52 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
53 |
* GNU General Public License for more details. |
|
54 |
* |
|
55 |
* You should have received a copy of the GNU General Public License |
|
56 |
* along with this program; if not, write to the Free Software |
|
57 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
58 |
* |
|
59 |
* For more information, contact: |
|
60 |
* |
|
61 |
* Generalitat Valenciana |
|
62 |
* Conselleria d'Infraestructures i Transport |
|
63 |
* Av. Blasco Ib??ez, 50 |
|
64 |
* 46010 VALENCIA |
|
65 |
* SPAIN |
|
66 |
* |
|
67 |
* +34 963862235 |
|
68 |
* gvsig@gva.es |
|
69 |
* www.gvsig.gva.es |
|
70 |
* |
|
71 |
* or |
|
72 |
* |
|
73 |
* IVER T.I. S.A |
|
74 |
* Salamanca 50 |
|
75 |
* 46005 Valencia |
|
76 |
* Spain |
|
77 |
* |
|
78 |
* +34 963163400 |
|
79 |
* dac@iver.es |
|
80 |
*/ |
|
81 |
/* CVS MESSAGES: |
|
82 |
* |
|
83 |
* $Id$ |
|
84 |
* $Log$ |
|
85 |
* Revision 1.1 2006-07-19 12:29:39 jorpiell |
|
86 |
* A?adido el driver de GML |
|
87 |
* |
|
88 |
* |
|
89 |
*/ |
|
90 |
/** |
|
91 |
* This class implements the gvSIG GML parser using the geotools |
|
92 |
* library |
|
93 |
* |
|
94 |
* @author Jorge Piera Llodr? (piera_jor@gva.es) |
|
95 |
*/ |
|
96 |
public class GMLDriver extends ConcreteMemoryDriver implements VectorialFileDriver{ |
|
97 |
private static Logger logger = Logger.getLogger(GMLDriver.class.getName()); |
|
98 |
private File m_Fich; |
|
99 |
private VectorialUniqueValueLegend defaultLegend; |
|
100 |
|
|
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 |
m_Fich = f; |
|
107 |
} |
|
108 |
|
|
109 |
/* |
|
110 |
* (non-Javadoc) |
|
111 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#close() |
|
112 |
*/ |
|
113 |
public void close() throws IOException { |
|
114 |
// TODO Auto-generated method stub |
|
115 |
|
|
116 |
} |
|
117 |
|
|
118 |
/* |
|
119 |
* (non-Javadoc) |
|
120 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#initialize() |
|
121 |
*/ |
|
122 |
public void initialize() throws IOException { |
|
123 |
float heightText = 10; |
|
124 |
|
|
125 |
GMLFeaturesIterator iterator; |
|
126 |
try { |
|
127 |
iterator = GMLFeaturesParser.getFeatureReader(m_Fich); |
|
128 |
} catch (Exception e1) { |
|
129 |
e1.printStackTrace(); |
|
130 |
throw new IOException(e1.toString()); |
|
131 |
} |
|
132 |
|
|
133 |
defaultLegend = LegendFactory.createVectorialUniqueValueLegend(getShapeType()); |
|
134 |
defaultLegend.setFieldName("Color"); |
|
135 |
defaultLegend.setLabelField("Text"); |
|
136 |
defaultLegend.setDefaultSymbol(new FSymbol(getShapeType())); |
|
137 |
defaultLegend.getDefaultSymbol().setShapeVisible(false); |
|
138 |
defaultLegend.getDefaultSymbol().setFontSizeInPixels(false); |
|
139 |
defaultLegend.getDefaultSymbol().setFont(new Font("SansSerif", |
|
140 |
Font.PLAIN, 9)); |
|
141 |
defaultLegend.getDefaultSymbol().setFontColor(Color.BLACK); |
|
142 |
defaultLegend.getDefaultSymbol().setFontSize(heightText); |
|
143 |
defaultLegend.getDefaultSymbol().setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
|
144 |
defaultLegend.getDefaultSymbol().setSize(3); |
|
145 |
defaultLegend.getDefaultSymbol().setSizeInPixels(true); |
|
146 |
|
|
147 |
defaultLegend.setLabelHeightField("HeightText"); |
|
148 |
defaultLegend.setLabelRotationField("RotationText"); |
|
149 |
|
|
150 |
ArrayList arrayFields = iterator.getAttributeNames(); |
|
151 |
Value[] auxRow; |
|
152 |
if (arrayFields.size()<0){ |
|
153 |
auxRow = new Value[0]; |
|
154 |
}else{ |
|
155 |
auxRow = new Value[arrayFields.size()]; |
|
156 |
} |
|
157 |
|
|
158 |
int i=0; |
|
159 |
|
|
160 |
getTableModel().setColumnIdentifiers(arrayFields.toArray()); |
|
161 |
|
|
162 |
IntValue clave; |
|
163 |
FSymbol theSymbol = null; |
|
164 |
|
|
165 |
while (iterator.hasNext()) { |
|
166 |
IFeature feature; |
|
167 |
try { |
|
168 |
System.out.println("Recuperando feature num: " + i); |
|
169 |
feature = iterator.next(); |
|
170 |
|
|
171 |
clave = ValueFactory.createValue(i); |
|
172 |
IGeometry geom = feature.getGeometry(); |
|
173 |
FShape shape = (FShape)geom.getInternalShape(); |
|
174 |
|
|
175 |
theSymbol = new FSymbol(getShapeType()); |
|
176 |
theSymbol.setDescription(clave.toString()); |
|
177 |
theSymbol.setStyle(FConstant.SYMBOL_STYLE_DGNSPECIAL); |
|
178 |
theSymbol.setSize(3); |
|
179 |
theSymbol.setSizeInPixels(true); |
|
180 |
|
|
181 |
for (int k=0 ; k<auxRow.length ; k++){ |
|
182 |
auxRow[k] = feature.getAttribute(k); |
|
183 |
} |
|
184 |
|
|
185 |
addShape(shape, auxRow); |
|
186 |
defaultLegend.addSymbol(clave, theSymbol); |
|
187 |
|
|
188 |
i++; |
|
189 |
} catch (NoSuchElementException e) { |
|
190 |
// TODO Auto-generated catch block |
|
191 |
e.printStackTrace(); |
|
192 |
} catch (DriverException e) { |
|
193 |
// TODO Auto-generated catch block |
|
194 |
e.printStackTrace(); |
|
195 |
} |
|
196 |
} |
|
197 |
|
|
198 |
|
|
199 |
} |
|
200 |
|
|
201 |
|
|
202 |
/* |
|
203 |
* (non-Javadoc) |
|
204 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#accept(java.io.File) |
|
205 |
*/ |
|
206 |
public boolean accept(File f) { |
|
207 |
if ((f.getName().toUpperCase().endsWith("GML")) || |
|
208 |
(f.getName().toUpperCase().endsWith("XML"))){ |
|
209 |
return true; |
|
210 |
} |
|
211 |
return false; |
|
212 |
|
|
213 |
} |
|
214 |
|
|
215 |
/* |
|
216 |
* (non-Javadoc) |
|
217 |
* @see com.iver.cit.gvsig.fmap.drivers.VectorialFileDriver#getFile() |
|
218 |
*/ |
|
219 |
public File getFile() { |
|
220 |
return m_Fich; |
|
221 |
} |
|
222 |
|
|
223 |
/* |
|
224 |
* (non-Javadoc) |
|
225 |
* @see com.hardcode.driverManager.Driver#getName() |
|
226 |
*/ |
Also available in: Unified diff