root / trunk / extensions / extGraph / src-test / com / iver / cit / gvsig / graphtests / TestCreatePolygon.java @ 39203
History | View | Annotate | Download (5.18 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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 |
*/
|
22 |
|
23 |
/*
|
24 |
* AUTHORS (In addition to CIT):
|
25 |
* 2008 {{Company}} {{Task}}
|
26 |
*/
|
27 |
|
28 |
package com.iver.cit.gvsig.graphtests; |
29 |
|
30 |
import java.io.File; |
31 |
import java.util.Collection; |
32 |
|
33 |
import junit.framework.TestCase; |
34 |
|
35 |
import org.cresques.cts.IProjection; |
36 |
import org.gvsig.exceptions.BaseException; |
37 |
import org.gvsig.fmap.algorithm.contouring.LoopRemover; |
38 |
|
39 |
import com.iver.cit.gvsig.fmap.core.IFeature; |
40 |
import com.iver.cit.gvsig.fmap.core.IGeometry; |
41 |
import com.iver.cit.gvsig.fmap.crs.CRSFactory; |
42 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
43 |
import com.iver.cit.gvsig.fmap.layers.LayerFactory; |
44 |
import com.iver.cit.gvsig.fmap.layers.ReadableVectorial; |
45 |
import com.vividsolutions.jts.geom.Geometry; |
46 |
import com.vividsolutions.jts.geom.Polygon; |
47 |
import com.vividsolutions.jts.operation.polygonize.Polygonizer; |
48 |
|
49 |
public class TestCreatePolygon extends TestCase { |
50 |
|
51 |
FLyrVect lyr; |
52 |
|
53 |
protected void setUp() throws Exception { |
54 |
super.setUp();
|
55 |
// Setup de los drivers
|
56 |
LayerFactory |
57 |
.setDriversPath("../_fwAndami/gvSIG/extensiones/com.iver.cit.gvsig/drivers");
|
58 |
|
59 |
// Setup del factory de DataSources
|
60 |
|
61 |
IProjection prj = CRSFactory.getCRS("EPSG:23030");
|
62 |
File shpFile = new File("test_files/contour3.shp"); |
63 |
lyr = (FLyrVect) LayerFactory.createLayer("Contour", "gvSIG shp driver", |
64 |
shpFile, prj); |
65 |
|
66 |
} |
67 |
|
68 |
public void testCalculatePolygon() throws BaseException { |
69 |
|
70 |
ReadableVectorial rv = lyr.getSource(); |
71 |
|
72 |
long t1 = System.currentTimeMillis(); |
73 |
LoopRemover sequencer = new LoopRemover();
|
74 |
Polygonizer pol = new Polygonizer();
|
75 |
rv.start(); |
76 |
for (int i=0; i < rv.getShapeCount(); i++) { |
77 |
IFeature feat = rv.getFeature(i); |
78 |
IGeometry geom = feat.getGeometry(); |
79 |
Geometry jtsGeom = geom.toJTSGeometry(); |
80 |
sequencer.add(jtsGeom); |
81 |
pol.add(jtsGeom); |
82 |
// if (jtsGeom instanceof LineString)
|
83 |
// {
|
84 |
// LineString lineString = (LineString) jtsGeom;
|
85 |
// graph.addEdge(lineString);
|
86 |
// }
|
87 |
} |
88 |
rv.stop(); |
89 |
|
90 |
// Iterator it = graph.edgeIterator();
|
91 |
// while (it.hasNext()) {
|
92 |
// Edge edge = (Edge) it.next();
|
93 |
// edge.
|
94 |
// }
|
95 |
Collection<Polygon> polygons = pol.getPolygons(); |
96 |
|
97 |
for (Polygon p : polygons) { |
98 |
System.out.println(p.toText());
|
99 |
} |
100 |
|
101 |
Geometry newJtsGeom = sequencer.getSequencedLineStrings(); |
102 |
System.out.println(newJtsGeom.toText());
|
103 |
long t2 = System.currentTimeMillis(); |
104 |
System.out.println("tiempo:" + (t2-t1)); |
105 |
|
106 |
// assertEquals(dist.doubleValue(), 8887, 0);
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 |
} |
113 |
// public void testCalculateContour() throws BaseException {
|
114 |
//
|
115 |
// ReadableVectorial rv = lyr.getSource();
|
116 |
//
|
117 |
// long t1 = System.currentTimeMillis();
|
118 |
//// WatsonTriangulator triangulator = new WatsonTriangulator();
|
119 |
//// ChewTriangulator triangulator = new ChewTriangulator();
|
120 |
// FJenettTriangulator triangulator = new FJenettTriangulator();
|
121 |
// rv.start();
|
122 |
// for (int i=0; i < rv.getShapeCount(); i++) {
|
123 |
// IFeature feat = rv.getFeature(i);
|
124 |
// IGeometry geom = feat.getGeometry();
|
125 |
// Object shp = geom.getInternalShape();
|
126 |
// if (shp instanceof FPoint2D)
|
127 |
// {
|
128 |
// FPoint2D p = (FPoint2D) geom.getInternalShape();
|
129 |
// // Leer la Z para hacer el contour. Para la trianqulaci?n no hace falta.
|
130 |
// triangulator.addVertex(new Vertex(p.getX(), p.getY()));
|
131 |
// }
|
132 |
// if (shp instanceof FMultiPoint2D)
|
133 |
// {
|
134 |
// FMultiPoint2D multi = (FMultiPoint2D) shp;
|
135 |
// for (int j=0; j < multi.getNumPoints(); j++) {
|
136 |
// FPoint2D p = multi.getPoint(j);
|
137 |
// NumericValue val = (NumericValue) feat.getAttribute(0);
|
138 |
// triangulator.addVertex(new Vertex(p.getX(), p.getY(), val.doubleValue()));
|
139 |
// }
|
140 |
// }
|
141 |
//
|
142 |
// }
|
143 |
// rv.stop();
|
144 |
//
|
145 |
// TIN tin = triangulator.calculateTriangulation();
|
146 |
// ContourCalculator contourCalculator = new ContourCalculator(tin);
|
147 |
// Collection<LineString> contour = contourCalculator.getContour(4.7);
|
148 |
// System.out.println("Contour = " + contour.toString());
|
149 |
//
|
150 |
// Collection<LineString> contour2 = contourCalculator.getContour_Complex_BAD(4.7);
|
151 |
// System.out.println("Contour2 = " + contour2.toString());
|
152 |
//
|
153 |
// List <Triangle> triangles = triangulator.getTriangles();
|
154 |
//
|
155 |
// long t2 = System.currentTimeMillis();
|
156 |
// System.out.println("tiempo:" + (t2-t1) + ". NumTriangles = " + triangles.size());
|
157 |
//
|
158 |
// // assertEquals(dist.doubleValue(), 8887, 0);
|
159 |
//
|
160 |
//
|
161 |
//
|
162 |
//
|
163 |
//
|
164 |
// }
|
165 |
|
166 |
} |
167 |
|