Revision 55
org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/LrsCalibrateRouteAlgorithm.java | ||
---|---|---|
170 | 170 |
if (geomPoint instanceof Point){ |
171 | 171 |
Point point=(Point) geomPoint; |
172 | 172 |
Object valueObject=featuresMap.get(routeName); |
173 |
if (valueObject!=null && valueObject instanceof Object[]){
|
|
174 |
Object[] objArray=(Object[])valueObject;
|
|
175 |
if (objArray[1] instanceof List){
|
|
176 |
List<Point> points=(List<Point>)objArray[1];
|
|
173 |
if (valueObject!=null && valueObject instanceof RouteAndPoints){
|
|
174 |
RouteAndPoints routeAndPoints=(RouteAndPoints)valueObject;
|
|
175 |
if (routeAndPoints.points instanceof List){
|
|
176 |
List<Point> points=routeAndPoints.points;
|
|
177 | 177 |
if (feature.getDefaultGeometry() instanceof Point){ |
178 |
Geometry geometry=(Geometry)objArray[0];
|
|
178 |
Geometry geometry=routeAndPoints.route;
|
|
179 | 179 |
if (isValidPoint(point,geometry, convertedSearchRadius)){ |
180 | 180 |
try { |
181 | 181 |
Point mPoint= pointToMPoint(geometry,point, measure); |
... | ... | |
259 | 259 |
|
260 | 260 |
Double searchRadiusInMeters=searchRadius*measureUnits.getTransToMeter(); |
261 | 261 |
//TODO |
262 |
// DistanceUnits projectionDistanceUnits=getProjectionDistanceUnits(projection);
|
|
262 |
//DistanceUnits projectionDistanceUnits=getProjectionDistanceUnits(projection);
|
|
263 | 263 |
//return searchRadiusInMeters/projectionDistanceUnits.getTransToMeter(); |
264 | 264 |
return searchRadiusInMeters; |
265 | 265 |
} catch (Exception e) { |
... | ... | |
288 | 288 |
ExpandedRoute expandedRoute=new ExpandedRoute(geometry, ignoreSpatialGaps); |
289 | 289 |
|
290 | 290 |
|
291 |
switch (calculationMethod) { |
|
292 |
case DISTANCE: |
|
293 |
if (extrapolateBeforeCalibrationPoints||interpolateBetweenCalibrationPoints||extrapolateAfterCalibrationPoints){ |
|
294 |
expandedRoute.resetMeasuresToDistances(); |
|
295 |
} |
|
296 |
case MEASURES: |
|
297 |
default: |
|
298 |
expandedRoute.addFixedPoints(points); |
|
299 |
expandedRoute.calculateCalibrationPoints(extrapolateBeforeCalibrationPoints,interpolateBetweenCalibrationPoints,extrapolateAfterCalibrationPoints); |
|
300 |
return expandedRoute.getRoute(); |
|
301 |
} |
|
302 |
|
|
291 |
expandedRoute.addFixedPoints(points); |
|
292 |
expandedRoute.calculateCalibrationPoints(calculationMethod,extrapolateBeforeCalibrationPoints,interpolateBetweenCalibrationPoints,extrapolateAfterCalibrationPoints); |
|
293 |
return expandedRoute.getRoute(); |
|
303 | 294 |
} |
304 | 295 |
|
305 | 296 |
|
... | ... | |
410 | 401 |
} |
411 | 402 |
|
412 | 403 |
private void addFixedPoints(List<Point> fixedPoints){ |
413 |
Double minMValue=null; |
|
414 |
Double maxMValue=null; |
|
415 | 404 |
for (Point fixedPoint:fixedPoints){ |
416 | 405 |
Double length=Double.valueOf(0); |
417 | 406 |
int index = 0; |
... | ... | |
438 | 427 |
Double mValue=fixedPoint.getCoordinateAt(MDIMENSION); |
439 | 428 |
vertex.setCoordinateAt(MDIMENSION, mValue); |
440 | 429 |
isFixedPoint.set(index, true); |
441 |
// vertices.set(index, vertex);
|
|
430 |
vertices.set(index, vertex); |
|
442 | 431 |
}else{ |
443 | 432 |
if (nextVertex!=null |
444 | 433 |
&& !LrsAlgorithmUtils.equalPoints(nextVertex, fixedPoint) |
... | ... | |
492 | 481 |
} |
493 | 482 |
} |
494 | 483 |
|
495 |
|
|
496 |
|
|
497 | 484 |
public void resetMeasuresToDistances(){ |
498 | 485 |
List<Point> points=LrsAlgorithmUtils.extractPoints(route); |
499 | 486 |
for (int i=0;i<points.size();i++){ |
... | ... | |
505 | 492 |
} |
506 | 493 |
} |
507 | 494 |
|
508 |
// public void interpolateBetweenCalibrationPoints(){ |
|
509 |
// Double newMValueBeforePoint=Double.NaN; |
|
510 |
// Double oldMValueBeforePoint=Double.NaN; |
|
511 |
// Double calibrationRatio=Double.NaN; |
|
512 |
// for (int i=firstFixedPointPos; i<=lastFixedPointPos-1;i++){ |
|
513 |
// if (isFixedPoint.get(i)){ |
|
514 |
// int pointBeforePos=i; |
|
515 |
// int pointAfterPos=getNextPosFixedPoint(i); |
|
516 |
// |
|
517 |
// newMValueBeforePoint=vertices.get(pointBeforePos).getCoordinateAt(MDIMENSION); |
|
518 |
// Double newMValueAfterPoint=vertices.get(pointAfterPos).getCoordinateAt(MDIMENSION); |
|
519 |
// |
|
520 |
// oldMValueBeforePoint=oldMValues.get(pointBeforePos); |
|
521 |
// Double oldMValueAfterPoint=oldMValues.get(pointAfterPos); |
|
522 |
// |
|
523 |
// Double distanceBetweenFixedPoints=newMValueAfterPoint-newMValueBeforePoint; |
|
524 |
// Double distanceBetweenOldFixedPoints=oldMValueAfterPoint-oldMValueBeforePoint; |
|
525 |
// |
|
526 |
// calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints; |
|
527 |
// }else{ |
|
528 |
// Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION); |
|
529 |
// Double distanceBetween=valueToRecalculate-oldMValueBeforePoint; |
|
530 |
// Double mValue=newMValueBeforePoint+(distanceBetween/calibrationRatio); |
|
531 |
// refreshMValueGeometryVertex(i,mValue); |
|
532 |
// } |
|
533 |
// } |
|
534 |
// } |
|
535 |
|
|
536 |
public void calculateCalibrationPoints(boolean before, boolean between, boolean after){ |
|
495 |
public void calculateCalibrationPoints(LrsMeasureCalculationMethods calculationMethod,boolean before, boolean between, boolean after){ |
|
537 | 496 |
for (int i=0; i<vertices.size();i++){ |
538 | 497 |
if(!isFixedPoint.get(i)){ |
539 | 498 |
Integer prevFixedPointPos=getPreviousPosFixedPoint(i); |
540 | 499 |
Integer nextFixedPointPos=getNextPosFixedPoint(i); |
541 | 500 |
|
542 | 501 |
if (prevFixedPointPos==null && nextFixedPointPos!=null && before){ |
543 |
//TODO |
|
544 |
//extrapolateBeforeCalibrationPoints(nextFixedPointPos,i); |
|
502 |
extrapolateBeforeCalibrationPoints(calculationMethod,nextFixedPointPos,i); |
|
545 | 503 |
} |
546 | 504 |
if (prevFixedPointPos!=null && nextFixedPointPos!=null && between){ |
547 |
calculateMValue(prevFixedPointPos,nextFixedPointPos,i); |
|
505 |
calculateMValue(calculationMethod,prevFixedPointPos,nextFixedPointPos,i);
|
|
548 | 506 |
} |
549 | 507 |
if (prevFixedPointPos!=null && nextFixedPointPos==null && after){ |
550 |
//TODO |
|
551 |
//extrapolateAfterCalibrationPoints(prevFixedPointPos,i); |
|
508 |
extrapolateAfterCalibrationPoints(calculationMethod,prevFixedPointPos,i); |
|
552 | 509 |
} |
553 | 510 |
} |
554 | 511 |
} |
555 | 512 |
} |
556 | 513 |
|
557 |
public void calculateMValue(int prevFixedPointPos,int nextFixedPointPos,int pos){ |
|
514 |
private void extrapolateBeforeCalibrationPoints(LrsMeasureCalculationMethods calculationMethod,int firstFixedPointPos,int pos){ |
|
515 |
Integer secondFixedPointPos=getNextPosFixedPoint(firstFixedPointPos+1); |
|
516 |
if (secondFixedPointPos!=null){ |
|
517 |
|
|
518 |
if (calculationMethod.equals(LrsMeasureCalculationMethods.DISTANCE)){ |
|
519 |
if (!isFixedPoint.get(pos)){ |
|
520 |
List<Point> points=LrsAlgorithmUtils.extractPoints(route); |
|
521 |
points.get(pos).setCoordinateAt(MDIMENSION, distances.get(pos)); |
|
522 |
vertices.get(pos).setCoordinateAt(MDIMENSION, distances.get(pos)); |
|
523 |
oldMValues.set(pos, distances.get(pos)); |
|
524 |
} |
|
525 |
} |
|
526 |
|
|
527 |
Double newMValueFirstPoint=vertices.get(firstFixedPointPos).getCoordinateAt(MDIMENSION); |
|
528 |
Double newMValueSecondPoint=vertices.get(secondFixedPointPos).getCoordinateAt(MDIMENSION); |
|
529 |
|
|
530 |
Double oldMValueFirstPoint; |
|
531 |
Double oldMValueSecondPoint; |
|
532 |
if (calculationMethod.equals(LrsMeasureCalculationMethods.DISTANCE)){ |
|
533 |
oldMValueFirstPoint=distances.get(firstFixedPointPos); |
|
534 |
oldMValueSecondPoint=distances.get(secondFixedPointPos); |
|
535 |
}else{ |
|
536 |
oldMValueFirstPoint=oldMValues.get(firstFixedPointPos); |
|
537 |
oldMValueSecondPoint=oldMValues.get(secondFixedPointPos); |
|
538 |
} |
|
539 |
|
|
540 |
Double distanceBetweenFixedPoints=newMValueSecondPoint-newMValueFirstPoint; |
|
541 |
Double distanceBetweenOldFixedPoints=oldMValueSecondPoint-oldMValueFirstPoint; |
|
542 |
|
|
543 |
Double calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints; |
|
544 |
|
|
545 |
Double valueToRecalculate=vertices.get(pos).getCoordinateAt(MDIMENSION); |
|
546 |
Double distanceBetween=oldMValueFirstPoint-valueToRecalculate; |
|
547 |
Double mValue=newMValueFirstPoint-(distanceBetween/calibrationRatio); |
|
548 |
refreshMValueGeometryVertex(pos,mValue,false); |
|
549 |
} |
|
550 |
} |
|
551 |
|
|
552 |
private void extrapolateAfterCalibrationPoints(LrsMeasureCalculationMethods calculationMethod,int lastFixedPointPos,int pos){ |
|
553 |
Integer prevFixedPointPos=getPreviousPosFixedPoint(lastFixedPointPos-1); |
|
554 |
if (prevFixedPointPos!=null){ |
|
555 |
calculateMValue(calculationMethod,prevFixedPointPos,lastFixedPointPos,pos); |
|
556 |
} |
|
557 |
} |
|
558 |
|
|
559 |
private void calculateMValue(LrsMeasureCalculationMethods calculationMethod,int prevFixedPointPos,int nextFixedPointPos,int pos){ |
|
560 |
|
|
561 |
if (calculationMethod.equals(LrsMeasureCalculationMethods.DISTANCE)){ |
|
562 |
if (!isFixedPoint.get(pos)){ |
|
563 |
List<Point> points=LrsAlgorithmUtils.extractPoints(route); |
|
564 |
points.get(pos).setCoordinateAt(MDIMENSION, distances.get(pos)); |
|
565 |
vertices.get(pos).setCoordinateAt(MDIMENSION, distances.get(pos)); |
|
566 |
oldMValues.set(pos, distances.get(pos)); |
|
567 |
} |
|
568 |
} |
|
569 |
|
|
558 | 570 |
Double newMValueBeforePoint=vertices.get(prevFixedPointPos).getCoordinateAt(MDIMENSION); |
559 | 571 |
Double newMValueAfterPoint=vertices.get(nextFixedPointPos).getCoordinateAt(MDIMENSION); |
560 | 572 |
|
561 |
Double oldMValueBeforePoint=oldMValues.get(prevFixedPointPos); |
|
562 |
Double oldMValueAfterPoint=oldMValues.get(nextFixedPointPos); |
|
573 |
Double oldMValueBeforePoint; |
|
574 |
Double oldMValueAfterPoint; |
|
575 |
if (calculationMethod.equals(LrsMeasureCalculationMethods.DISTANCE)){ |
|
576 |
oldMValueBeforePoint=distances.get(prevFixedPointPos); |
|
577 |
oldMValueAfterPoint=distances.get(nextFixedPointPos); |
|
578 |
}else{ |
|
579 |
oldMValueBeforePoint=oldMValues.get(prevFixedPointPos); |
|
580 |
oldMValueAfterPoint=oldMValues.get(nextFixedPointPos); |
|
581 |
} |
|
563 | 582 |
|
564 | 583 |
Double distanceBetweenFixedPoints=newMValueAfterPoint-newMValueBeforePoint; |
565 | 584 |
Double distanceBetweenOldFixedPoints=oldMValueAfterPoint-oldMValueBeforePoint; |
... | ... | |
569 | 588 |
Double valueToRecalculate=vertices.get(pos).getCoordinateAt(MDIMENSION); |
570 | 589 |
Double distanceBetween=valueToRecalculate-oldMValueBeforePoint; |
571 | 590 |
Double mValue=newMValueBeforePoint+(distanceBetween/calibrationRatio); |
572 |
refreshMValueGeometryVertex(pos,mValue); |
|
591 |
refreshMValueGeometryVertex(pos,mValue, true);
|
|
573 | 592 |
} |
574 | 593 |
|
575 | 594 |
|
576 |
// public void extrapolateBeforeCalibrationPoints(){ |
|
577 |
// Integer nextFixedPointPos=getNextPosFixedPoint(firstFixedPointPos); |
|
578 |
// if (nextFixedPointPos!=null){ |
|
579 |
// Double newMValueFirstPoint=vertices.get(firstFixedPointPos).getCoordinateAt(MDIMENSION); |
|
580 |
// Double newMValueSecondPoint=vertices.get(nextFixedPointPos).getCoordinateAt(MDIMENSION); |
|
581 |
// |
|
582 |
// Double oldMValueFirstPoint=oldMValues.get(firstFixedPointPos); |
|
583 |
// Double oldMValueSecondPoint=oldMValues.get(nextFixedPointPos); |
|
584 |
// |
|
585 |
// Double distanceBetweenFixedPoints=newMValueSecondPoint-newMValueFirstPoint; |
|
586 |
// Double distanceBetweenOldFixedPoints=oldMValueSecondPoint-oldMValueFirstPoint; |
|
587 |
// |
|
588 |
// Double calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints; |
|
589 |
// for (int i=0; i<firstFixedPointPos;i++){ |
|
590 |
// Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION); |
|
591 |
// Double distanceBetween=oldMValueFirstPoint-valueToRecalculate; |
|
592 |
// Double mValue=newMValueFirstPoint-(distanceBetween/calibrationRatio); |
|
593 |
// refreshMValueGeometryVertex(i,mValue); |
|
594 |
// } |
|
595 |
// } |
|
596 |
// } |
|
597 |
// |
|
598 |
// public void extrapolateAfterCalibrationPoints(){ |
|
599 |
// Integer prevFixedPointPos=getPreviousPosFixedPoint(lastFixedPointPos); |
|
600 |
// if (prevFixedPointPos!=null){ |
|
601 |
// Double newMValueLastPoint=vertices.get(lastFixedPointPos).getCoordinateAt(MDIMENSION); |
|
602 |
// Double newMValuePrevPoint=vertices.get(prevFixedPointPos).getCoordinateAt(MDIMENSION); |
|
603 |
// |
|
604 |
// Double oldMValueLastPoint=oldMValues.get(lastFixedPointPos); |
|
605 |
// Double oldMValuePrevPoint=oldMValues.get(prevFixedPointPos); |
|
606 |
// |
|
607 |
// Double distanceBetweenFixedPoints=newMValueLastPoint-newMValuePrevPoint; |
|
608 |
// Double distanceBetweenOldFixedPoints=oldMValueLastPoint-oldMValuePrevPoint; |
|
609 |
// |
|
610 |
// Double calibrationRatio=distanceBetweenOldFixedPoints/distanceBetweenFixedPoints; |
|
611 |
// for (int i=lastFixedPointPos+1; i<vertices.size();i++){ |
|
612 |
// Double valueToRecalculate=vertices.get(i).getCoordinateAt(MDIMENSION); |
|
613 |
// Double distanceBetween=valueToRecalculate-oldMValueLastPoint; |
|
614 |
// Double mValue=newMValueLastPoint+(distanceBetween/calibrationRatio); |
|
615 |
// refreshMValueGeometryVertex(i,mValue); |
|
616 |
// } |
|
617 |
// } |
|
618 |
// } |
|
619 |
// |
|
620 |
// private Integer getNextPosFixedPoint(int pos){ |
|
621 |
// for (int i=pos+1;i<isFixedPoint.size();i++){ |
|
622 |
// if (isFixedPoint.get(i)){ |
|
623 |
// if( !distances.get(pos).equals(distances.get(i)) ){ |
|
624 |
// return i; |
|
625 |
// } |
|
626 |
// } |
|
627 |
// } |
|
628 |
// return null; |
|
629 |
// } |
|
630 |
|
|
631 |
|
|
632 |
|
|
633 | 595 |
private Integer getNextPosFixedPoint(int pos){ |
634 | 596 |
Integer nextFixedPointPos= findNextFixedPointInLine(pos); |
635 | 597 |
if (nextFixedPointPos!=null){ |
... | ... | |
763 | 725 |
} |
764 | 726 |
|
765 | 727 |
|
766 |
private void refreshMValueGeometryVertex(int i, Double mValue){ |
|
728 |
private void refreshMValueGeometryVertex(int i, Double mValue, boolean fixed){
|
|
767 | 729 |
List<Point> points=LrsAlgorithmUtils.extractPoints(route); |
768 | 730 |
vertices.get(i).setCoordinateAt(MDIMENSION, mValue); |
769 | 731 |
points.get(i).setCoordinateAt(MDIMENSION,mValue); |
770 |
isFixedPoint.set(i, true);
|
|
732 |
isFixedPoint.set(i, fixed);
|
|
771 | 733 |
} |
772 | 734 |
|
773 | 735 |
} |
Also available in: Unified diff