Revision 23163 trunk/extensions/extTopology/src/com/iver/cit/gvsig/geoprocess/impl/referencing/fmap/ReferencingGeoprocess.java
ReferencingGeoprocess.java | ||
---|---|---|
42 | 42 |
* dac@iver.es |
43 | 43 |
*/ |
44 | 44 |
/* CVS MESSAGES: |
45 |
* |
|
46 |
* $Id: |
|
47 |
* $Log: |
|
48 |
*/ |
|
45 |
*
|
|
46 |
* $Id:
|
|
47 |
* $Log:
|
|
48 |
*/
|
|
49 | 49 |
package com.iver.cit.gvsig.geoprocess.impl.referencing.fmap; |
50 | 50 |
|
51 | 51 |
import java.rmi.server.UID; |
52 | 52 |
import java.util.Map; |
53 | 53 |
|
54 | 54 |
import org.apache.log4j.Logger; |
55 |
import org.geotools.referencefork.referencing.operation.transform.AbstractMathTransform; |
|
56 | 55 |
import org.gvsig.exceptions.BaseException; |
57 | 56 |
import org.gvsig.referencing.ReferencingUtil; |
58 | 57 |
import org.gvsig.topology.Messages; |
... | ... | |
62 | 61 |
|
63 | 62 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
64 | 63 |
import com.hardcode.gdbms.engine.values.Value; |
64 |
import com.iver.andami.PluginServices; |
|
65 | 65 |
import com.iver.cit.gvsig.drivers.featureiterators.FeatureBitsetIterator; |
66 | 66 |
import com.iver.cit.gvsig.exceptions.visitors.StartVisitorException; |
67 | 67 |
import com.iver.cit.gvsig.exceptions.visitors.StartWriterVisitorException; |
68 | 68 |
import com.iver.cit.gvsig.exceptions.visitors.StopVisitorException; |
69 |
import com.iver.cit.gvsig.fmap.MapContext; |
|
69 | 70 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
70 | 71 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
71 | 72 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
... | ... | |
73 | 74 |
import com.iver.cit.gvsig.fmap.drivers.ILayerDefinition; |
74 | 75 |
import com.iver.cit.gvsig.fmap.drivers.LayerDefinition; |
75 | 76 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
77 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
|
78 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
|
76 | 79 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
77 | 80 |
import com.iver.cit.gvsig.geoprocess.core.AbstractMonitorableGeoprocess; |
78 | 81 |
import com.iver.cit.gvsig.geoprocess.core.fmap.DefinitionUtils; |
79 | 82 |
import com.iver.cit.gvsig.geoprocess.core.fmap.FeaturePersisterProcessor2; |
80 | 83 |
import com.iver.cit.gvsig.geoprocess.core.fmap.GeoprocessException; |
84 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
|
81 | 85 |
import com.iver.utiles.swing.threads.CancellableProgressTask; |
82 | 86 |
|
83 | 87 |
/** |
84 | 88 |
* Geoprocess to spatial adjust or reference a vectorial layer |
89 |
* |
|
85 | 90 |
* @author Alvaro Zabala |
86 |
* |
|
91 |
*
|
|
87 | 92 |
*/ |
88 | 93 |
public class ReferencingGeoprocess extends AbstractMonitorableGeoprocess { |
89 | 94 |
private static Logger logger = Logger.getLogger(ReferencingGeoprocess.class |
90 | 95 |
.getName()); |
91 |
|
|
96 |
|
|
92 | 97 |
private LayerDefinition resultLayerDefinition; |
93 |
|
|
94 |
private /*Abstract*/MathTransform mathTransform; |
|
95 |
|
|
96 |
|
|
97 |
public ReferencingGeoprocess(FLyrVect inputLyr){ |
|
98 |
|
|
99 |
private MathTransform mathTransform; |
|
100 |
|
|
101 |
private boolean hasAuxiliarLyrs = false; |
|
102 |
|
|
103 |
private FLyrVect[] auxiliarLyrs = null; |
|
104 |
|
|
105 |
public ReferencingGeoprocess(FLyrVect inputLyr) { |
|
98 | 106 |
firstLayer = inputLyr; |
99 | 107 |
} |
100 |
|
|
108 |
|
|
101 | 109 |
@Override |
102 | 110 |
public void checkPreconditions() throws GeoprocessException { |
103 | 111 |
try { |
104 | 112 |
int numShapes = firstLayer.getSource().getShapeCount(); |
105 |
if(numShapes == 0) |
|
113 |
if (numShapes == 0)
|
|
106 | 114 |
throw new GeoprocessException("capa de entrada sin features"); |
107 | 115 |
} catch (ReadDriverException e) { |
108 |
throw new GeoprocessException("Error de driver al tratar de acceder al numero de elementos", e); |
|
116 |
throw new GeoprocessException( |
|
117 |
"Error de driver al tratar de acceder al numero de elementos", |
|
118 |
e); |
|
109 | 119 |
} |
110 |
|
|
111 |
if(mathTransform == null) |
|
112 |
throw new GeoprocessException("No se ha especificado un metodo de transformacion espacial"); |
|
120 |
|
|
121 |
if (mathTransform == null) |
|
122 |
throw new GeoprocessException( |
|
123 |
"No se ha especificado un metodo de transformacion espacial"); |
|
113 | 124 |
} |
114 | 125 |
|
115 | 126 |
@Override |
116 | 127 |
public ILayerDefinition createLayerDefinition() { |
117 |
if(resultLayerDefinition == null){
|
|
128 |
if (resultLayerDefinition == null) {
|
|
118 | 129 |
try { |
119 | 130 |
resultLayerDefinition = DefinitionUtils |
120 | 131 |
.createLayerDefinition(firstLayer); |
... | ... | |
125 | 136 |
return resultLayerDefinition; |
126 | 137 |
} |
127 | 138 |
|
128 |
|
|
129 | 139 |
@Override |
130 | 140 |
public void setParameters(Map params) throws GeoprocessException { |
131 |
mathTransform = (MathTransform) /*(AbstractMathTransform)*/ params.get("mathTransform"); |
|
141 |
mathTransform = (MathTransform) params.get("mathTransform"); |
|
142 |
hasAuxiliarLyrs = ((Boolean) params.get("hasAuxiliar")).booleanValue(); |
|
143 |
if(hasAuxiliarLyrs){ |
|
144 |
this.auxiliarLyrs = (FLyrVect[]) params.get("auxiliarLyrs"); |
|
145 |
} |
|
132 | 146 |
} |
133 | 147 |
|
134 | 148 |
@Override |
... | ... | |
139 | 153 |
int numOfSteps = firstLayer.getSource().getShapeCount(); |
140 | 154 |
progressMonitor.setFinalStep(numOfSteps); |
141 | 155 |
progressMonitor.setDeterminatedProcess(true); |
142 |
progressMonitor.setNote(Messages.getText("referencing_geoprocess_note")); |
|
156 |
progressMonitor.setNote(Messages |
|
157 |
.getText("referencing_geoprocess_note")); |
|
143 | 158 |
progressMonitor.setStatusMessage(Messages |
144 | 159 |
.getText("referencing_geoprocess_layer_message")); |
145 | 160 |
} catch (ReadDriverException e) { |
146 | 161 |
throw new GeoprocessException( |
147 | 162 |
"error accediendo al numero de features de una layer", e); |
148 | 163 |
} |
149 |
|
|
164 |
|
|
150 | 165 |
} |
151 | 166 |
|
152 | 167 |
@Override |
153 | 168 |
public void process(CancellableProgressTask progressMonitor) |
154 | 169 |
throws GeoprocessException { |
155 |
|
|
156 |
/* |
|
157 |
* ++++++++++++++++++++++++++ |
|
158 |
* FIXME: MOVER A CLASE ABSTRACTA |
|
159 |
* */ |
|
170 |
|
|
171 |
/* |
|
172 |
* ++++++++++++++++++++++++++ FIXME: MOVER A CLASE ABSTRACTA |
|
173 |
*/ |
|
160 | 174 |
if (progressMonitor != null) { |
161 | 175 |
initialize(progressMonitor); |
162 | 176 |
} |
... | ... | |
175 | 189 |
throw new GeoprocessException(e1); |
176 | 190 |
} |
177 | 191 |
|
178 |
/* |
|
179 |
* +++++++++++++++++ |
|
180 |
*/
|
|
181 |
|
|
192 |
/*
|
|
193 |
* +++++++++++++++++
|
|
194 |
*/
|
|
195 |
|
|
182 | 196 |
try { |
183 | 197 |
IFeatureIterator featureIterator = null; |
184 |
if(this.operateOnlyWithSelection){
|
|
198 |
if (this.operateOnlyWithSelection) {
|
|
185 | 199 |
FBitSet selection = firstLayer.getRecordset().getSelection(); |
186 |
featureIterator = new FeatureBitsetIterator(selection, firstLayer.getSource()); |
|
187 |
}else{ |
|
200 |
featureIterator = new FeatureBitsetIterator(selection, |
|
201 |
firstLayer.getSource()); |
|
202 |
} else { |
|
188 | 203 |
featureIterator = firstLayer.getSource().getFeatureIterator(); |
189 | 204 |
} |
190 |
|
|
191 |
while(featureIterator.hasNext()){
|
|
205 |
|
|
206 |
while (featureIterator.hasNext()) {
|
|
192 | 207 |
IFeature feature = featureIterator.next(); |
193 | 208 |
IGeometry fmapGeo = feature.getGeometry(); |
194 | 209 |
Value[] values = feature.getAttributes(); |
195 |
IGeometry transformedGeometry = ReferencingUtil.getInstance(). |
|
196 |
createTransformedGeometry(fmapGeo, |
|
197 |
null, |
|
198 |
null, |
|
199 |
this.mathTransform); |
|
200 |
if(progressMonitor != null) |
|
210 |
IGeometry transformedGeometry = ReferencingUtil.getInstance() |
|
211 |
.createTransformedGeometry(fmapGeo, null, null, |
|
212 |
this.mathTransform); |
|
213 |
if (progressMonitor != null) |
|
201 | 214 |
progressMonitor.reportStep(); |
202 |
|
|
203 |
if(transformedGeometry != null){ |
|
204 |
DefaultFeature newFeature = |
|
205 |
new DefaultFeature(transformedGeometry, |
|
206 |
values, |
|
207 |
new UID().toString()); |
|
215 |
|
|
216 |
if (transformedGeometry != null) { |
|
217 |
DefaultFeature newFeature = new DefaultFeature( |
|
218 |
transformedGeometry, values, new UID().toString()); |
|
208 | 219 |
featureProcessor.processFeature(newFeature); |
209 | 220 |
} |
210 |
}//while |
|
221 |
}// while
|
|
211 | 222 |
featureProcessor.finish(); |
212 | 223 |
if (progressMonitor != null) { |
213 | 224 |
progressMonitor.finished(); |
... | ... | |
221 | 232 |
"Error al acceder a la informacion del driver dentro del geoproceso", |
222 | 233 |
e); |
223 | 234 |
} catch (TransformException e) { |
224 |
throw new GeoprocessException("Error de transformacion de coordenadas", e); |
|
235 |
throw new GeoprocessException( |
|
236 |
"Error de transformacion de coordenadas", e); |
|
225 | 237 |
} catch (FactoryException e) { |
226 |
throw new GeoprocessException("Error al tratar de construir una transformacion de coordenadas", e); |
|
238 |
throw new GeoprocessException( |
|
239 |
"Error al tratar de construir una transformacion de coordenadas", |
|
240 |
e); |
|
241 |
} |
|
242 |
|
|
243 |
} |
|
244 |
|
|
245 |
@Override |
|
246 |
public FLayer getResult() throws GeoprocessException { |
|
247 |
MapContext map = ((View) PluginServices.getMDIManager() |
|
248 |
.getActiveWindow()).getModel().getMapContext(); |
|
249 |
|
|
250 |
// first of all, we look for an existing flayers container |
|
251 |
FLayers rootLyrs = map.getLayers(); |
|
252 |
String folderName = PluginServices.getText(this, |
|
253 |
"SPATIAL_ADJUST_SESSION") |
|
254 |
+ " " |
|
255 |
+ ReferencingUtil.getInstance() |
|
256 |
.getNumberOfSpatialAdjustSessions(); |
|
257 |
FLayers adjustSessionLyrs = (FLayers) rootLyrs.getLayer(folderName); |
|
258 |
if (adjustSessionLyrs == null){ |
|
259 |
adjustSessionLyrs = new FLayers(); |
|
260 |
adjustSessionLyrs.setMapContext(map); |
|
261 |
adjustSessionLyrs.setParentLayer(map.getLayers()); |
|
262 |
adjustSessionLyrs.setName(folderName); |
|
263 |
System.err.println("Error, geoproceso ajuste espacial sin capa de links"); |
|
264 |
} |
|
265 |
if (hasAuxiliarLyrs && auxiliarLyrs != null) { |
|
266 |
int position = 0; |
|
267 |
for (int i = 0; i < auxiliarLyrs.length; i++) { |
|
268 |
adjustSessionLyrs.addLayer(position, auxiliarLyrs[i]); |
|
269 |
position++; |
|
270 |
} |
|
227 | 271 |
} |
228 | 272 |
|
273 |
adjustSessionLyrs.addLayer(super.getResult()); |
|
274 |
|
|
275 |
map.invalidate(); |
|
276 |
return adjustSessionLyrs; |
|
229 | 277 |
} |
230 | 278 |
|
231 | 279 |
} |
Also available in: Unified diff