root / trunk / extensions / extGeoProcessing / src / com / iver / cit / gvsig / geoprocess / merge / fmap / MergeVisitor.java @ 5628
History | View | Annotate | Download (4.92 KB)
1 |
/*
|
---|---|
2 |
* Created on 05-mar-2006
|
3 |
*
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
5 |
*
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
7 |
*
|
8 |
* This program is free software; you can redistribute it and/or
|
9 |
* modify it under the terms of the GNU General Public License
|
10 |
* as published by the Free Software Foundation; either version 2
|
11 |
* of the License, or (at your option) any later version.
|
12 |
*
|
13 |
* This program is distributed in the hope that it will be useful,
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
16 |
* GNU General Public License for more details.
|
17 |
*
|
18 |
* You should have received a copy of the GNU General Public License
|
19 |
* along with this program; if not, write to the Free Software
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
21 |
*
|
22 |
* For more information, contact:
|
23 |
*
|
24 |
* Generalitat Valenciana
|
25 |
* Conselleria d'Infraestructures i Transport
|
26 |
* Av. Blasco Ib??ez, 50
|
27 |
* 46010 VALENCIA
|
28 |
* SPAIN
|
29 |
*
|
30 |
* +34 963862235
|
31 |
* gvsig@gva.es
|
32 |
* www.gvsig.gva.es
|
33 |
*
|
34 |
* or
|
35 |
*
|
36 |
* IVER T.I. S.A
|
37 |
* Salamanca 50
|
38 |
* 46005 Valencia
|
39 |
* Spain
|
40 |
*
|
41 |
* +34 963163400
|
42 |
* dac@iver.es
|
43 |
*/
|
44 |
/* CVS MESSAGES:
|
45 |
*
|
46 |
* $Id: MergeVisitor.java 5628 2006-06-02 18:21:28Z azabala $
|
47 |
* $Log$
|
48 |
* Revision 1.2 2006-06-02 18:21:28 azabala
|
49 |
* *** empty log message ***
|
50 |
*
|
51 |
* Revision 1.1 2006/05/24 21:10:15 azabala
|
52 |
* primera version en cvs despues de refactoring orientado a crear un framework extensible de geoprocessing
|
53 |
*
|
54 |
* Revision 1.5 2006/03/23 21:05:11 azabala
|
55 |
* *** empty log message ***
|
56 |
*
|
57 |
* Revision 1.4 2006/03/17 19:53:34 azabala
|
58 |
* *** empty log message ***
|
59 |
*
|
60 |
* Revision 1.3 2006/03/14 18:32:46 fjp
|
61 |
* Cambio con LayerDefinition para que sea compatible con la definici?n de tablas tambi?n.
|
62 |
*
|
63 |
* Revision 1.2 2006/03/07 21:01:33 azabala
|
64 |
* *** empty log message ***
|
65 |
*
|
66 |
* Revision 1.1 2006/03/05 19:59:16 azabala
|
67 |
* *** empty log message ***
|
68 |
*
|
69 |
*
|
70 |
*/
|
71 |
package com.iver.cit.gvsig.geoprocess.merge.fmap; |
72 |
|
73 |
import com.hardcode.gdbms.engine.values.Value; |
74 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
75 |
import com.iver.cit.gvsig.fmap.DriverException; |
76 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
77 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
78 |
import com.iver.cit.gvsig.fmap.drivers.FieldDescription; |
79 |
import com.iver.cit.gvsig.fmap.drivers.ITableDefinition; |
80 |
import com.iver.cit.gvsig.fmap.edition.EditionException; |
81 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
82 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
83 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.AlphanumericData; |
84 |
import com.iver.cit.gvsig.fmap.layers.layerOperations.VectorialData; |
85 |
import com.iver.cit.gvsig.fmap.operations.strategies.FeatureVisitor; |
86 |
import com.iver.cit.gvsig.fmap.operations.strategies.VisitException; |
87 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeatureFactory; |
88 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeatureProcessor; |
89 |
|
90 |
/**
|
91 |
* Visits all features of a layer, in context of a
|
92 |
* merge geoprocess, and creates a new feature with the
|
93 |
* attributes equals to ITableDefinition specified
|
94 |
*
|
95 |
* @author azabala
|
96 |
*
|
97 |
*/
|
98 |
public class MergeVisitor implements FeatureVisitor { |
99 |
|
100 |
SelectableDataSource recordset; |
101 |
ITableDefinition definition; |
102 |
FeatureProcessor featureProcessor; |
103 |
|
104 |
public MergeVisitor(ITableDefinition schema,
|
105 |
FeatureProcessor processor){ |
106 |
this.definition = schema;
|
107 |
this.featureProcessor = processor;
|
108 |
} |
109 |
|
110 |
public void visit(IGeometry g, int index) throws VisitException { |
111 |
if(g == null) |
112 |
return;
|
113 |
FieldDescription[] fields =
|
114 |
definition.getFieldsDesc(); |
115 |
Value[] values = new Value[fields.length]; |
116 |
for(int i = 0; i < fields.length; i++){ |
117 |
String fieldName = fields[i].getFieldName();
|
118 |
try {
|
119 |
int fieldIndex = recordset.getFieldIndexByName(fieldName);
|
120 |
if(fieldIndex == -1) |
121 |
values[i] = ValueFactory.createNullValue(); |
122 |
else{
|
123 |
//we must to verify data type, not only field name
|
124 |
int fieldType = fields[i].getFieldType();
|
125 |
int recordsetType = recordset.getFieldType(fieldIndex);
|
126 |
if(fieldType != recordsetType){
|
127 |
values[i] = ValueFactory.createNullValue(); |
128 |
}else{
|
129 |
values[i] = recordset.getFieldValue(index, fieldIndex); |
130 |
} |
131 |
} |
132 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
133 |
throw new VisitException("Error en merge al tratar de leer el atributo de un feature de una de las capas"); |
134 |
} |
135 |
}//for
|
136 |
IFeature feature = FeatureFactory.createFeature(values, g); |
137 |
featureProcessor.processFeature(feature); |
138 |
} |
139 |
|
140 |
public void stop(FLayer layer) { |
141 |
featureProcessor.finish(); |
142 |
} |
143 |
|
144 |
public boolean start(FLayer layer) { |
145 |
if(layer instanceof VectorialData && layer instanceof AlphanumericData){ |
146 |
try {
|
147 |
this.recordset = ((AlphanumericData)layer).getRecordset();
|
148 |
this.featureProcessor.start();
|
149 |
} catch (DriverException e) {
|
150 |
return false; |
151 |
} catch (EditionException e) {
|
152 |
return false; |
153 |
} |
154 |
return true; |
155 |
} |
156 |
return false; |
157 |
} |
158 |
|
159 |
public String getProcessDescription() { |
160 |
return "Merging many layers"; |
161 |
} |
162 |
|
163 |
} |
164 |
|