|
17 | 17 |
|
18 | 18 | import org.locationtech.jts.geom.CoordinateSequence; |
19 | 19 | import org.locationtech.jts.geom.MultiPolygon; |
| 20 | +import org.locationtech.jts.geom.Point; |
20 | 21 | import org.locationtech.jts.geom.Polygon; |
21 | 22 |
|
22 | 23 | public class MIFFeatureReaderTest { |
23 | 24 |
|
24 | 25 | @Test |
25 | 26 | public void testReadingEmptyMIDFields() throws URISyntaxException, IOException { |
26 | | - try { |
27 | | - File mif = new File(getClass().getResource("empty_fields.MIF").toURI()); |
28 | | - File mid = new File(getClass().getResource("empty_fields.MID").toURI()); |
29 | | - DataStore store = new MIFDataStore(mif, mid); |
30 | | - SimpleFeatureSource source = store.getFeatureSource("empty_fields"); |
31 | | - SimpleFeatureCollection fc = source.getFeatures(); |
32 | | - Assertions.assertEquals(1, fc.size()); |
33 | | - try (SimpleFeatureIterator it = fc.features()) { |
34 | | - if (!it.hasNext()) { |
35 | | - Assertions.fail(); |
36 | | - } |
37 | | - SimpleFeature f = it.next(); |
38 | | - |
39 | | - /* |
40 | | - Region 1 |
41 | | - 4 |
42 | | - 357517.2 6860602.8 |
43 | | - 357539.1 6860613.8 |
44 | | - 357556.1 6860578.1 |
45 | | - 357533.8 6860567.8 |
46 | | - */ |
47 | | - Polygon region = (Polygon) f.getDefaultGeometry(); |
48 | | - Assertions.assertEquals(5, region.getNumPoints()); // +1 because ring is automatically closed |
49 | | - Assertions.assertEquals(0, region.getNumInteriorRing()); |
50 | | - |
51 | | - CoordinateSequence csq = region.getExteriorRing().getCoordinateSequence(); |
52 | | - Assertions.assertEquals(357517.2, csq.getOrdinate(0, 0), 1e-9); |
53 | | - Assertions.assertEquals(6860602.8, csq.getOrdinate(0, 1), 1e-9); |
54 | | - Assertions.assertEquals(357539.1, csq.getOrdinate(1, 0), 1e-9); |
55 | | - Assertions.assertEquals(6860613.8, csq.getOrdinate(1, 1), 1e-9); |
56 | | - Assertions.assertEquals(357556.1, csq.getOrdinate(2, 0), 1e-9); |
57 | | - Assertions.assertEquals(6860578.1, csq.getOrdinate(2, 1), 1e-9); |
58 | | - Assertions.assertEquals(357533.8, csq.getOrdinate(3, 0), 1e-9); |
59 | | - Assertions.assertEquals(6860567.8, csq.getOrdinate(3, 1), 1e-9); |
60 | | - Assertions.assertEquals(357517.2, csq.getOrdinate(4, 0), 1e-9); |
61 | | - Assertions.assertEquals(6860602.8, csq.getOrdinate(4, 1), 1e-9); |
62 | | - |
63 | | - Assertions.assertNull(f.getAttribute("id")); |
64 | | - Assertions.assertEquals(Integer.class, f.getProperty("id").getType().getBinding()); |
65 | | - |
66 | | - Assertions.assertNull(f.getAttribute("foo")); |
67 | | - Assertions.assertEquals(Long.class, f.getProperty("foo").getType().getBinding()); |
68 | | - |
69 | | - Assertions.assertNull(f.getAttribute("bar")); |
70 | | - Assertions.assertEquals(Float.class, f.getProperty("bar").getType().getBinding()); |
71 | | - |
72 | | - Assertions.assertNull(f.getAttribute("baz")); |
73 | | - Assertions.assertEquals(Double.class, f.getProperty("baz").getType().getBinding()); |
74 | | - |
75 | | - Assertions.assertNull(f.getAttribute("qux")); |
76 | | - Assertions.assertEquals(Boolean.class, f.getProperty("qux").getType().getBinding()); |
77 | | - |
78 | | - if (it.hasNext()) { |
79 | | - Assertions.fail(); |
80 | | - } |
| 27 | + File mif = new File(getClass().getResource("empty_fields.MIF").toURI()); |
| 28 | + File mid = new File(getClass().getResource("empty_fields.MID").toURI()); |
| 29 | + DataStore store = new MIFDataStore(mif, mid); |
| 30 | + SimpleFeatureSource source = store.getFeatureSource("empty_fields"); |
| 31 | + SimpleFeatureCollection fc = source.getFeatures(); |
| 32 | + Assertions.assertEquals(1, fc.size()); |
| 33 | + try (SimpleFeatureIterator it = fc.features()) { |
| 34 | + if (!it.hasNext()) { |
| 35 | + Assertions.fail(); |
| 36 | + } |
| 37 | + SimpleFeature f = it.next(); |
| 38 | + |
| 39 | + /* |
| 40 | + Region 1 |
| 41 | + 4 |
| 42 | + 357517.2 6860602.8 |
| 43 | + 357539.1 6860613.8 |
| 44 | + 357556.1 6860578.1 |
| 45 | + 357533.8 6860567.8 |
| 46 | + */ |
| 47 | + Polygon region = (Polygon) f.getDefaultGeometry(); |
| 48 | + Assertions.assertEquals(5, region.getNumPoints()); // +1 because ring is automatically closed |
| 49 | + Assertions.assertEquals(0, region.getNumInteriorRing()); |
| 50 | + |
| 51 | + CoordinateSequence csq = region.getExteriorRing().getCoordinateSequence(); |
| 52 | + Assertions.assertEquals(357517.2, csq.getOrdinate(0, 0), 1e-9); |
| 53 | + Assertions.assertEquals(6860602.8, csq.getOrdinate(0, 1), 1e-9); |
| 54 | + Assertions.assertEquals(357539.1, csq.getOrdinate(1, 0), 1e-9); |
| 55 | + Assertions.assertEquals(6860613.8, csq.getOrdinate(1, 1), 1e-9); |
| 56 | + Assertions.assertEquals(357556.1, csq.getOrdinate(2, 0), 1e-9); |
| 57 | + Assertions.assertEquals(6860578.1, csq.getOrdinate(2, 1), 1e-9); |
| 58 | + Assertions.assertEquals(357533.8, csq.getOrdinate(3, 0), 1e-9); |
| 59 | + Assertions.assertEquals(6860567.8, csq.getOrdinate(3, 1), 1e-9); |
| 60 | + Assertions.assertEquals(357517.2, csq.getOrdinate(4, 0), 1e-9); |
| 61 | + Assertions.assertEquals(6860602.8, csq.getOrdinate(4, 1), 1e-9); |
| 62 | + |
| 63 | + Assertions.assertNull(f.getAttribute("id")); |
| 64 | + Assertions.assertEquals(Integer.class, f.getProperty("id").getType().getBinding()); |
| 65 | + |
| 66 | + Assertions.assertNull(f.getAttribute("foo")); |
| 67 | + Assertions.assertEquals(Long.class, f.getProperty("foo").getType().getBinding()); |
| 68 | + |
| 69 | + Assertions.assertNull(f.getAttribute("bar")); |
| 70 | + Assertions.assertEquals(Float.class, f.getProperty("bar").getType().getBinding()); |
| 71 | + |
| 72 | + Assertions.assertNull(f.getAttribute("baz")); |
| 73 | + Assertions.assertEquals(Double.class, f.getProperty("baz").getType().getBinding()); |
| 74 | + |
| 75 | + Assertions.assertNull(f.getAttribute("qux")); |
| 76 | + Assertions.assertEquals(Boolean.class, f.getProperty("qux").getType().getBinding()); |
| 77 | + |
| 78 | + if (it.hasNext()) { |
| 79 | + Assertions.fail(); |
81 | 80 | } |
82 | | - } catch (Exception e) { |
83 | | - e.printStackTrace(); |
84 | 81 | } |
85 | 82 | } |
86 | 83 |
|
@@ -170,4 +167,49 @@ public void testFeatureReader() throws URISyntaxException, IOException { |
170 | 167 | } |
171 | 168 | } |
172 | 169 |
|
| 170 | + @Test |
| 171 | + public void testReadingTextstringOnSeparateLine() throws URISyntaxException, IOException { |
| 172 | + File mif = new File(getClass().getResource("textstring_separate_line.mif").toURI()); |
| 173 | + File fakeMid = new File("anything_that_doesnt_exists"); |
| 174 | + |
| 175 | + DataStore store = new MIFDataStore(mif, fakeMid); |
| 176 | + SimpleFeatureSource source = store.getFeatureSource("textstring_separate_line"); |
| 177 | + SimpleFeatureCollection fc = source.getFeatures(); |
| 178 | + Assertions.assertEquals(2, fc.size()); |
| 179 | + try (SimpleFeatureIterator it = fc.features()) { |
| 180 | + if (!it.hasNext()) { |
| 181 | + Assertions.fail(); |
| 182 | + } |
| 183 | + SimpleFeature f = it.next(); |
| 184 | + |
| 185 | + /* |
| 186 | + REGION 1 |
| 187 | + 8 |
| 188 | + 321129.582 7003475.008 |
| 189 | + 319770.969 7003405.009 |
| 190 | + 319492.514 7003390.491 |
| 191 | + 319479.797 7003389.828 |
| 192 | + 318699.691 7003352.012 |
| 193 | + 318696.539 7003426.558 |
| 194 | + 321120.18 7003556.465 |
| 195 | + 321129.582 7003475.008 |
| 196 | + BRUSH(1,0) |
| 197 | + */ |
| 198 | + Polygon region = (Polygon) f.getDefaultGeometry(); |
| 199 | + Assertions.assertEquals(8, region.getNumPoints()); |
| 200 | + Assertions.assertEquals(0, region.getNumInteriorRing()); |
| 201 | + |
| 202 | + /* |
| 203 | + TEXT |
| 204 | + "233-404-5-70" |
| 205 | + 319350.402 7003400.612 319415.202 7003405.612 |
| 206 | + */ |
| 207 | + if (!it.hasNext()) { |
| 208 | + Assertions.fail(); |
| 209 | + } |
| 210 | + f = it.next(); |
| 211 | + Assertions.assertEquals(Point.class, f.getDefaultGeometry().getClass()); |
| 212 | + } |
| 213 | + } |
| 214 | + |
173 | 215 | } |
0 commit comments