Revision 64 org.gvsig.sextante/trunk/org.gvsig.sextante.app/org.gvsig.sextante.app.algorithm/org.gvsig.sextante.app.algorithm.spatialjoin/src/main/java/org/gvsig/sextante/app/algorithm/spatialjoin/SpatialJoinAlgorithm.java
SpatialJoinAlgorithm.java | ||
---|---|---|
18 | 18 |
*/ |
19 | 19 |
package org.gvsig.sextante.app.algorithm.spatialjoin; |
20 | 20 |
|
21 |
import java.util.ArrayList; |
|
21 | 22 |
import java.util.HashMap; |
23 |
import java.util.Iterator; |
|
22 | 24 |
|
23 | 25 |
import org.gvsig.fmap.dal.DALLocator; |
24 | 26 |
import org.gvsig.fmap.dal.DataManager; |
... | ... | |
27 | 29 |
import org.gvsig.fmap.dal.feature.FeatureSet; |
28 | 30 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
29 | 31 |
import org.gvsig.fmap.dal.feature.FeatureType; |
30 |
import org.gvsig.sextante.app.algorithm.spatialjoin.SpatiallyIndexedSpatialJoinOperation; |
|
32 |
import org.gvsig.sextante.app.algorithm.base.core.GeometryOperation; |
|
33 |
import org.gvsig.sextante.app.algorithm.dissolve.DissolveRule; |
|
34 |
import org.gvsig.sextante.app.algorithm.dissolve.IDissolveRule; |
|
35 |
import org.gvsig.sextante.app.algorithm.dissolve.Summary; |
|
31 | 36 |
import org.gvsig.sextante.app.extension.core.gvGeoAlgorithm; |
32 | 37 |
import org.gvsig.sextante.app.extension.core.gvVectorLayer; |
33 | 38 |
|
... | ... | |
35 | 40 |
import es.unex.sextante.dataObjects.IVectorLayer; |
36 | 41 |
import es.unex.sextante.exceptions.GeoAlgorithmExecutionException; |
37 | 42 |
import es.unex.sextante.exceptions.RepeatedParameterNameException; |
43 |
import es.unex.sextante.exceptions.UnsupportedOutputChannelException; |
|
38 | 44 |
import es.unex.sextante.outputs.OutputVectorLayer; |
39 | 45 |
|
40 | 46 |
/** |
... | ... | |
120 | 126 |
|
121 | 127 |
//Builds the output and computes the operation |
122 | 128 |
try { |
129 |
FeatureSet features = null; |
|
130 |
features = lyr1.getFeatureStore().getFeatureSet(); |
|
131 |
FeatureType featureType1 = features.getDefaultFeatureType(); |
|
132 |
features = lyr2.getFeatureStore().getFeatureSet(); |
|
133 |
FeatureType featureType2 = features.getDefaultFeatureType(); |
|
134 |
|
|
135 |
GeometryOperation operation = null; |
|
136 |
FeatureStore outFeatStore = null; |
|
137 |
|
|
123 | 138 |
if(nearest) { |
124 |
FeatureSet features = null; |
|
125 |
features = lyr1.getFeatureStore().getFeatureSet(); |
|
126 |
FeatureType featureType1 = features.getDefaultFeatureType(); |
|
127 |
features = lyr2.getFeatureStore().getFeatureSet(); |
|
128 |
FeatureType featureType2 = features.getDefaultFeatureType(); |
|
129 |
|
|
130 |
FeatureStore outFeatStore = buildOutPutStoreFromUnion(featureType1, |
|
139 |
outFeatStore = buildOutPutStoreFromUnion(featureType1, |
|
131 | 140 |
featureType2, |
132 | 141 |
lyr1.getShapeType(), |
133 | 142 |
Sextante.getText("SpatialJoin"), |
... | ... | |
135 | 144 |
"DIST", |
136 | 145 |
Double.class); |
137 | 146 |
|
138 |
SpatiallyIndexedSpatialJoinOperation operation = new SpatiallyIndexedSpatialJoinOperation(lyr2, indexName + "_idx"); |
|
139 |
operation.setProgressModel(this); |
|
140 |
operation.computesGeometryOperation(lyr1.getFeatureStore(), |
|
141 |
outFeatStore, |
|
142 |
attrNames, |
|
143 |
selectedGeom, |
|
144 |
true); |
|
147 |
operation = new SpatiallyIndexedSpatialJoinOperation(lyr2, indexName + "_idx"); |
|
148 |
} else { |
|
149 |
outFeatStore = buildSpatialJoinOutPutStore(featureType1, |
|
150 |
lyr1.getShapeType(), |
|
151 |
Sextante.getText("SpatialJoin"), |
|
152 |
RESULT); |
|
153 |
IDissolveRule rule = new DissolveRule(0, funcMap); |
|
154 |
Summary summary = new Summary(rule, outFeatStore.getDefaultFeatureType()); |
|
155 |
//summary.loadDefaultSummarizes(this.feature); |
|
156 |
operation = new IntersectsSpatialJoinOperation(lyr2, indexName + "_idx", summary); |
|
145 | 157 |
} |
158 |
|
|
159 |
operation.setProgressModel(this); |
|
160 |
operation.computesGeometryOperation(lyr1.getFeatureStore(), |
|
161 |
outFeatStore, |
|
162 |
attrNames, |
|
163 |
selectedGeom, |
|
164 |
true); |
|
146 | 165 |
} catch (DataException e) { |
147 | 166 |
Sextante.addErrorToLog(e); |
148 | 167 |
} |
... | ... | |
181 | 200 |
} |
182 | 201 |
} |
183 | 202 |
|
203 |
/** |
|
204 |
* Builds the output FeatureStore |
|
205 |
* @param featureType |
|
206 |
* @return FeatureStore |
|
207 |
*/ |
|
208 |
@SuppressWarnings("unchecked") |
|
209 |
protected FeatureStore buildSpatialJoinOutPutStore(FeatureType featureType1, |
|
210 |
int shapeType, |
|
211 |
String sextanteLayerName, |
|
212 |
String sextanteLayerLabel) { |
|
213 |
ArrayList<Class> typesList = new ArrayList<Class>(); |
|
214 |
ArrayList<String> attr = new ArrayList<String>(); |
|
215 |
|
|
216 |
Iterator it = featureType1.iterator(); |
|
217 |
while( it.hasNext() ) { |
|
218 |
FeatureAttributeDescriptor attribute = (FeatureAttributeDescriptor)it.next(); |
|
219 |
if(attribute.getName().compareTo("GEOMETRY") != 0) { |
|
220 |
attr.add(attribute.getName()); |
|
221 |
typesList.add(attribute.getObjectClass()); |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
for (int i = 0; i < funcList.length; i++) { |
|
226 |
if(funcList[i]) { |
|
227 |
String fieldName = funcMap.get(Summary[i]); |
|
228 |
if(fieldName.length() >= 6) |
|
229 |
fieldName = fieldName.substring(0, 7); |
|
230 |
attr.add(fieldName + "_" + Summary[i]); |
|
231 |
typesList.add(Double.class); |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
attr.add("NUM_RELA"); |
|
236 |
typesList.add(Integer.class); |
|
237 |
|
|
238 |
attrNames = new String[attr.size()]; |
|
239 |
attr.toArray(attrNames); |
|
240 |
Class[] types = new Class[typesList.size()]; |
|
241 |
typesList.toArray(types); |
|
242 |
|
|
243 |
try { |
|
244 |
IVectorLayer output = getNewVectorLayer(sextanteLayerLabel, |
|
245 |
sextanteLayerName, |
|
246 |
shapeType, types, attrNames); |
|
247 |
return ((gvVectorLayer)output).getFeatureStore(); |
|
248 |
} catch (UnsupportedOutputChannelException e) { |
|
249 |
Sextante.addErrorToLog(e); |
|
250 |
} |
|
251 |
return null; |
|
252 |
} |
|
253 |
|
|
184 | 254 |
} |
Also available in: Unified diff