Revision 329
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/java/org/gvsig/geoprocess/algorithm/xyshift/XYShiftOperation.java | ||
---|---|---|
53 | 53 |
import org.gvsig.fmap.geom.Geometry; |
54 | 54 |
import org.gvsig.fmap.geom.GeometryLocator; |
55 | 55 |
import org.gvsig.fmap.geom.GeometryManager; |
56 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
|
57 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
|
58 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
|
56 | 59 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
57 | 60 |
import org.gvsig.fmap.geom.primitive.Curve; |
58 | 61 |
import org.gvsig.fmap.geom.primitive.GeneralPathX; |
... | ... | |
87 | 90 |
public EditableFeature invoke(org.gvsig.fmap.geom.Geometry g, Feature feature) { |
88 | 91 |
List geomList = feature.getGeometries(); |
89 | 92 |
try { |
93 |
if(!persister.isCompatibleType(feature.getDefaultGeometry())) |
|
94 |
return lastEditFeature; |
|
95 |
|
|
90 | 96 |
if(geomList == null) { |
91 | 97 |
org.gvsig.fmap.geom.Geometry oldGeom = feature.getDefaultGeometry(); |
92 | 98 |
Geometry newGeom = shiftGeometry(oldGeom); |
... | ... | |
126 | 132 |
* @throws CreateGeometryException |
127 | 133 |
*/ |
128 | 134 |
private Geometry shiftGeometry(Geometry oldGeom) throws CreateGeometryException { |
129 |
Geometry newGeom = null; |
|
130 |
if(oldGeom.getType() == Geometry.TYPES.SURFACE || oldGeom.getType() == Geometry.TYPES.MULTISURFACE) |
|
131 |
newGeom = shiftSurface((Surface)oldGeom); |
|
132 |
if(oldGeom.getType() == Geometry.TYPES.CURVE || oldGeom.getType() == Geometry.TYPES.MULTICURVE) |
|
133 |
newGeom = shiftCurve((Curve)oldGeom); |
|
134 |
if(oldGeom.getType() == Geometry.TYPES.POINT || oldGeom.getType() == Geometry.TYPES.MULTIPOINT) |
|
135 |
newGeom = shiftPoint((Point)oldGeom); |
|
136 |
return newGeom; |
|
135 |
if(oldGeom.getType() == Geometry.TYPES.SURFACE) |
|
136 |
return shiftSurface((Surface)oldGeom); |
|
137 |
else if(oldGeom.getType() == Geometry.TYPES.MULTISURFACE) |
|
138 |
return shiftMultiSurface((MultiSurface)oldGeom); |
|
139 |
else if(oldGeom.getType() == Geometry.TYPES.CURVE) |
|
140 |
return shiftCurve((Curve)oldGeom); |
|
141 |
else if(oldGeom.getType() == Geometry.TYPES.MULTICURVE) |
|
142 |
return shiftMultiCurve((MultiCurve)oldGeom); |
|
143 |
else if(oldGeom.getType() == Geometry.TYPES.POINT) |
|
144 |
return shiftPoint((Point)oldGeom); |
|
145 |
else if(oldGeom.getType() == Geometry.TYPES.MULTIPOINT) |
|
146 |
return shiftMultiPoint((MultiPoint)oldGeom); |
|
147 |
return oldGeom; |
|
137 | 148 |
} |
138 | 149 |
|
139 | 150 |
/** |
... | ... | |
158 | 169 |
} |
159 | 170 |
|
160 | 171 |
/** |
172 |
* Shifts all coordinates in a multisurface |
|
173 |
* @param geom |
|
174 |
* @return |
|
175 |
* @throws CreateGeometryException |
|
176 |
*/ |
|
177 |
private MultiSurface shiftMultiSurface(MultiSurface geom) throws CreateGeometryException { |
|
178 |
MultiSurface surface = (MultiSurface)geometryManager.create(Geometry.TYPES.MULTISURFACE, geom.getGeometryType().getSubType()); |
|
179 |
for (int i = 0; i < geom.getPrimitivesNumber(); i++) { |
|
180 |
Surface s = geom.getSurfaceAt(i); |
|
181 |
shiftSurface(s); |
|
182 |
surface.addSurface(s); |
|
183 |
} |
|
184 |
return surface; |
|
185 |
} |
|
186 |
|
|
187 |
/** |
|
161 | 188 |
* Shifts all coordinates in a curve |
162 | 189 |
* @param geom |
163 | 190 |
* @return |
... | ... | |
179 | 206 |
} |
180 | 207 |
|
181 | 208 |
/** |
209 |
* Shifts all coordinates in a multicurve |
|
210 |
* @param geom |
|
211 |
* @return |
|
212 |
* @throws CreateGeometryException |
|
213 |
*/ |
|
214 |
private MultiCurve shiftMultiCurve(MultiCurve geom) throws CreateGeometryException { |
|
215 |
MultiCurve curve = (MultiCurve)geometryManager.create(Geometry.TYPES.MULTICURVE, geom.getGeometryType().getSubType()); |
|
216 |
for (int i = 0; i < geom.getPrimitivesNumber(); i++) { |
|
217 |
Curve c = geom.getCurveAt(i); |
|
218 |
shiftCurve(c); |
|
219 |
curve.addCurve(c); |
|
220 |
} |
|
221 |
return curve; |
|
222 |
} |
|
223 |
|
|
224 |
/** |
|
182 | 225 |
* Shifts a point |
183 | 226 |
* @param geom |
184 | 227 |
* @return |
... | ... | |
191 | 234 |
return point; |
192 | 235 |
} |
193 | 236 |
|
237 |
/** |
|
238 |
* Shifts all coordinates in a multisurface |
|
239 |
* @param geom |
|
240 |
* @return |
|
241 |
* @throws CreateGeometryException |
|
242 |
*/ |
|
243 |
private MultiPoint shiftMultiPoint(MultiPoint geom) throws CreateGeometryException { |
|
244 |
MultiPoint point = (MultiPoint)geometryManager.create(Geometry.TYPES.MULTIPOINT, geom.getGeometryType().getSubType()); |
|
245 |
for (int i = 0; i < geom.getPrimitivesNumber(); i++) { |
|
246 |
Point p = geom.getPointAt(i); |
|
247 |
shiftPoint(p); |
|
248 |
point.addPoint(p); |
|
249 |
} |
|
250 |
return point; |
|
251 |
} |
|
252 |
|
|
194 | 253 |
/* |
195 | 254 |
* (non-Javadoc) |
196 | 255 |
* @see org.gvsig.geoprocess.algorithm.base.core.GeometryOperation#invoke(org.gvsig.fmap.geom.Geometry, org.gvsig.fmap.dal.feature.EditableFeature) |
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.xyshift/src/main/java/org/gvsig/geoprocess/algorithm/xyshift/XYShiftAlgorithm.java | ||
---|---|---|
44 | 44 |
*/ |
45 | 45 |
public class XYShiftAlgorithm extends AbstractSextanteGeoProcess { |
46 | 46 |
|
47 |
public static final String RESULT = "RESULT"; |
|
48 |
public static final String LAYER = "LAYER"; |
|
49 |
public static final String CHECK = "CHECK"; |
|
50 |
public static final String X = "X"; |
|
51 |
public static final String Y = "Y"; |
|
47 |
public static final String RESULT_POL = "RESULT_POL"; |
|
48 |
public static final String RESULT_POINT = "RESULT_POINT"; |
|
49 |
public static final String RESULT_LINE = "RESULT_LINE"; |
|
50 |
public static final String LAYER = "LAYER"; |
|
51 |
public static final String CHECK = "CHECK"; |
|
52 |
public static final String X = "X"; |
|
53 |
public static final String Y = "Y"; |
|
52 | 54 |
|
53 | 55 |
/* |
54 | 56 |
* (non-Javadoc) |
... | ... | |
73 | 75 |
} catch (RepeatedParameterNameException e) { |
74 | 76 |
Sextante.addErrorToLog(e); |
75 | 77 |
} |
76 |
addOutputVectorLayer(RESULT, getTranslation("XY-Shift"), |
|
77 |
OutputVectorLayer.SHAPE_TYPE_UNDEFINED); |
|
78 |
addOutputVectorLayer(RESULT_POL, getTranslation("XYShift_polygon"), |
|
79 |
OutputVectorLayer.SHAPE_TYPE_POLYGON); |
|
80 |
addOutputVectorLayer(RESULT_LINE, getTranslation("XYShift_line"), |
|
81 |
OutputVectorLayer.SHAPE_TYPE_LINE); |
|
82 |
addOutputVectorLayer(RESULT_POINT, getTranslation("XYShift_point"), |
|
83 |
OutputVectorLayer.SHAPE_TYPE_POINT); |
|
78 | 84 |
} |
79 |
|
|
85 |
|
|
80 | 86 |
/* |
81 | 87 |
* (non-Javadoc) |
82 | 88 |
* @see es.unex.sextante.core.GeoAlgorithm#processAlgorithm() |
83 | 89 |
*/ |
84 | 90 |
public boolean processAlgorithm() throws GeoAlgorithmExecutionException { |
85 |
if(existsOutPutFile(XYShiftAlgorithm.RESULT, 0)) { |
|
91 |
if(existsOutPutFile(XYShiftAlgorithm.RESULT_POL, 0) || |
|
92 |
existsOutPutFile(XYShiftAlgorithm.RESULT_LINE, 0) || |
|
93 |
existsOutPutFile(XYShiftAlgorithm.RESULT_POINT, 0)) { |
|
86 | 94 |
throw new GeoAlgorithmExecutionException(getTranslation("file_exists")); |
87 | 95 |
} |
88 | 96 |
IVectorLayer layer = m_Parameters.getParameterValueAsVectorLayer(LAYER); |
... | ... | |
100 | 108 |
FeatureSet features = null; |
101 | 109 |
features = storeLayer.getFeatureSet(); |
102 | 110 |
FeatureType featureType = features.getDefaultFeatureType(); |
103 |
FeatureStore outFeatStore = |
|
104 |
buildOutPutStore(featureType, layer.getShapeType(), |
|
105 |
getTranslation("XYShift"), RESULT); |
|
106 | 111 |
|
107 |
GeometryOperation operation = new XYShiftOperation(x, y, this); |
|
108 |
operation.setTaskStatus(getStatus()); |
|
109 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true); |
|
112 |
if (isPolygon(storeLayer) || isUndefined(storeLayer)) { |
|
113 |
FeatureStore outFeatStore = |
|
114 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON, |
|
115 |
getTranslation("XYShift_polygon"), RESULT_POL); |
|
116 |
|
|
117 |
GeometryOperation operation = new XYShiftOperation(x, y, this); |
|
118 |
operation.setTaskStatus(getStatus()); |
|
119 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true); |
|
120 |
} else { |
|
121 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POLYGON, |
|
122 |
getTranslation("Null_polygon"), RESULT_POL); |
|
123 |
} |
|
124 |
|
|
125 |
if (isLine(storeLayer) || isUndefined(storeLayer)) { |
|
126 |
FeatureStore outFeatStore = |
|
127 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE, |
|
128 |
getTranslation("XYShift_line"), RESULT_LINE); |
|
129 |
|
|
130 |
GeometryOperation operation = new XYShiftOperation(x, y, this); |
|
131 |
operation.setTaskStatus(getStatus()); |
|
132 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true); |
|
133 |
} else { |
|
134 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_LINE, |
|
135 |
getTranslation("Null_line"), RESULT_LINE); |
|
136 |
} |
|
137 |
|
|
138 |
if (isPoint(storeLayer) || isUndefined(storeLayer)) { |
|
139 |
FeatureStore outFeatStore = |
|
140 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POINT, |
|
141 |
getTranslation("XYShift_point"), RESULT_POINT); |
|
142 |
|
|
143 |
GeometryOperation operation = new XYShiftOperation(x, y, this); |
|
144 |
operation.setTaskStatus(getStatus()); |
|
145 |
operation.computesFeatureOperation(storeLayer, outFeatStore, attrNames, selectedGeom, true); |
|
146 |
} else { |
|
147 |
buildOutPutStore(featureType, IVectorLayer.SHAPE_TYPE_POINT, |
|
148 |
getTranslation("Null_point"), RESULT_POINT); |
|
149 |
} |
|
110 | 150 |
} catch (DataException e) { |
111 | 151 |
Sextante.addErrorToLog(e); |
112 | 152 |
return false; |
org.gvsig.geoprocess/trunk/org.gvsig.geoprocess/org.gvsig.geoprocess.algorithm/org.gvsig.geoprocess.algorithm.base/src/main/java/org/gvsig/geoprocess/algorithm/base/core/DALFeaturePersister.java | ||
---|---|---|
561 | 561 |
return featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
562 | 562 |
} |
563 | 563 |
|
564 |
@SuppressWarnings("deprecation") |
|
565 |
public int getType() { |
|
566 |
if(store == null) |
|
567 |
return org.gvsig.fmap.geom.Geometry.TYPES.NULL; |
|
568 |
FeatureType featureType; |
|
569 |
try { |
|
570 |
featureType = store.getDefaultFeatureType(); |
|
571 |
} catch (DataException e) { |
|
572 |
return org.gvsig.fmap.geom.Geometry.TYPES.NULL; |
|
573 |
} |
|
574 |
int indexGeom = featureType.getDefaultGeometryAttributeIndex(); |
|
575 |
return featureType.getAttributeDescriptor(indexGeom).getGeometryType(); |
|
576 |
} |
|
577 |
|
|
578 |
public boolean isCompatibleType(org.gvsig.fmap.geom.Geometry geom) { |
|
579 |
if(store == null) |
|
580 |
return false; |
|
581 |
try { |
|
582 |
return acceptType(store, geom); |
|
583 |
} catch (ReadException e) { |
|
584 |
return false; |
|
585 |
} |
|
586 |
} |
|
587 |
|
|
564 | 588 |
/** |
565 | 589 |
* Gets the output FeatureStore |
566 | 590 |
* @return |
Also available in: Unified diff