Revision 25477
trunk/extensions/extGraph/src/org/gvsig/graph/solvers/ServiceAreaExtractor2.java | ||
---|---|---|
43 | 43 |
// @author: Fco. Jos? Pe?arrubia fpenarru@gmail.com |
44 | 44 |
package org.gvsig.graph.solvers; |
45 | 45 |
|
46 |
import java.awt.geom.Point2D; |
|
47 |
import java.awt.geom.Rectangle2D; |
|
46 | 48 |
import java.io.File; |
47 | 49 |
import java.sql.Types; |
48 | 50 |
import java.util.ArrayList; |
... | ... | |
263 | 265 |
Triangulator triangulator = new OrbisGisTriangulator(); |
264 | 266 |
|
265 | 267 |
private TIN tin; |
268 |
|
|
269 |
private Rectangle2D.Double fullExtent = null; |
|
266 | 270 |
/** |
267 | 271 |
* @param net |
268 | 272 |
* @throws InitializeWriterException |
... | ... | |
505 | 509 |
Coordinate c = new Coordinate(x,y,z); |
506 | 510 |
if (!borderCoords.contains(c)) { |
507 | 511 |
borderCoords.add(c); |
512 |
if (borderCoords.size() == 2) { |
|
513 |
Iterator<Coordinate> it = borderCoords.iterator(); |
|
514 |
int i=0; |
|
515 |
Coordinate cAuxF1 = null; |
|
516 |
Coordinate cAuxF2 = null; |
|
517 |
while (it.hasNext()) { |
|
518 |
if (i==0) |
|
519 |
cAuxF1 = it.next(); |
|
520 |
else |
|
521 |
cAuxF2 = it.next(); |
|
522 |
i++; |
|
523 |
} |
|
524 |
fullExtent = new Rectangle2D.Double(); |
|
525 |
fullExtent.setFrameFromDiagonal(cAuxF1.x,cAuxF1.y, cAuxF2.x, cAuxF2.y); |
|
526 |
} |
|
527 |
else |
|
528 |
if (fullExtent != null) |
|
529 |
fullExtent.add(new Point2D.Double(x,y)); |
|
508 | 530 |
} |
509 | 531 |
} |
510 | 532 |
|
... | ... | |
751 | 773 |
|
752 | 774 |
} // for |
753 | 775 |
if (bDoCompactArea) { |
776 |
addExteriorPoints(); |
|
754 | 777 |
calculateTriangulation(); |
755 | 778 |
getBorderPoints(); |
756 | 779 |
} |
... | ... | |
759 | 782 |
if (bDoCompactArea) { |
760 | 783 |
ContourCalculator contourCalculator = new ContourCalculator(tin); |
761 | 784 |
Polygonizer pol = new Polygonizer(); |
762 |
pol.add(contourCalculator.getContour(costs[j])); |
|
785 |
pol.add(contourCalculator.getContour(costs[j]-0.5));
|
|
763 | 786 |
Collection<Polygon> polygons = pol.getPolygons(); |
764 | 787 |
Iterator<Polygon> it = polygons.iterator(); |
765 | 788 |
double maxArea = 0; |
... | ... | |
780 | 803 |
{ |
781 | 804 |
jtsGeom = serviceAreaPolygons.get(j); |
782 | 805 |
} |
783 |
writePolygon(idFlag, costs[j], jtsGeom); |
|
806 |
if (jtsGeom != null) |
|
807 |
writePolygon(idFlag, costs[j], jtsGeom); |
|
784 | 808 |
} |
785 | 809 |
|
786 | 810 |
|
787 | 811 |
} |
788 | 812 |
|
789 | 813 |
/** |
814 |
* We add points from fullExtent to allow better contour calculations |
|
815 |
*/ |
|
816 |
private void addExteriorPoints() { |
|
817 |
int numSteps = 30; // por ejemplo, 30 puntos por cada lado del rect?ngulo |
|
818 |
double stepX = fullExtent.width / numSteps; |
|
819 |
double stepY = fullExtent.height / numSteps; |
|
820 |
for (int i=0; i < numSteps; i++) { |
|
821 |
double x = fullExtent.getMinX() + stepX*i; |
|
822 |
double y = fullExtent.getMinY() + stepY*i; |
|
823 |
|
|
824 |
Coordinate cUp = new Coordinate(x, fullExtent.getMaxY() + 10.0, Double.MAX_VALUE); |
|
825 |
Coordinate cDown = new Coordinate(x, fullExtent.getMinY() - 10.0, Double.MAX_VALUE); |
|
826 |
Coordinate cLeft = new Coordinate(fullExtent.getMinX() - 10.0, y, Double.MAX_VALUE); |
|
827 |
Coordinate cRight = new Coordinate(fullExtent.getMaxX() + 10.0, y, Double.MAX_VALUE); |
|
828 |
|
|
829 |
borderCoords.add(cUp); |
|
830 |
borderCoords.add(cDown); |
|
831 |
borderCoords.add(cLeft); |
|
832 |
borderCoords.add(cRight); |
|
833 |
} |
|
834 |
|
|
835 |
|
|
836 |
} |
|
837 |
|
|
838 |
/** |
|
790 | 839 |
* @param d |
791 | 840 |
* |
792 | 841 |
*/ |
Also available in: Unified diff