NodeTest.java (21017B)
1 package osm.protobuf; 2 3 import java.io.File; 4 import java.io.RandomAccessFile; 5 import java.net.URI; 6 import java.util.Iterator; 7 import java.util.List; 8 9 import org.junit.Assert; 10 import org.junit.Test; 11 12 import osm.message.Entity; 13 import osm.message.Node; 14 15 /** 16 * Demonstrates how to read a file. Reads sample.pbf from the resources folder 17 * and prints details about it to the standard output. 18 * 19 * @author Michael Tandy 20 */ 21 public class NodeTest { 22 public static record ExpectedNode(long id, double latitude, double longitude) { 23 } 24 25 @Test 26 public void test() throws Exception { 27 ExpectedNode[] expected = new ExpectedNode[] { 28 new ExpectedNode(653970877, 51.763603, -0.228757), 29 new ExpectedNode(647105170, 51.763591, -0.234465), 30 new ExpectedNode(672663476, 51.765749, -0.229070), 31 new ExpectedNode(241806356, 51.768945, -0.232662), 32 new ExpectedNode(692945017, 51.766185, -0.230069), 33 new ExpectedNode(1709246734, 51.766433, -0.230854), 34 new ExpectedNode(175685506, 51.765169, -0.229374), 35 new ExpectedNode(647105129, 51.769327, -0.218457), 36 new ExpectedNode(647105160, 51.768192, -0.231686), 37 new ExpectedNode(672663473, 51.765530, -0.229187), 38 new ExpectedNode(647105141, 51.773204, -0.222598), 39 new ExpectedNode(25365926, 51.766340, -0.233556), 40 new ExpectedNode(1685167296, 51.766924, -0.234783), 41 new ExpectedNode(677439943, 51.763178, -0.230230), 42 new ExpectedNode(1701110757, 51.766400, -0.228489), 43 new ExpectedNode(663806673, 51.765470, -0.229220), 44 new ExpectedNode(502550970, 51.765118, -0.233667), 45 new ExpectedNode(692887095, 51.766318, -0.229190), 46 new ExpectedNode(1685167376, 51.760411, -0.241161), 47 new ExpectedNode(175697821, 51.765000, -0.232204), 48 new ExpectedNode(677438877, 51.764126, -0.228303), 49 new ExpectedNode(175685111, 51.764882, -0.229966), 50 new ExpectedNode(647105131, 51.769022, -0.217223), 51 new ExpectedNode(240134267, 51.764217, -0.233120), 52 new ExpectedNode(691203111, 51.765755, -0.230230), 53 new ExpectedNode(1685167394, 51.761213, -0.240218), 54 new ExpectedNode(534873274, 51.763918, -0.236563), 55 new ExpectedNode(676945192, 51.765148, -0.230615), 56 new ExpectedNode(691203106, 51.764494, -0.233449), 57 new ExpectedNode(647105155, 51.769580, -0.232061), 58 new ExpectedNode(32950368, 51.769048, -0.232790), 59 new ExpectedNode(647105133, 51.769183, -0.216784), 60 new ExpectedNode(175683944, 51.763140, -0.232112), 61 new ExpectedNode(623540467, 51.765719, -0.225990), 62 new ExpectedNode(647225601, 51.762732, -0.231722), 63 new ExpectedNode(32953195, 51.761987, -0.231091), 64 new ExpectedNode(653970876, 51.763436, -0.229153), 65 new ExpectedNode(676945352, 51.765646, -0.228469), 66 new ExpectedNode(663806670, 51.765540, -0.228771), 67 new ExpectedNode(1709246676, 51.766438, -0.231121), 68 new ExpectedNode(647105047, 51.774057, -0.222895), 69 new ExpectedNode(175697862, 51.765004, -0.232747), 70 new ExpectedNode(647105145, 51.771007, -0.230355), 71 new ExpectedNode(647105167, 51.762860, -0.236278), 72 new ExpectedNode(1111758067, 51.771433, -0.216984), 73 new ExpectedNode(647105166, 51.767468, -0.234229), 74 new ExpectedNode(692887118, 51.766186, -0.228918), 75 new ExpectedNode(663806658, 51.765679, -0.228614), 76 new ExpectedNode(175685507, 51.765508, -0.229788), 77 new ExpectedNode(647224486, 51.766388, -0.228706), 78 new ExpectedNode(502552074, 51.766711, -0.229590), 79 new ExpectedNode(647105132, 51.768905, -0.216932), 80 new ExpectedNode(25365925, 51.766651, -0.233518), 81 new ExpectedNode(623540472, 51.765321, -0.225475), 82 new ExpectedNode(691202857, 51.766804, -0.231711), 83 new ExpectedNode(175686201, 51.765721, -0.228361), 84 new ExpectedNode(927070648, 51.763087, -0.232061), 85 new ExpectedNode(25365924, 51.767090, -0.233453), 86 new ExpectedNode(676945335, 51.765388, -0.228437), 87 new ExpectedNode(647105127, 51.769321, -0.219637), 88 new ExpectedNode(647105134, 51.769124, -0.216290), 89 new ExpectedNode(30983853, 51.764268, -0.233185), 90 new ExpectedNode(647105164, 51.767548, -0.233295), 91 new ExpectedNode(502552081, 51.766833, -0.233484), 92 new ExpectedNode(691202855, 51.766809, -0.231946), 93 new ExpectedNode(647057820, 51.765382, -0.226710), 94 new ExpectedNode(691202869, 51.767216, -0.231947), 95 new ExpectedNode(647105159, 51.768849, -0.232458), 96 new ExpectedNode(1739780291, 51.764890, -0.226086), 97 new ExpectedNode(676945267, 51.763905, -0.228040), 98 new ExpectedNode(663806664, 51.765444, -0.229274), 99 new ExpectedNode(647105143, 51.771399, -0.230034), 100 new ExpectedNode(691202858, 51.765928, -0.232698), 101 new ExpectedNode(1701110775, 51.766290, -0.228709), 102 new ExpectedNode(365548881, 51.763854, -0.232807), 103 new ExpectedNode(647224465, 51.765604, -0.226263), 104 new ExpectedNode(691202873, 51.766711, -0.232826), 105 new ExpectedNode(287659881, 51.766233, -0.228823), 106 new ExpectedNode(1685167328, 51.765389, -0.235803), 107 new ExpectedNode(1685167381, 51.762135, -0.238938), 108 new ExpectedNode(1685167371, 51.768683, -0.233758), 109 new ExpectedNode(1709246791, 51.765771, -0.229747), 110 new ExpectedNode(647105156, 51.769420, -0.232072), 111 new ExpectedNode(647105139, 51.773291, -0.221257), 112 new ExpectedNode(32953193, 51.763418, -0.232387), 113 new ExpectedNode(676945199, 51.765151, -0.230782), 114 new ExpectedNode(647105147, 51.770210, -0.231976), 115 new ExpectedNode(672628083, 51.764391, -0.225433), 116 new ExpectedNode(25365922, 51.768145, -0.233167), 117 new ExpectedNode(1709246741, 51.765960, -0.229886), 118 new ExpectedNode(647105153, 51.769673, -0.232265), 119 new ExpectedNode(30983851, 51.765372, -0.233546), 120 new ExpectedNode(691202863, 51.765224, -0.232225), 121 new ExpectedNode(691202838, 51.767798, -0.233387), 122 new ExpectedNode(175684459, 51.763370, -0.231564), 123 new ExpectedNode(1685167313, 51.762503, -0.238485), 124 new ExpectedNode(692945016, 51.765714, -0.230069), 125 new ExpectedNode(25365921, 51.768513, -0.232722), 126 new ExpectedNode(676945322, 51.765118, -0.229479), 127 new ExpectedNode(534873251, 51.763658, -0.236760), 128 new ExpectedNode(1685167341, 51.768171, -0.234063), 129 new ExpectedNode(691203110, 51.765769, -0.230874), 130 new ExpectedNode(676945292, 51.764506, -0.228754), 131 new ExpectedNode(1685167391, 51.761506, -0.239827), 132 new ExpectedNode(676945241, 51.763212, -0.229644), 133 new ExpectedNode(663806653, 51.765898, -0.228877), 134 new ExpectedNode(623624259, 51.764905, -0.234965), 135 new ExpectedNode(1685167373, 51.763777, -0.237235), 136 new ExpectedNode(676945320, 51.765375, -0.230143), 137 new ExpectedNode(240134268, 51.764403, -0.232382), 138 new ExpectedNode(676945316, 51.764949, -0.230532), 139 new ExpectedNode(623624154, 51.765244, -0.234365), 140 new ExpectedNode(647105142, 51.774147, -0.226321), 141 new ExpectedNode(1739780285, 51.764824, -0.226000), 142 new ExpectedNode(175697671, 51.765012, -0.233620), 143 new ExpectedNode(647224613, 51.764970, -0.229134), 144 new ExpectedNode(647105121, 51.769055, -0.221268), 145 new ExpectedNode(692887101, 51.766293, -0.228488), 146 new ExpectedNode(175683342, 51.763273, -0.229558), 147 new ExpectedNode(240134269, 51.765577, -0.230133), 148 new ExpectedNode(691203053, 51.766871, -0.230638), 149 new ExpectedNode(1697422651, 51.763725, -0.228467), 150 new ExpectedNode(534873285, 51.764110, -0.236786), 151 new ExpectedNode(647105148, 51.770131, -0.232104), 152 new ExpectedNode(647105165, 51.767482, -0.233317), 153 new ExpectedNode(534873185, 51.763403, -0.236752), 154 new ExpectedNode(175685104, 51.764391, -0.231506), 155 new ExpectedNode(647105163, 51.768079, -0.233048), 156 new ExpectedNode(651652536, 51.764591, -0.224432), 157 new ExpectedNode(647105115, 51.766990, -0.227373), 158 new ExpectedNode(677439944, 51.763332, -0.229790), 159 new ExpectedNode(647105162, 51.768232, -0.232866), 160 new ExpectedNode(676945319, 51.765218, -0.230449), 161 new ExpectedNode(1539682123, 51.769102, -0.232828), 162 new ExpectedNode(534873208, 51.763536, -0.236889), 163 new ExpectedNode(647105128, 51.769354, -0.219090), 164 new ExpectedNode(1739780280, 51.764758, -0.225914), 165 new ExpectedNode(175698323, 51.767216, -0.231110), 166 new ExpectedNode(676945189, 51.764650, -0.230926), 167 new ExpectedNode(1739780294, 51.764955, -0.224922), 168 new ExpectedNode(676945326, 51.765291, -0.229382), 169 new ExpectedNode(663806672, 51.765417, -0.229059), 170 new ExpectedNode(45169425, 51.769130, -0.233478), 171 new ExpectedNode(672663469, 51.765930, -0.229036), 172 new ExpectedNode(675146, 51.769270, -0.232860), 173 new ExpectedNode(691203054, 51.766658, -0.230273), 174 new ExpectedNode(1606957353, 51.760049, -0.241558), 175 new ExpectedNode(647105125, 51.769248, -0.220260), 176 new ExpectedNode(534874147, 51.765262, -0.235825), 177 new ExpectedNode(14713407, 51.765828, -0.227391), 178 new ExpectedNode(818056434, 51.766040, -0.233470), 179 new ExpectedNode(1111758069, 51.769198, -0.216444), 180 new ExpectedNode(175699187, 51.765663, -0.231004), 181 new ExpectedNode(175698155, 51.767389, -0.230809), 182 new ExpectedNode(691202861, 51.765516, -0.231002), 183 new ExpectedNode(651594517, 51.763745, -0.228419), 184 new ExpectedNode(691203051, 51.765901, -0.231217), 185 new ExpectedNode(647224485, 51.765127, -0.226399), 186 new ExpectedNode(1709246749, 51.765632, -0.230025), 187 new ExpectedNode(677440300, 51.762625, -0.231624), 188 new ExpectedNode(647105172, 51.764294, -0.233070), 189 new ExpectedNode(175686498, 51.765424, -0.228052), 190 new ExpectedNode(692944963, 51.764665, -0.233953), 191 new ExpectedNode(663806656, 51.765763, -0.228715), 192 new ExpectedNode(647105154, 51.769626, -0.232179), 193 new ExpectedNode(676945317, 51.765015, -0.230385), 194 new ExpectedNode(647105169, 51.763033, -0.235323), 195 new ExpectedNode(692945021, 51.766617, -0.229479), 196 new ExpectedNode(1709246789, 51.766231, -0.230173), 197 new ExpectedNode(175686499, 51.765976, -0.228635), 198 new ExpectedNode(691202866, 51.767110, -0.232955), 199 new ExpectedNode(1111758072, 51.769507, -0.216315), 200 new ExpectedNode(647105123, 51.769155, -0.220818), 201 new ExpectedNode(672663468, 51.765622, -0.228672), 202 new ExpectedNode(676945197, 51.765281, -0.230541), 203 new ExpectedNode(692945020, 51.766471, -0.229673), 204 new ExpectedNode(175697881, 51.764664, -0.232747), 205 new ExpectedNode(175685109, 51.764946, -0.230095), 206 new ExpectedNode(1685167304, 51.760787, -0.240738), 207 new ExpectedNode(692944951, 51.764943, -0.234254), 208 new ExpectedNode(692945019, 51.766225, -0.229673), 209 new ExpectedNode(676945334, 51.765467, -0.228255), 210 new ExpectedNode(175684463, 51.765445, -0.226790), 211 new ExpectedNode(692944957, 51.764651, -0.234168), 212 new ExpectedNode(647105144, 51.771332, -0.229905), 213 new ExpectedNode(691203055, 51.765928, -0.230187), 214 new ExpectedNode(676945331, 51.765589, -0.229749), 215 new ExpectedNode(672663474, 51.765638, -0.229315), 216 new ExpectedNode(647105146, 51.770283, -0.231836), 217 new ExpectedNode(534873171, 51.763005, -0.237147), 218 new ExpectedNode(647105157, 51.769307, -0.232308), 219 new ExpectedNode(676945327, 51.765347, -0.229744), 220 new ExpectedNode(675150, 51.766907, -0.229904), 221 new ExpectedNode(663806666, 51.765165, -0.228973), 222 new ExpectedNode(691202871, 51.766950, -0.232826), 223 new ExpectedNode(672663477, 51.765646, -0.228948), 224 new ExpectedNode(647105158, 51.769015, -0.232297), 225 new ExpectedNode(673784380, 51.762202, -0.231241), 226 new ExpectedNode(647105152, 51.769739, -0.232330), 227 new ExpectedNode(692945022, 51.766344, -0.228825), 228 new ExpectedNode(676945315, 51.764929, -0.230336), 229 new ExpectedNode(676945346, 51.765450, -0.228506), 230 new ExpectedNode(647105119, 51.768119, -0.223854), 231 new ExpectedNode(175698430, 51.766924, -0.231110), 232 new ExpectedNode(1685167387, 51.765901, -0.235408), 233 new ExpectedNode(175685910, 51.766003, -0.227820), 234 new ExpectedNode(820969139, 51.767836, -0.231358), 235 new ExpectedNode(647105102, 51.763883, -0.232727), 236 new ExpectedNode(675151, 51.766141, -0.228136), 237 new ExpectedNode(175698324, 51.766008, -0.231131), 238 new ExpectedNode(1685167282, 51.762958, -0.237989), 239 new ExpectedNode(502552090, 51.765557, -0.233577), 240 new ExpectedNode(623624155, 51.765449, -0.234590), 241 new ExpectedNode(267826070, 51.764017, -0.232970), 242 new ExpectedNode(25365930, 51.766791, -0.234972), 243 new ExpectedNode(676945195, 51.765156, -0.230570), 244 new ExpectedNode(1709246675, 51.766423, -0.230168), 245 new ExpectedNode(647105137, 51.774248, -0.218055), 246 new ExpectedNode(651652534, 51.764261, -0.225160), 247 new ExpectedNode(676945293, 51.764816, -0.229133), 248 new ExpectedNode(1692947499, 51.773860, -0.225851), 249 new ExpectedNode(623624257, 51.765396, -0.234075), 250 new ExpectedNode(175697824, 51.764998, -0.232032), 251 new ExpectedNode(672663478, 51.765575, -0.229104), 252 new ExpectedNode(1685167290, 51.763311, -0.237639), 253 new ExpectedNode(390911769, 51.766861, -0.229798), 254 new ExpectedNode(676945323, 51.765506, -0.229937), 255 new ExpectedNode(647105136, 51.773720, -0.217976), 256 new ExpectedNode(1539682039, 51.768036, -0.233265), 257 new ExpectedNode(691202860, 51.766247, -0.230595), 258 new ExpectedNode(1145410964, 51.769148, -0.232860), 259 new ExpectedNode(647105130, 51.769188, -0.217728), 260 new ExpectedNode(691203049, 51.766645, -0.234564), 261 new ExpectedNode(1539682089, 51.768368, -0.232938), 262 new ExpectedNode(175698550, 51.766911, -0.230809), 263 new ExpectedNode(623540479, 51.765560, -0.224961), 264 new ExpectedNode(677439941, 51.763240, -0.230472), 265 new ExpectedNode(25365927, 51.766333, -0.232681), 266 new ExpectedNode(647105135, 51.770431, -0.216476), 267 new ExpectedNode(30983852, 51.764773, -0.233577), 268 new ExpectedNode(647105150, 51.769938, -0.232265), 269 new ExpectedNode(623624261, 51.764407, -0.235985), 270 new ExpectedNode(647105149, 51.770024, -0.232212), 271 new ExpectedNode(677439946, 51.763219, -0.229690), 272 new ExpectedNode(691203109, 51.765671, -0.232912), 273 new ExpectedNode(647105171, 51.764248, -0.233242), 274 new ExpectedNode(1709246746, 51.766196, -0.230058), 275 new ExpectedNode(175685106, 51.764728, -0.230781), 276 new ExpectedNode(663806661, 51.765857, -0.228507), 277 new ExpectedNode(677439947, 51.764197, -0.228387), 278 new ExpectedNode(647105117, 51.767435, -0.226150), 279 new ExpectedNode(647105168, 51.762754, -0.235838), 280 new ExpectedNode(623624267, 51.764016, -0.233964), 281 new ExpectedNode(1709246737, 51.766423, -0.230671), 282 new ExpectedNode(175684462, 51.764271, -0.229245), 283 new ExpectedNode(175698551, 51.766539, -0.230166), 284 new ExpectedNode(675148, 51.768657, -0.232378), 285 new ExpectedNode(676945332, 51.764887, -0.229157), 286 new ExpectedNode(675149, 51.767913, -0.231459), 287 new ExpectedNode(692945018, 51.766178, -0.229758), 288 new ExpectedNode(623540483, 51.765155, -0.224456), 289 new ExpectedNode(676945350, 51.765533, -0.228712), 290 new ExpectedNode(175698975, 51.765729, -0.233577), 291 new ExpectedNode(175685102, 51.764176, -0.232069), 292 new ExpectedNode(676945347, 51.765417, -0.228572), 293 new ExpectedNode(534873262, 51.763775, -0.236889), 294 new ExpectedNode(25365931, 51.765437, -0.236066), 295 new ExpectedNode(672663470, 51.765668, -0.229614), 296 new ExpectedNode(647105138, 51.773941, -0.221418), 297 new ExpectedNode(647105151, 51.769819, -0.232340), 298 new ExpectedNode(32953194, 51.762232, -0.231263), 299 new ExpectedNode(1685167315, 51.766349, -0.235121), 300 new ExpectedNode(1111758071, 51.769058, -0.216775), 301 new ExpectedNode(691203098, 51.764324, -0.234279), 302 new ExpectedNode(175698553, 51.766253, -0.230172), 303 new ExpectedNode(1685167287, 51.767572, -0.234395), 304 new ExpectedNode(672663471, 51.765452, -0.229359), 305 new ExpectedNode(676945325, 51.765209, -0.229575), 306 new ExpectedNode(623624156, 51.765622, -0.234693), 307 new ExpectedNode(647105140, 51.773198, -0.222341), 308 new ExpectedNode(25365928, 51.766333, -0.232198), 309 new ExpectedNode(676945329, 51.765389, -0.229634), 310 new ExpectedNode(663806668, 51.765337, -0.228533), 311 new ExpectedNode(692944966, 51.764977, -0.233985), 312 new ExpectedNode(691203099, 51.764162, -0.234157), 313 new ExpectedNode(175685100, 51.764091, -0.232103), 314 new ExpectedNode(25365923, 51.767521, -0.233449), 315 new ExpectedNode(647105161, 51.767973, -0.232169), 316 new ExpectedNode(672663467, 51.765478, -0.228989), 317 new ExpectedNode(691202854, 51.766818, -0.232419) 318 }; 319 320 URI testFileURL = NodeTest.class.getClassLoader().getResource("protobuf-test.osm.pbf").toURI(); 321 322 Iterator<Entity> entities = new BlobSpliterator( 323 new RandomAccessFile(new File(testFileURL), "r"), 324 System.out::println) 325 .stream() 326 .flatMap(List::stream) 327 .filter(Node.class::isInstance) 328 .iterator(); 329 330 int expectedIndex = 0; 331 while (entities.hasNext() && expectedIndex < expected.length) { 332 Node node = (Node) entities.next(); 333 ExpectedNode ex = expected[expectedIndex]; 334 335 Assert.assertEquals(ex.id, node.getID()); 336 Assert.assertTrue("latitude", Math.abs(ex.latitude - node.getLatitude()) < 0.1); 337 Assert.assertTrue("longitude", 338 Math.abs(ex.longitude - node.getLongitude()) < 0.1); 339 340 expectedIndex++; 341 } 342 } 343 }