svn-gvsig-desktop / tags / v2_0_0_Build_2059 / libraries / libFMap_geometries / src-test / org / gvsig / fmap / geom / wktparser / WKTParserTest.java @ 39313
History | View | Annotate | Download (3.22 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 |
* 2009 {Iver T.I.} {Task}
|
26 |
*/
|
27 |
|
28 |
package org.gvsig.fmap.geom.wktparser; |
29 |
|
30 |
import java.awt.geom.PathIterator; |
31 |
|
32 |
import com.vividsolutions.jts.io.ParseException; |
33 |
|
34 |
import junit.framework.Assert; |
35 |
|
36 |
import org.gvsig.fmap.geom.Geometry; |
37 |
import org.gvsig.fmap.geom.GeometryLocator; |
38 |
import org.gvsig.fmap.geom.GeometryManager; |
39 |
import org.gvsig.fmap.geom.exception.CreateGeometryException; |
40 |
import org.gvsig.fmap.geom.operation.fromwkt.WKTParser; |
41 |
import org.gvsig.fmap.geom.primitive.Curve; |
42 |
import org.gvsig.tools.junit.AbstractLibraryAutoInitTestCase; |
43 |
import org.slf4j.Logger; |
44 |
import org.slf4j.LoggerFactory; |
45 |
|
46 |
/**
|
47 |
* @author jldominguez
|
48 |
*/
|
49 |
public class WKTParserTest extends AbstractLibraryAutoInitTestCase { |
50 |
private GeometryManager manager;
|
51 |
|
52 |
final static private Logger logger = LoggerFactory.getLogger("org.gvsig"); |
53 |
|
54 |
protected void doSetUp() throws Exception { |
55 |
manager = GeometryLocator.getGeometryManager(); |
56 |
} |
57 |
|
58 |
public void testParseWKT() throws InstantiationException, IllegalAccessException, CreateGeometryException{ |
59 |
|
60 |
|
61 |
WKTParser wp = new WKTParser();
|
62 |
try {
|
63 |
Geometry geom = wp.read("LINESTRING(0 0, 1 1, 2 1)");
|
64 |
|
65 |
Assert.assertTrue(geom instanceof Curve);
|
66 |
PathIterator piter = geom.getPathIterator(null); |
67 |
|
68 |
double[] curr = new double[6]; |
69 |
int type = 0; |
70 |
|
71 |
type = piter.currentSegment(curr); |
72 |
Assert.assertEquals(PathIterator.SEG_MOVETO, type);
|
73 |
Assert.assertEquals(0, curr[0], 0.0000000001); |
74 |
Assert.assertEquals(0, curr[1], 0.0000000001); |
75 |
piter.next(); |
76 |
|
77 |
type = piter.currentSegment(curr); |
78 |
Assert.assertEquals(PathIterator.SEG_LINETO, type);
|
79 |
Assert.assertEquals(1, curr[0], 0.0000000001); |
80 |
Assert.assertEquals(1, curr[1], 0.0000000001); |
81 |
piter.next(); |
82 |
|
83 |
type = piter.currentSegment(curr); |
84 |
Assert.assertEquals(PathIterator.SEG_LINETO, type);
|
85 |
Assert.assertEquals(2, curr[0], 0.0000000001); |
86 |
Assert.assertEquals(1, curr[1], 0.0000000001); |
87 |
|
88 |
piter.next(); |
89 |
Assert.assertTrue(piter.isDone()); |
90 |
|
91 |
} catch (ParseException e) { |
92 |
logger.info("Error while checking line string from WKT.", e);
|
93 |
Assert.assertTrue(e == null);
|
94 |
} |
95 |
|
96 |
} |
97 |
} |
98 |
|