Revision 22876 trunk/libraries/libTopology/src/org/gvsig/jts/voronoi/ChewVoronoiStrategy.java
ChewVoronoiStrategy.java | ||
---|---|---|
48 | 48 |
*/ |
49 | 49 |
package org.gvsig.jts.voronoi; |
50 | 50 |
|
51 |
import java.awt.geom.Point2D; |
|
51 | 52 |
import java.rmi.server.UID; |
52 | 53 |
import java.util.ArrayList; |
53 | 54 |
import java.util.List; |
54 | 55 |
|
55 | 56 |
import org.gvsig.exceptions.BaseException; |
56 |
import org.gvsig.fmap.core.NewFConverter; |
|
57 |
import org.gvsig.jts.voronoi.Voronoier.VoronoiStrategy; |
|
58 |
import org.gvsig.jts.voronoi.chew.ChewVoronoiList; |
|
57 |
import org.gvsig.fmap.core.FGeometryUtil; |
|
59 | 58 |
import org.gvsig.jts.voronoi.chew.DTriangulationForJTS; |
59 |
import org.gvsig.topology.Messages; |
|
60 | 60 |
|
61 | 61 |
import com.hardcode.gdbms.engine.values.Value; |
62 | 62 |
import com.hardcode.gdbms.engine.values.ValueFactory; |
63 |
import com.iver.cit.gvsig.fmap.core.DefaultFeature; |
|
64 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
|
65 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
|
66 | 63 |
import com.iver.utiles.swing.threads.CancellableProgressTask; |
67 |
import com.vividsolutions.jts.geom.Geometry;
|
|
64 |
import com.vividsolutions.jts.geom.Coordinate;
|
|
68 | 65 |
|
69 |
public class ChewVoronoiStrategy implements VoronoiStrategy { |
|
70 |
|
|
71 |
|
|
72 |
//TODO Ahora mismo el parametro onlySelection se est? ignorando. |
|
73 |
//Hay que modificar DTriangulationForJTS para que tenga en cuenta esto |
|
74 |
|
|
75 |
|
|
76 |
public List<IFeature> createTin(VoronoiAndTinInputLyr inputLyr, boolean onlySelection, |
|
77 |
CancellableProgressTask progressMonitor) throws BaseException { |
|
66 |
public class ChewVoronoiStrategy extends AbstractVoronoiStrategy { |
|
78 | 67 |
|
79 |
ChewVoronoiList pointList = new ChewVoronoiList(inputLyr); |
|
80 |
DTriangulationForJTS ojVoronoi = new DTriangulationForJTS(pointList); |
|
81 |
List<Geometry> delaunayEdges = ojVoronoi.getTinTriangles(progressMonitor); |
|
82 |
return createFeatureCollection(delaunayEdges); |
|
83 |
} |
|
84 |
|
|
85 |
public List<IFeature> createThiessenPolygons(VoronoiAndTinInputLyr inputLyr, |
|
86 |
boolean onlySelection,CancellableProgressTask progressMonitor) |
|
68 |
public List<TriangleFeature> createTin(VoronoiAndTinInputLyr inputLyr, |
|
69 |
boolean onlySelection, CancellableProgressTask progressMonitor) |
|
87 | 70 |
throws BaseException { |
88 |
ChewVoronoiList pointList = new ChewVoronoiList(inputLyr); |
|
89 |
DTriangulationForJTS ojVoronoi = new DTriangulationForJTS(pointList); |
|
90 |
List<Geometry> thiessenPolygons = ojVoronoi.getThiessenPolys(progressMonitor); |
|
91 |
return createFeatureCollection(thiessenPolygons); |
|
71 |
|
|
72 |
DTriangulationForJTS ojVoronoi = new DTriangulationForJTS(inputLyr, |
|
73 |
onlySelection); |
|
74 |
List<Coordinate[]> delaunayEdges = ojVoronoi |
|
75 |
.getTinTriangles(progressMonitor); |
|
76 |
return createTinFeatureCollection(delaunayEdges); |
|
92 | 77 |
} |
93 |
|
|
94 |
|
|
95 |
private List<IFeature> createFeatureCollection(List<Geometry> geoms){
|
|
96 |
List<IFeature> solution = new ArrayList<IFeature>();
|
|
78 |
|
|
79 |
private List<TriangleFeature> createTinFeatureCollection( |
|
80 |
List<Coordinate[]> geoms) {
|
|
81 |
List<TriangleFeature> solution = new ArrayList<TriangleFeature>();
|
|
97 | 82 |
for (int i = 0; i < geoms.size(); i++) { |
98 |
Geometry jtsGeom = geoms.get(i); |
|
99 |
IGeometry geom = NewFConverter.toFMap(jtsGeom); |
|
83 |
Coordinate[] jtsGeom = geoms.get(i); |
|
84 |
Point2D[] points = FGeometryUtil.getCoordinatesAsPoint2D(jtsGeom); |
|
85 |
FTriangle triangle = new FTriangle(points[0], points[1], points[2]); |
|
100 | 86 |
Value fid = ValueFactory.createValue(i); |
101 | 87 |
Value associatedVertex = ValueFactory.createValue(i); |
102 | 88 |
Value[] values = new Value[] { fid, associatedVertex }; |
103 |
DefaultFeature feature = new DefaultFeature(geom, values, new UID()
|
|
104 |
.toString()); |
|
89 |
TriangleFeature feature = new TriangleFeature(triangle, values,
|
|
90 |
new UID().toString());
|
|
105 | 91 |
solution.add(feature); |
106 | 92 |
} |
107 | 93 |
|
108 | 94 |
return solution; |
109 | 95 |
} |
110 | 96 |
|
111 |
public List<IFeature> createThiessenPolygons(VoronoiAndTinInputLyr inputLyr, |
|
112 |
boolean onlySelection) |
|
113 |
throws BaseException { |
|
114 |
return createThiessenPolygons(inputLyr, onlySelection, null); |
|
97 |
public String getName() { |
|
98 |
return Messages.getText("Chew: Incremental TIN based in a bounding triangle"); |
|
115 | 99 |
} |
116 | 100 |
|
117 |
public List<IFeature> createTin(VoronoiAndTinInputLyr inputLyr, boolean onlySelection) |
|
118 |
throws BaseException { |
|
119 |
return createTin(inputLyr, onlySelection, null); |
|
120 |
} |
|
121 | 101 |
} |
Also available in: Unified diff