Revision 34 org.gvsig.lrs/trunk/org.gvsig.lrs/org.gvsig.lrs.lib/org.gvsig.lrs.lib.impl/src/main/java/org/gvsig/lrs/lib/impl/LrsCreateRouteAlgorithm.java
LrsCreateRouteAlgorithm.java | ||
---|---|---|
461 | 461 |
return null; |
462 | 462 |
} |
463 | 463 |
|
464 |
// /** |
|
465 |
// * Returns the measure corresponding to the point into the geometry |
|
466 |
// * |
|
467 |
// * @param mGeometry |
|
468 |
// * @param point |
|
469 |
// * @return |
|
470 |
// * @throws GeometryOperationException |
|
471 |
// * @throws GeometryOperationNotSupportedException |
|
472 |
// * @throws CreateGeometryException |
|
473 |
// */ |
|
474 |
// private double getM(MultiLine multiLine, Point point) throws GeometryOperationNotSupportedException, |
|
475 |
// GeometryOperationException, CreateGeometryException { |
|
476 |
// GeometryManager geomManager = GeometryLocator.getGeometryManager(); |
|
477 |
// if (!(multiLine.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM2DM)) |
|
478 |
// || (multiLine.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3DM))) { |
|
479 |
// return Double.NaN; |
|
480 |
// } |
|
481 |
// if (!(point.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM2DM)) |
|
482 |
// || (point.getGeometryType().isSubTypeOf(Geometry.SUBTYPES.GEOM3DM))) { |
|
483 |
// return Double.NaN; |
|
484 |
// } |
|
485 |
// for (int i = 0; i < multiLine.getPrimitivesNumber(); i++) { |
|
486 |
// Line line = (Line) multiLine.getPrimitiveAt(i); |
|
487 |
// if (line.intersects(point)) { |
|
488 |
// for (int j = 0; j < line.getNumVertices() - 1; j++) { |
|
489 |
// Point vertex1 = line.getVertex(j); |
|
490 |
// double m1 = vertex1.getCoordinateAt(vertex1.getDimension() - 1); |
|
491 |
// double x1 = vertex1.getX(); |
|
492 |
// double y1 = vertex1.getY(); |
|
493 |
// if (point.equals(vertex1)) { |
|
494 |
// return m1; |
|
495 |
// } |
|
496 |
// Point vertex2 = line.getVertex(j + 1); |
|
497 |
// double m2 = vertex2.getCoordinateAt(vertex2.getDimension() - 1); |
|
498 |
// double x2 = vertex2.getX(); |
|
499 |
// double y2 = vertex2.getY(); |
|
500 |
// if (point.equals(vertex2)) { |
|
501 |
// return m2; |
|
502 |
// } |
|
503 |
// Line auxLine = (Line) geomManager.create(Geometry.TYPES.LINE, Geometry.SUBTYPES.GEOM2DM); |
|
504 |
// auxLine.addVertex(line.getVertex(j)); |
|
505 |
// auxLine.addVertex(line.getVertex(j + 1)); |
|
506 |
// if (auxLine.intersects(point)) { |
|
507 |
// if (x1 != x2) { |
|
508 |
// return strightLineThroughTwoPointsEquation(x1, x2, m1, m2, point.getX()); |
|
509 |
// } else { |
|
510 |
// return strightLineThroughTwoPointsEquation(y1, y2, m1, m2, point.getY()); |
|
511 |
// } |
|
512 |
// } |
|
513 |
// } |
|
514 |
// } |
|
515 |
// } |
|
516 |
// return Double.NaN; |
|
517 |
// } |
|
518 |
|
|
519 | 464 |
/** |
520 | 465 |
* Checks if a bifurcation occurs at one point and return the vertex with maximum M |
521 | 466 |
* |
... | ... | |
592 | 537 |
return result; |
593 | 538 |
} |
594 | 539 |
|
595 |
// /** |
|
596 |
// * @param closestPoints |
|
597 |
// * @return |
|
598 |
// * @throws CreateEnvelopeException |
|
599 |
// * @throws GeometryOperationException |
|
600 |
// * @throws GeometryOperationNotSupportedException |
|
601 |
// */ |
|
602 |
// private Point getClosestPointByCoordinatePriority(Geometry[] closestPoints) throws CreateEnvelopeException, |
|
603 |
// GeometryOperationNotSupportedException, GeometryOperationException { |
|
604 |
// LrsCoordinatesPriority coordinatePriority = parameters.getCoordinatePriority(); |
|
605 |
// GeometryManager geomanager = GeometryLocator.getGeometryManager(); |
|
606 |
// Envelope envelope = geomanager.createEnvelope(Geometry.SUBTYPES.GEOM2D); |
|
607 |
// for (int i = 0; i < closestPoints.length; i++) { |
|
608 |
// envelope.add(closestPoints[i]); |
|
609 |
// } |
|
610 |
// Point origin = envelope.getLowerCorner(); |
|
611 |
// switch (coordinatePriority) { |
|
612 |
// case DOWN_LEFT: |
|
613 |
// break; |
|
614 |
// case DOWN_RIGHT: |
|
615 |
// Double maxX = envelope.getMaximum(DIMENSIONS.X); |
|
616 |
// origin.setX(maxX); |
|
617 |
// break; |
|
618 |
// case UP_LEFT: |
|
619 |
// Double maxY = envelope.getMaximum(DIMENSIONS.Y); |
|
620 |
// origin.setY(maxY); |
|
621 |
// break; |
|
622 |
// case UP_RIGHT: |
|
623 |
// origin = envelope.getUpperCorner(); |
|
624 |
// break; |
|
625 |
// default: |
|
626 |
// break; |
|
627 |
// } |
|
628 |
// Point closestPoint = null; |
|
629 |
// double minDistance = Double.POSITIVE_INFINITY; |
|
630 |
// for (int i = 0; i < closestPoints.length; i++) { |
|
631 |
// Point point = (Point) closestPoints[i]; |
|
632 |
// double distance = origin.distance(point); |
|
633 |
// if (minDistance > distance) { |
|
634 |
// minDistance = distance; |
|
635 |
// closestPoint = point; |
|
636 |
// } |
|
637 |
// } |
|
638 |
// return closestPoint; |
|
639 |
// } |
|
640 |
|
|
641 |
// private Double getCalculatedMValueForFirstPoint(Geometry mGeometry, Geometry geometry) { |
|
642 |
// List<Point> mPoints = extractPoints(mGeometry); |
|
643 |
// Point point = extractFirstPoint(geometry); |
|
644 |
// for (Point mPoint : mPoints) { |
|
645 |
// if (mPoint.getX() == point.getX() && mPoint.getY() == point.getY()) { |
|
646 |
// int dimensionM = mPoint.getDimension() - 1; |
|
647 |
// return mPoint.getCoordinateAt(dimensionM); |
|
648 |
// } |
|
649 |
// } |
|
650 |
// return null; |
|
651 |
// } |
|
652 |
|
|
653 | 540 |
/** |
654 | 541 |
* Returns a multiline calculate by two field method |
655 | 542 |
* |
... | ... | |
880 | 767 |
return null; |
881 | 768 |
} |
882 | 769 |
|
883 |
// /** |
|
884 |
// * Calculate distance between a point and the firstPoint of the geometry |
|
885 |
// * |
|
886 |
// * @param point |
|
887 |
// * @param geometry |
|
888 |
// * @return |
|
889 |
// * @throws GeometryOperationNotSupportedException |
|
890 |
// * @throws GeometryOperationException |
|
891 |
// */ |
|
892 |
// private Double calculateGap(Point point, Geometry geometry) throws GeometryOperationNotSupportedException, |
|
893 |
// GeometryOperationException { |
|
894 |
// Double gap = new Double(0); |
|
895 |
// if (geometry instanceof Line) { |
|
896 |
// Line line = (Line) geometry; |
|
897 |
// if (point != null) { |
|
898 |
// Point firstPoint = line.getVertex(0); |
|
899 |
// gap = firstPoint.distance(point); |
|
900 |
// } |
|
901 |
// } |
|
902 |
// if (geometry instanceof MultiLine) { |
|
903 |
// MultiLine multiLine = (MultiLine) geometry; |
|
904 |
// if (point != null) { |
|
905 |
// Line line = (Line) multiLine.getPrimitiveAt(0); |
|
906 |
// Point firstPoint = line.getVertex(0); |
|
907 |
// gap = firstPoint.distance(point); |
|
908 |
// } |
|
909 |
// } |
|
910 |
// return gap; |
|
911 |
// } |
|
912 |
|
|
913 | 770 |
/** |
914 | 771 |
* Sorts mList |
915 | 772 |
* |
... | ... | |
1143 | 1000 |
return stretches; |
1144 | 1001 |
} |
1145 | 1002 |
|
1146 |
|
|
1147 |
// private Point extractFirstPoint(Geometry geometry) { |
|
1148 |
// Point firstPoint = null; |
|
1149 |
// List<Line> lines = extractLines(geometry); |
|
1150 |
// if (lines != null && !lines.isEmpty()) { |
|
1151 |
// firstPoint = lines.get(0).getVertex(0); |
|
1152 |
// } |
|
1153 |
// return firstPoint; |
|
1154 |
// } |
|
1155 |
|
|
1156 |
// private List<Point> extractPoints(Geometry geometry) { |
|
1157 |
// List<Point> points = new ArrayList<Point>(); |
|
1158 |
// List<Line> lines = extractLines(geometry); |
|
1159 |
// for (Line line : lines) { |
|
1160 |
// for (int i = 0; i < line.getNumVertices(); i++) { |
|
1161 |
// points.add(line.getVertex(i)); |
|
1162 |
// } |
|
1163 |
// } |
|
1164 |
// return points; |
|
1165 |
// } |
|
1166 |
|
|
1167 | 1003 |
/** |
1168 | 1004 |
* Extracts lines of a geometry. |
1169 | 1005 |
* |
... | ... | |
1219 | 1055 |
return geometry; |
1220 | 1056 |
} |
1221 | 1057 |
|
1222 |
// private Map<Object, List<FeatureReference>> getGroupedReferences(FeatureSelection selection, |
|
1223 |
// final FeatureAttributeDescriptor idRouteField) throws BaseException { |
|
1224 |
// final Map<Object, List<FeatureReference>> refs = new HashMap<Object, List<FeatureReference>>(); |
|
1225 |
// selection.accept(new Visitor() { |
|
1226 |
// |
|
1227 |
// public void visit(Object obj) throws VisitCanceledException, BaseException { |
|
1228 |
// Feature feature = (Feature) obj; |
|
1229 |
// Object id = feature.getFeature(idRouteField.getName()); |
|
1230 |
// FeatureReference reference = feature.getReference(); |
|
1231 |
// List<FeatureReference> references = refs.get(id); |
|
1232 |
// if (references == null) { |
|
1233 |
// references = new ArrayList<FeatureReference>(); |
|
1234 |
// } |
|
1235 |
// references.add(reference); |
|
1236 |
// refs.put(id, references); |
|
1237 |
// } |
|
1238 |
// }); |
|
1239 |
// return refs; |
|
1240 |
// } |
|
1241 |
|
|
1242 | 1058 |
/** |
1243 | 1059 |
* Returns the geometric length of a line |
1244 | 1060 |
* |
... | ... | |
1260 | 1076 |
return lenght; |
1261 | 1077 |
} |
1262 | 1078 |
|
1263 |
// /** |
|
1264 |
// * @param multiLine |
|
1265 |
// * @return lenght |
|
1266 |
// * @throws GeometryOperationException |
|
1267 |
// * @throws GeometryOperationNotSupportedException |
|
1268 |
// */ |
|
1269 |
// private double getMultiLineLength(MultiLine multiLine, boolean ignoreSpatialGaps) |
|
1270 |
// throws GeometryOperationNotSupportedException, GeometryOperationException { |
|
1271 |
// // We assume that the primitives are consecutive. |
|
1272 |
// double lenght = 0; |
|
1273 |
// Point previousVertex = null; |
|
1274 |
// for (int j = 0; j < multiLine.getPrimitivesNumber(); j++) { |
|
1275 |
// Line line = (Line) multiLine.getPrimitiveAt(j); |
|
1276 |
// if (ignoreSpatialGaps) { |
|
1277 |
// previousVertex = null; |
|
1278 |
// } |
|
1279 |
// for (int i = 0; i < line.getNumVertices(); i++) { |
|
1280 |
// Point vertex = line.getVertex(i); |
|
1281 |
// if (previousVertex != null) { |
|
1282 |
// lenght += previousVertex.distance(vertex); |
|
1283 |
// } |
|
1284 |
// previousVertex = vertex; |
|
1285 |
// } |
|
1286 |
// } |
|
1287 |
// return lenght; |
|
1288 |
// } |
|
1289 |
|
|
1290 | 1079 |
/* |
1291 | 1080 |
* (non-Javadoc) |
1292 | 1081 |
* |
... | ... | |
1457 | 1246 |
|
1458 | 1247 |
} |
1459 | 1248 |
|
1460 |
// private class PointToReferencePointComparator implements Comparator<Point> { |
|
1461 |
// |
|
1462 |
// private Point referencePoint; |
|
1463 |
// |
|
1464 |
// public PointToReferencePointComparator(Point referencePoint) { |
|
1465 |
// this.referencePoint = referencePoint; |
|
1466 |
// } |
|
1467 |
// |
|
1468 |
// public int compare(Point point1, Point point2) { |
|
1469 |
// Double distance1; |
|
1470 |
// try { |
|
1471 |
// distance1 = point1.distance(referencePoint); |
|
1472 |
// } catch (Exception e) { |
|
1473 |
// distance1 = Double.MAX_VALUE; |
|
1474 |
// } |
|
1475 |
// Double distance2; |
|
1476 |
// try { |
|
1477 |
// distance2 = point2.distance(referencePoint); |
|
1478 |
// } catch (Exception e) { |
|
1479 |
// distance2 = Double.MAX_VALUE; |
|
1480 |
// } |
|
1481 |
// return distance1.compareTo(distance2); |
|
1482 |
// } |
|
1483 |
// } |
|
1484 |
|
|
1485 | 1249 |
} |
Also available in: Unified diff