@@ -236,4 +236,126 @@ public function testShapeName()
236
236
$ obj = new ShapeRecord (-1 );
237
237
$ this ->assertEquals ('Shape -1 ' , $ obj ->getShapeName ());
238
238
}
239
+
240
+ /**
241
+ * Test shapes save/load round robin
242
+ *
243
+ * @param int $type Shape type
244
+ * @param array $points Points
245
+ *
246
+ * @return void
247
+ *
248
+ * @dataProvider shapes
249
+ */
250
+ public function testShapeSaveLoad ($ type , $ points )
251
+ {
252
+ $ filename = "./data/test_shape- $ type.* " ;
253
+ $ shp = new ShapeFile ($ type );
254
+
255
+ $ record0 = new ShapeRecord ($ type );
256
+
257
+ foreach ($ points as $ point ) {
258
+ $ record0 ->addPoint ($ point [0 ], $ point [1 ]);
259
+ }
260
+
261
+ $ shp ->addRecord ($ record0 );
262
+
263
+ $ shp ->saveToFile ($ filename );
264
+
265
+ $ shp2 = new ShapeFile ($ type );
266
+ $ shp2 ->loadFromFile ($ filename );
267
+
268
+ $ this ->assertEquals (
269
+ count ($ shp ->records ),
270
+ count ($ shp2 ->records )
271
+ );
272
+
273
+ $ record = $ shp ->records [0 ];
274
+ $ record2 = $ shp2 ->records [0 ];
275
+
276
+ $ items = array ('numparts ' , 'numpoints ' );
277
+ foreach ($ items as $ item ) {
278
+ if (isset ($ record ->SHPData [$ item ])) {
279
+ $ this ->assertEquals (
280
+ $ record ->SHPData [$ item ],
281
+ $ record2 ->SHPData [$ item ]
282
+ );
283
+ }
284
+ }
285
+ }
286
+
287
+ /**
288
+ * Test shapes save/load round robin with z coordinate
289
+ *
290
+ * @param int $type Shape type
291
+ * @param array $points Points
292
+ *
293
+ * @return void
294
+ *
295
+ * @dataProvider shapes
296
+ */
297
+ public function testZetShapeSaveLoad ($ type , $ points )
298
+ {
299
+ $ this ->testShapeSaveLoad ($ type + 10 , $ points );
300
+ }
301
+
302
+ /**
303
+ * Test shapes save/load round robin with measure
304
+ *
305
+ * @param int $type Shape type
306
+ * @param array $points Points
307
+ *
308
+ * @return void
309
+ *
310
+ * @dataProvider shapes
311
+ */
312
+ public function testMeasureShapeSaveLoad ($ type , $ points )
313
+ {
314
+ $ this ->testShapeSaveLoad ($ type + 20 , $ points );
315
+ }
316
+
317
+ /**
318
+ * Data provider for save/load testing
319
+ *
320
+ * @return array
321
+ */
322
+ public function shapes ()
323
+ {
324
+ return array (
325
+ array (
326
+ 1 ,
327
+ array (
328
+ array (array ('x ' => 10 , 'y ' => 20 ), 0 ),
329
+ )
330
+ ),
331
+ array (
332
+ 3 ,
333
+ array (
334
+ array (array ('x ' => 10 , 'y ' => 20 ), 0 ),
335
+ array (array ('x ' => 20 , 'y ' => 20 ), 0 ),
336
+ array (array ('x ' => 20 , 'y ' => 20 ), 1 ),
337
+ array (array ('x ' => 20 , 'y ' => 10 ), 1 ),
338
+ )
339
+ ),
340
+ array (
341
+ 5 ,
342
+ array (
343
+ array (array ('x ' => 10 , 'y ' => 20 ), 0 ),
344
+ array (array ('x ' => 20 , 'y ' => 20 ), 0 ),
345
+ array (array ('x ' => 20 , 'y ' => 20 ), 1 ),
346
+ array (array ('x ' => 20 , 'y ' => 10 ), 1 ),
347
+ array (array ('x ' => 20 , 'y ' => 10 ), 2 ),
348
+ array (array ('x ' => 10 , 'y ' => 20 ), 2 ),
349
+ )
350
+ ),
351
+ array (
352
+ 8 ,
353
+ array (
354
+ array (array ('x ' => 10 , 'y ' => 20 ), 0 ),
355
+ array (array ('x ' => 20 , 'y ' => 20 ), 0 ),
356
+ array (array ('x ' => 20 , 'y ' => 10 ), 0 ),
357
+ )
358
+ ),
359
+ );
360
+ }
239
361
}
0 commit comments