gvsig-vectorediting / org.gvsig.vectorediting.offset / trunk / org.gvsig.vectorediting.offset / org.gvsig.vectorediting.offset.lib / org.gvsig.vectorediting.offset.lib.prov / org.gvsig.vectorediting.offset.lib.prov.offset / src / main / java / org / gvsig / vectorediting / offset / lib / prov / offset / OffsetEditingProvider.java @ 577
History | View | Annotate | Download (23.3 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright ? 2007-2014 gvSIG Association
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.vectorediting.offset.lib.prov.offset; |
26 |
|
27 |
import java.awt.geom.AffineTransform; |
28 |
import java.util.ArrayList; |
29 |
import java.util.HashMap; |
30 |
import java.util.LinkedHashMap; |
31 |
import java.util.List; |
32 |
import java.util.Map; |
33 |
|
34 |
import org.apache.commons.lang3.mutable.MutableDouble; |
35 |
import org.gvsig.fmap.dal.exception.DataException; |
36 |
import org.gvsig.fmap.dal.feature.EditableFeature; |
37 |
import org.gvsig.fmap.dal.feature.Feature; |
38 |
import org.gvsig.fmap.dal.feature.FeatureSelection; |
39 |
import org.gvsig.fmap.dal.feature.FeatureStore; |
40 |
import org.gvsig.fmap.geom.Geometry; |
41 |
import org.gvsig.fmap.geom.GeometryLocator; |
42 |
import org.gvsig.fmap.geom.GeometryManager; |
43 |
import org.gvsig.fmap.geom.aggregate.Aggregate; |
44 |
import org.gvsig.fmap.geom.aggregate.MultiCurve; |
45 |
import org.gvsig.fmap.geom.aggregate.MultiPoint; |
46 |
import org.gvsig.fmap.geom.aggregate.MultiSurface; |
47 |
import org.gvsig.fmap.geom.exception.CreateEnvelopeException; |
48 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
49 |
import org.gvsig.fmap.geom.operation.GeometryOperationException; |
50 |
import org.gvsig.fmap.geom.operation.GeometryOperationNotSupportedException; |
51 |
import org.gvsig.fmap.geom.primitive.Circle; |
52 |
import org.gvsig.fmap.geom.primitive.Circumference; |
53 |
import org.gvsig.fmap.geom.primitive.Curve; |
54 |
import org.gvsig.fmap.geom.primitive.Ellipse; |
55 |
import org.gvsig.fmap.geom.primitive.Envelope; |
56 |
import org.gvsig.fmap.geom.primitive.Line; |
57 |
import org.gvsig.fmap.geom.primitive.OrientablePrimitive; |
58 |
import org.gvsig.fmap.geom.primitive.PeriEllipse; |
59 |
import org.gvsig.fmap.geom.primitive.Point; |
60 |
import org.gvsig.fmap.geom.primitive.Polygon; |
61 |
import org.gvsig.fmap.geom.primitive.Surface; |
62 |
import org.gvsig.fmap.mapcontext.rendering.symbols.ISymbol; |
63 |
import org.gvsig.tools.ToolsLocator; |
64 |
import org.gvsig.tools.dispose.DisposableIterator; |
65 |
import org.gvsig.tools.dynobject.DynObject; |
66 |
import org.gvsig.tools.i18n.I18nManager; |
67 |
import org.gvsig.tools.locator.LocatorException; |
68 |
import org.gvsig.tools.service.spi.ProviderServices; |
69 |
import org.gvsig.vectorediting.lib.api.DrawingStatus; |
70 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter; |
71 |
import org.gvsig.vectorediting.lib.api.EditingServiceParameter.TYPE; |
72 |
import org.gvsig.vectorediting.lib.api.exceptions.DrawServiceException; |
73 |
import org.gvsig.vectorediting.lib.api.exceptions.FinishServiceException; |
74 |
import org.gvsig.vectorediting.lib.api.exceptions.InvalidEntryException; |
75 |
import org.gvsig.vectorediting.lib.api.exceptions.StartServiceException; |
76 |
import org.gvsig.vectorediting.lib.spi.AbstractEditingProvider; |
77 |
import org.gvsig.vectorediting.lib.spi.DefaultDrawingStatus; |
78 |
import org.gvsig.vectorediting.lib.spi.DefaultEditingServiceParameter; |
79 |
import org.gvsig.vectorediting.lib.spi.EditingProvider; |
80 |
import org.gvsig.vectorediting.lib.spi.EditingProviderFactory; |
81 |
import org.gvsig.vectorediting.lib.spi.EditingProviderLocator; |
82 |
import org.gvsig.vectorediting.lib.spi.EditingProviderManager; |
83 |
import org.gvsig.vectorediting.lib.spi.EditingProviderServices; |
84 |
|
85 |
public class OffsetEditingProvider extends AbstractEditingProvider implements |
86 |
EditingProvider { |
87 |
|
88 |
private final Double PRECISION=new Double(1.0e-5); |
89 |
|
90 |
private I18nManager i18nManager = ToolsLocator.getI18nManager();
|
91 |
|
92 |
private EditingServiceParameter selectionParameter;
|
93 |
|
94 |
private EditingServiceParameter pointParameter;
|
95 |
|
96 |
private Map<EditingServiceParameter, Object> values; |
97 |
|
98 |
private FeatureStore featureStore;
|
99 |
|
100 |
public OffsetEditingProvider(ProviderServices providerServices,
|
101 |
DynObject parameters) { |
102 |
super(providerServices);
|
103 |
this.featureStore =
|
104 |
(FeatureStore) parameters |
105 |
.getDynValue(EditingProviderFactory.FEATURE_STORE_FIELD); |
106 |
|
107 |
this.selectionParameter =
|
108 |
new DefaultEditingServiceParameter("selection", |
109 |
i18nManager.getTranslation("selection"), TYPE.SELECTION);
|
110 |
|
111 |
this.pointParameter =
|
112 |
new DefaultEditingServiceParameter("offset_distance", |
113 |
i18nManager.getTranslation("offset_distance"),
|
114 |
TYPE.POSITION); |
115 |
} |
116 |
|
117 |
public EditingServiceParameter next() {
|
118 |
|
119 |
if (values.get(selectionParameter) == null) { |
120 |
return selectionParameter;
|
121 |
} else if (values.get(pointParameter) == null) { |
122 |
return pointParameter;
|
123 |
} |
124 |
return null; |
125 |
} |
126 |
|
127 |
public DrawingStatus getDrawingStatus(Point mousePosition) |
128 |
throws DrawServiceException {
|
129 |
DefaultDrawingStatus drawingStatus = new DefaultDrawingStatus();
|
130 |
EditingProviderManager editingProviderManager = |
131 |
EditingProviderLocator.getProviderManager(); |
132 |
ISymbol auxiliaryLineSymbolEditing = editingProviderManager.getSymbol("auxiliary-line-symbol-editing");
|
133 |
ISymbol auxiliaryPointSymbolEditing = editingProviderManager.getSymbol("auxiliary-point-symbol-editing");
|
134 |
ISymbol lineSymbolEditing = editingProviderManager.getSymbol("line-symbol-editing");
|
135 |
ISymbol polygonSymbolEditing = editingProviderManager.getSymbol("polygon-symbol-editing");
|
136 |
|
137 |
|
138 |
FeatureSelection selected = |
139 |
(FeatureSelection) values.get(selectionParameter); |
140 |
try {
|
141 |
if ((selected != null) && !selected.isEmpty()) { |
142 |
Point point=null; |
143 |
Object pointValue = (Point) values.get(pointParameter); |
144 |
if ((pointValue != null) && (pointValue instanceof Point)) { |
145 |
point=(Point)pointValue;
|
146 |
}else{
|
147 |
point=mousePosition; |
148 |
Line line;
|
149 |
line = |
150 |
GeometryLocator.getGeometryManager().createLine( |
151 |
featureStore.getDefaultFeatureType() |
152 |
.getDefaultGeometryAttribute().getGeomType() |
153 |
.getSubType()); |
154 |
Point closestPoint=getClosestPoint(point,selected);
|
155 |
//TODO
|
156 |
Point perpendicularPoint=null; |
157 |
MutableDouble normalModule=new MutableDouble();
|
158 |
try {
|
159 |
perpendicularPoint=getPerpendicularPoint(closestPoint, point,selected,normalModule); |
160 |
//normalModule=getNormalModule(closestPoint, point,selected);
|
161 |
} catch (Exception e) { |
162 |
throw new DrawServiceException(e); |
163 |
} |
164 |
line.addVertex(closestPoint); |
165 |
//line.addVertex(point);
|
166 |
line.addVertex(perpendicularPoint); |
167 |
|
168 |
drawingStatus.addStatus(line, auxiliaryLineSymbolEditing, "");
|
169 |
|
170 |
AffineTransform at;
|
171 |
try {
|
172 |
at = getSymmetryAffineTransform(normalModule.getValue()); |
173 |
} catch (Exception e) { |
174 |
throw new DrawServiceException(e); |
175 |
} |
176 |
|
177 |
DisposableIterator it; |
178 |
it = selected.fastIterator(); |
179 |
|
180 |
while (it.hasNext()) {
|
181 |
Feature feat = (Feature) it.next(); |
182 |
Geometry transformedGeometry = feat.getDefaultGeometry().cloneGeometry(); |
183 |
transformedGeometry.transform(at); |
184 |
|
185 |
ISymbol symbol=null;
|
186 |
if(transformedGeometry instanceof Curve || transformedGeometry instanceof MultiCurve){ |
187 |
symbol = lineSymbolEditing; |
188 |
} else if(transformedGeometry instanceof Surface || transformedGeometry instanceof MultiSurface){ |
189 |
symbol = polygonSymbolEditing; |
190 |
} else if(transformedGeometry instanceof Point || transformedGeometry instanceof MultiPoint){ |
191 |
symbol = auxiliaryPointSymbolEditing; |
192 |
} |
193 |
if(transformedGeometry instanceof Aggregate){ |
194 |
int primitivesNumber = ((Aggregate)transformedGeometry).getPrimitivesNumber();
|
195 |
for (int i = 0; i < primitivesNumber; i++) { |
196 |
drawingStatus.addStatus(((Aggregate)transformedGeometry).getPrimitiveAt(i), symbol, "");
|
197 |
} |
198 |
} else {
|
199 |
drawingStatus.addStatus(transformedGeometry, symbol, "");
|
200 |
} |
201 |
} |
202 |
it.dispose(); |
203 |
} |
204 |
return drawingStatus;
|
205 |
} |
206 |
} catch (Exception e) { |
207 |
throw new DrawServiceException(e); |
208 |
} |
209 |
return null; |
210 |
} |
211 |
|
212 |
private AffineTransform getSymmetryAffineTransform(Double distance) |
213 |
throws GeometryOperationNotSupportedException,
|
214 |
GeometryOperationException { |
215 |
|
216 |
AffineTransform translate =
|
217 |
AffineTransform.getTranslateInstance(distance,
|
218 |
0);
|
219 |
|
220 |
return translate;
|
221 |
} |
222 |
|
223 |
|
224 |
public void stop() { |
225 |
values.clear(); |
226 |
} |
227 |
|
228 |
private void validateAndInsertValue(EditingServiceParameter param, |
229 |
Object value) throws InvalidEntryException { |
230 |
if (param == selectionParameter) {
|
231 |
if (value instanceof FeatureSelection) { |
232 |
values.put(param, value); |
233 |
return;
|
234 |
} |
235 |
} else if (param == pointParameter) { |
236 |
if (value instanceof Point) { |
237 |
values.put(param, value); |
238 |
return;
|
239 |
} |
240 |
} |
241 |
} |
242 |
|
243 |
public List<EditingServiceParameter> getParameters() { |
244 |
List<EditingServiceParameter> list =
|
245 |
new ArrayList<EditingServiceParameter>(); |
246 |
list.add(selectionParameter); |
247 |
list.add(pointParameter); |
248 |
return list;
|
249 |
} |
250 |
|
251 |
public void setValue(Object value) throws InvalidEntryException { |
252 |
EditingServiceParameter param = next(); |
253 |
validateAndInsertValue(param, value); |
254 |
} |
255 |
|
256 |
public void finishAndStore() throws FinishServiceException { |
257 |
|
258 |
FeatureSelection selected = |
259 |
(FeatureSelection) values.get(selectionParameter); |
260 |
try {
|
261 |
if (!selected.isEmpty()) {
|
262 |
Point point = (Point) values.get(pointParameter); |
263 |
if ((point != null)) { |
264 |
|
265 |
Double distance;
|
266 |
try {
|
267 |
Point closestPoint=getClosestPoint(point,selected);
|
268 |
distance = point.distance(closestPoint); |
269 |
} catch (GeometryOperationNotSupportedException e1) {
|
270 |
throw new FinishServiceException(e1); |
271 |
} catch (GeometryOperationException e1) {
|
272 |
throw new FinishServiceException(e1); |
273 |
} |
274 |
|
275 |
AffineTransform at;
|
276 |
try {
|
277 |
at = getSymmetryAffineTransform(distance); |
278 |
} catch (GeometryOperationNotSupportedException e) {
|
279 |
throw new FinishServiceException(e); |
280 |
} catch (GeometryOperationException e) {
|
281 |
throw new FinishServiceException(e); |
282 |
} |
283 |
|
284 |
DisposableIterator it; |
285 |
it = selected.fastIterator(); |
286 |
|
287 |
while (it.hasNext()) {
|
288 |
Feature feature = (Feature) it.next(); |
289 |
Geometry geom = |
290 |
feature.getDefaultGeometry().cloneGeometry(); |
291 |
geom.transform(at); |
292 |
|
293 |
// Se crea una feature nueva copiando los valores de
|
294 |
// la feature original excepto aquellos que sean PK
|
295 |
EditingProviderServices editingProviderServices = |
296 |
(EditingProviderServices) getProviderServices(); |
297 |
EditableFeature editableFeature = |
298 |
editingProviderServices |
299 |
.getFeatureCopyWithoutPK(featureStore, |
300 |
feature); |
301 |
editableFeature.setDefaultGeometry(geom); |
302 |
editingProviderServices |
303 |
.insertFeatureIntoFeatureStore(editableFeature, |
304 |
featureStore); |
305 |
|
306 |
} |
307 |
it.dispose(); |
308 |
featureStore.getFeatureSelection().deselectAll(); |
309 |
} |
310 |
} |
311 |
} catch (DataException e) {
|
312 |
throw new FinishServiceException(e); |
313 |
} |
314 |
} |
315 |
|
316 |
private Double getNormalModule(Point closestPoint, Point distancePoint,FeatureSelection selected) |
317 |
throws DataException, CreateEnvelopeException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException, LocatorException{
|
318 |
|
319 |
MutableDouble distance=null;
|
320 |
getPerpendicularPoint(closestPoint, distancePoint, selected, distance); |
321 |
return distance.getValue();
|
322 |
} |
323 |
|
324 |
private Point getPerpendicularPoint(Point closestPoint, Point distancePoint,FeatureSelection selected) |
325 |
throws DataException, CreateEnvelopeException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException, LocatorException{
|
326 |
return getPerpendicularPoint(closestPoint,distancePoint,selected,null); |
327 |
} |
328 |
|
329 |
|
330 |
private Point getPerpendicularPoint(Point closestPoint, Point distancePoint,FeatureSelection selected, MutableDouble normalModule) |
331 |
throws DataException, CreateEnvelopeException, GeometryOperationNotSupportedException, GeometryOperationException, CreateGeometryException, LocatorException{
|
332 |
|
333 |
int subType = featureStore.getDefaultFeatureType()
|
334 |
.getDefaultGeometryAttribute().getGeomType() |
335 |
.getSubType(); |
336 |
|
337 |
Geometry containingGeometry=getContainingGeometry(selected, closestPoint); |
338 |
|
339 |
if (containingGeometry instanceof Circle || containingGeometry instanceof Ellipse || |
340 |
containingGeometry instanceof Circumference || containingGeometry instanceof PeriEllipse){ |
341 |
if (containingGeometry instanceof Circle){ |
342 |
Circle circle=(Circle)containingGeometry; |
343 |
Circumference circumference =(Circumference)GeometryLocator. |
344 |
getGeometryManager().create(Geometry.TYPES.CIRCUMFERENCE, subType); |
345 |
circumference.setPoints(circle.getCenter(), circle.getRadious()); |
346 |
containingGeometry=circumference; |
347 |
} |
348 |
if (containingGeometry instanceof Ellipse || containingGeometry instanceof Circumference){ |
349 |
Ellipse ellipse=(Ellipse)containingGeometry; |
350 |
PeriEllipse periellipse =(PeriEllipse)GeometryLocator. |
351 |
getGeometryManager().create(Geometry.TYPES.PERIELLIPSE, subType); |
352 |
periellipse.setPoints(ellipse.getAxis1Start(), ellipse.getAxis1End(), ellipse.getAxis2Dist()); |
353 |
containingGeometry=periellipse; |
354 |
} |
355 |
if (containingGeometry instanceof PeriEllipse){ |
356 |
Integer direction;
|
357 |
if (containingGeometry.contains(distancePoint)){
|
358 |
direction=-1;
|
359 |
}else{
|
360 |
direction=1;
|
361 |
} |
362 |
normalModule.setValue(closestPoint.distance(distancePoint)*direction); |
363 |
return distancePoint;
|
364 |
} |
365 |
} |
366 |
|
367 |
Line containingLine=null; |
368 |
if (containingGeometry!=null){ |
369 |
containingLine = getContainingLine(containingGeometry, closestPoint, subType); |
370 |
} |
371 |
|
372 |
if (containingLine!=null){ |
373 |
Double module=containingLine.perimeter();
|
374 |
|
375 |
Point point0=containingLine.getVertex(0); |
376 |
Point point1=containingLine.getVertex(1); |
377 |
|
378 |
Double unitarianX=(point1.getX()-point0.getX())/module;
|
379 |
Double unitarianY=(point1.getY()-point0.getY())/module;
|
380 |
|
381 |
Point unitarianPoint=GeometryLocator.getGeometryManager().createPoint(
|
382 |
unitarianX, |
383 |
unitarianY, |
384 |
subType); |
385 |
|
386 |
Double perpendicularAngle=Math.PI/2; |
387 |
AffineTransform rotate = AffineTransform.getRotateInstance(perpendicularAngle); |
388 |
unitarianPoint.transform(rotate); |
389 |
|
390 |
Double distance=getDirectedDistance(closestPoint, distancePoint, containingLine);
|
391 |
|
392 |
unitarianPoint.setX(unitarianPoint.getX()*distance); |
393 |
unitarianPoint.setY(unitarianPoint.getY()*distance); |
394 |
|
395 |
unitarianPoint.setX(unitarianPoint.getX()+closestPoint.getX()); |
396 |
unitarianPoint.setY(unitarianPoint.getY()+closestPoint.getY()); |
397 |
|
398 |
if (distance>0){ |
399 |
normalModule.setValue(unitarianPoint.distance(closestPoint)); |
400 |
}else{
|
401 |
normalModule.setValue(-unitarianPoint.distance(closestPoint)); |
402 |
} |
403 |
|
404 |
|
405 |
return unitarianPoint;
|
406 |
} |
407 |
return null; |
408 |
} |
409 |
|
410 |
private Double getDirectedDistance(Point pointInLine, Point distancePoint, Line line) |
411 |
throws GeometryOperationNotSupportedException, GeometryOperationException{
|
412 |
Double distance=distancePoint.distance(pointInLine);
|
413 |
EditingProviderServices editingProviderServices = |
414 |
(EditingProviderServices) getProviderServices(); |
415 |
Double angle = editingProviderServices.getAngle(pointInLine, distancePoint);
|
416 |
double angleLine = editingProviderServices.getAngle(line.getVertex(0), line.getVertex(1)); |
417 |
|
418 |
Double angleDifference=angle - angleLine;
|
419 |
if ( angleDifference<0 ){ |
420 |
angleDifference+=2*Math.PI; |
421 |
} |
422 |
if (angleDifference > Math.PI ) { |
423 |
distance = -distance; // perpendicularAngle=3*Math.PI/2;
|
424 |
} |
425 |
return distance;
|
426 |
} |
427 |
|
428 |
private Line getContainingLine(Geometry containingGeometry, |
429 |
Point containedPoint, int subType) |
430 |
throws CreateGeometryException,
|
431 |
GeometryOperationNotSupportedException, GeometryOperationException { |
432 |
if (containingGeometry instanceof Line ||containingGeometry instanceof Polygon ){ |
433 |
OrientablePrimitive orientableGeometry=(OrientablePrimitive)containingGeometry; |
434 |
for (int i=0; i<orientableGeometry.getNumVertices()-1;i++){ |
435 |
Point point=orientableGeometry.getVertex(i);
|
436 |
Point nextPoint=orientableGeometry.getVertex(i+1); |
437 |
Line line =
|
438 |
GeometryLocator.getGeometryManager().createLine( |
439 |
subType); |
440 |
line.addVertex(point); |
441 |
line.addVertex(nextPoint); |
442 |
//FIXME
|
443 |
//if (line.contains(closestPoint)){
|
444 |
if (line.isWithinDistance(containedPoint, PRECISION)){
|
445 |
return line;
|
446 |
} |
447 |
} |
448 |
} |
449 |
return null; |
450 |
} |
451 |
|
452 |
private Geometry getContainingGeometry (FeatureSelection selected,Point point) |
453 |
throws DataException, GeometryOperationNotSupportedException, GeometryOperationException{
|
454 |
|
455 |
DisposableIterator it; |
456 |
it = selected.fastIterator(); |
457 |
while (it.hasNext()) {
|
458 |
Feature feat = (Feature) it.next(); |
459 |
Geometry geometry = feat.getDefaultGeometry(); |
460 |
if(geometry instanceof Aggregate){ |
461 |
int primitivesNumber = ((Aggregate)geometry).getPrimitivesNumber();
|
462 |
for (int i = 0; i < primitivesNumber; i++) { |
463 |
Geometry primitiveGeometry=((Aggregate)geometry).getPrimitiveAt(i); |
464 |
if (primitiveGeometry instanceof Polygon) { |
465 |
Polygon geomPoly = (Polygon)primitiveGeometry; |
466 |
//FIXME
|
467 |
if (geomPoly.isWithinDistance(point, PRECISION)){
|
468 |
//if (geomPoly.touches(point)){
|
469 |
return primitiveGeometry;
|
470 |
} |
471 |
//FIXME
|
472 |
//} else if(primitiveGeometry.contains(closestPoint)){
|
473 |
} else if(primitiveGeometry.isWithinDistance(point, PRECISION)){ |
474 |
return primitiveGeometry;
|
475 |
} |
476 |
} |
477 |
} else {
|
478 |
if (geometry instanceof Polygon) { |
479 |
Polygon geomPoly = (Polygon)geometry; |
480 |
//FIXME
|
481 |
if (geomPoly.isWithinDistance(point, PRECISION)){
|
482 |
//if (geomPoly.touches(point)){
|
483 |
return geometry;
|
484 |
} |
485 |
//FIXME
|
486 |
//} else if(geometry.contains(closestPoint)){
|
487 |
} else if(geometry.isWithinDistance(point, PRECISION)){ |
488 |
return geometry;
|
489 |
} |
490 |
} |
491 |
} |
492 |
return null; |
493 |
} |
494 |
|
495 |
private Point getClosestPoint(Point point, FeatureSelection selected) |
496 |
throws DataException, GeometryOperationNotSupportedException,
|
497 |
GeometryOperationException{ |
498 |
|
499 |
DisposableIterator it; |
500 |
it = selected.fastIterator(); |
501 |
ArrayList<Point> closestPoints = new ArrayList<Point>(); |
502 |
while (it.hasNext()) {
|
503 |
Feature feat = (Feature) it.next(); |
504 |
Geometry geometry = feat.getDefaultGeometry(); |
505 |
Geometry[] geoms = point.closestPoints(geometry);
|
506 |
if (geoms!=null){ |
507 |
for (int i=0;i<geoms.length;i++){ |
508 |
Geometry closePoint=geoms[i]; |
509 |
if (closePoint!=null && closePoint instanceof Point){ |
510 |
closestPoints.add((Point)closePoint);
|
511 |
} |
512 |
} |
513 |
} |
514 |
} |
515 |
it.dispose(); |
516 |
double minorDistance=Double.POSITIVE_INFINITY; |
517 |
Point closestPoint=null; |
518 |
for (Point closePoint:closestPoints){ |
519 |
double distance=point.distance(closePoint);
|
520 |
if (distance<minorDistance && distance>Double.valueOf(0)){ |
521 |
minorDistance=distance; |
522 |
closestPoint=closePoint; |
523 |
} |
524 |
} |
525 |
return closestPoint;
|
526 |
} |
527 |
|
528 |
|
529 |
public Geometry finish() throws FinishServiceException { |
530 |
return null; |
531 |
} |
532 |
|
533 |
public void start() throws StartServiceException { |
534 |
this.values = new HashMap<EditingServiceParameter, Object>(); |
535 |
FeatureSelection selected = null;
|
536 |
if (featureStore != null) { |
537 |
try {
|
538 |
selected = |
539 |
(FeatureSelection) featureStore.getFeatureSelection() |
540 |
.clone(); |
541 |
} catch (DataException e) {
|
542 |
throw new StartServiceException(e); |
543 |
} catch (CloneNotSupportedException e) { |
544 |
// Do nothing
|
545 |
} |
546 |
if ((selected != null) && (selected.getSelectedCount() > 0)) { |
547 |
values.put(selectionParameter, selected); |
548 |
} |
549 |
} |
550 |
} |
551 |
|
552 |
public String getName() { |
553 |
return OffsetEditingProviderFactory.PROVIDER_NAME;
|
554 |
} |
555 |
|
556 |
} |