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
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) |
Also available in: Unified diff