-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patherreur_topo.R
746 lines (525 loc) · 23.8 KB
/
erreur_topo.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
# Date: 2022-09-08
# Author: Olivier Leroy www.branchtwigleaf.com/
# Goal:
# Produce a set of topology errors to test them against classic
# functions to correct them
# I elected to work with list because some topology errors require more than one
# polygon
# library used sf, sfheaders
# inspiration :
# http://s3.cleverelephant.ca/invalid.html from P.Ramsey
# library used sf, sfheaders
library(sf)
library(sfheaders)
## 1. usefull functions ======================================================
source("src/functions.R")
## 2. Creating a big list of error =============================================
# TODO maybe divide name into "family of errors"
create_my_errors <- function(){
errors <- list()
## 2.1 Polygon =================================================================
### 1. Polygon - Exverted shell, point touch
df <- data.frame(
x = c(1, 1, 4, 8, 8, 4, 1),
y = c(1, 8, 6, 1, 8, 6, 1)
)
df_sf <- sfheaders::sf_polygon(df)
df_sf$id <- "Polygon - Exverted shell, point touch"
# df_sf$sf_type <- extract_first_word(df_sf$id)
errors[[df_sf$id]] <- df_sf
## 2. Polygon - Exverted shell, point-line touch
df <- data.frame(
x = c(1, 1, 8, 8, 5, 1),
y = c(1, 8, 8, 1, 8, 1)
)
## add to the list
df_sf <- sfheaders::sf_polygon(df)
df_sf$id <- "Polygon - Exverted shell, point-line touch"
df_sf$sf_type <- extract_first_word(df_sf$id)
errors[[df_sf$id]] <- df_sf
## 3. Polygon - Exverted shell, line touch
df <- data.frame(
x = c(1, 1, 8, 8, 5, 3, 1),
y = c(1, 8, 8, 1, 8, 8, 1)
)
df_sf <- sfheaders::sf_polygon(df)
df_sf$id <- "Polygon - Exverted shell, line touch"
df_sf$sf_type <- extract_first_word(df_sf$id)
errors[[df_sf$id]] <- df_sf
## 4. Polygon - Inverted shell, point touch
df <- data.frame(
x = c(1, 1, 4, 2, 6, 4, 8, 8, 1),
y = c(1, 8, 8, 5, 5, 8, 8, 1, 1)
)
df_sf <- sfheaders::sf_polygon(df)
df_sf$id <- "Polygon - Inverted shell, point touch"
df_sf$sf_type <- extract_first_word(df_sf$id)
errors[[df_sf$id]] <- df_sf
## 5. Polygon - Inverted shell, point-line touch
df <- data.frame(
x = c(1, 1, 3, 3, 7, 3, 8, 8, 1),
y = c(1, 8, 8, 2, 2, 5, 5, 1, 1)
)
#quick_plot(df)
df_sf <- sfheaders::sf_polygon(df)
df_sf$id <- "Polygon - Inverted shell, point-line touch"
errors[[df_sf$id]] <- df_sf
## 6. Polygon - Inverted shell, line touch, exterior
df <- data.frame(
x = c(1, 1, 6, 6, 3, 3, 8, 8, 1),
y = c(1, 8, 8, 4, 4, 8, 8, 1, 1)
)
df_sf <- sfheaders::sf_polygon(df)
df_sf$id <- "Polygon - Inverted shell, line touch, exterior"
errors[[df_sf$id]] <- df_sf
## 7. Polygon - Inverted shell, line touch, interior
df <- data.frame(
x = c(1, 1, 4.5, 4.5, 3, 6, 4.5, 4.5, 8, 8, 1 ),
y = c(1, 8, 8, 6 , 3.5, 3.5, 6, 8, 8, 1, 1 )
)
df_sf <- sfheaders::sf_polygon(df)
df_sf$id <- "Polygon - Inverted shell, line touch, interior"
errors[[df_sf$id]] <- df_sf
## 8 polygon/hole Exverted hole, point touch
# here I think I need sf
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,2), c(2,6), c(4,5), c(6,2), c(6,6), c(4,5), c(2,2))
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Exverted hole, point touch")
errors[[pol_sf1$id]] <- pol_sf1
## 9 Polygon/hole Exverted hole, point-line touch
p2 <- rbind(c(2,2), c(2,6), c(6,6), c(6,2), c(4,6), c(2,2))
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Exverted hole, point-line touch")
errors[[pol_sf1$id]] <- pol_sf1
## 10 Polygon/Hole Exverted hole, line touch
p2 <- rbind(c(2,2), c(2,6), c(3,5), c(4,5), c(6,6), c(6,2), c(4,5), c(3,5), c(2,2))
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Exverted hole, line touch")
errors[[pol_sf1$id]] <- pol_sf1
## 11 Polygon/hole - Inverted hole, point touch
inner <- data.frame(
x = c(1, 1, 4, 2, 6, 4, 8, 8, 1),
y = c(1, 8, 8, 5, 5, 8, 8, 1, 1)
)
# scaling
p2 <- scaling_sfheader(inner)
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Inverted hole, point touch")
errors[[pol_sf1$id]] <- pol_sf1
## 12 Polygon/Hole - Inverted hole, point-line touch
inner <- data.frame(
x = c(1, 1, 3, 3, 7, 3, 8, 8, 1),
y = c(1, 8, 8, 2, 2, 5, 5, 1, 1)
)
p2 <- scaling_sfheader(inner)
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Inverted hole, point-line touch")
errors[[pol_sf1$id]] <- pol_sf1
## 13. Polygon/Hole - Inverted hole, line touch, interior
inner <- data.frame(
x = c(1, 1, 6, 6, 3, 3, 8, 8, 1),
y = c(1, 8, 8, 4, 4, 8, 8, 1, 1)
)
p2 <- scaling_sfheader(inner)
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Inverted hole, line touch, interior")
errors[[pol_sf1$id]] <- pol_sf1
## 14. Polygon/Hole - Inverted hole, line touch, exterior
p2 <- rbind(c(2,2), c(7, 2), c(4.5, 7), c(4.5, 5), c(3.5, 3.5), c(5.5, 3.5),
c(4.5, 5), c(4.5, 7), c(2,2))
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Inverted hole, line touch, exterior")
errors[[pol_sf1$id]] <- pol_sf1
## 15. Polygon/Hole - Exverted shell, point touch; exverted hole, point touch
p1 <- rbind(c(1,1), c(1,8), c(8,1), c(8,8), c(1,1))
p2 <- rbind(c(2,3), c(2,6), c(7,3), c(7,6), c(2,3))
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Exverted shell, point touch; exverted hole, point touch")
errors[[pol_sf1$id]] <- pol_sf1
## 16. Polygon/Hole - Exverted shell, point touch; exverted hole, line touch
p2 <- rbind(c(2,3), c(2,6), c(3.5, 4.5), c(5.5, 4.5)
, c(7,3), c(7,6),
c(5.5, 4.5), c(3.5, 4.5),
c(2,3))
pol <-st_polygon(list(p1,p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Exverted shell, point touch; exverted hole, line touch")
errors[[pol_sf1$id]] <- pol_sf1
## 17. Polygon/Hole - Exverted shell, line touch; exverted hole, line touch
p1 <- rbind(c(1,1), c(1,8), c(3.5, 4.5), c(5.5, 4.5), c(8,1), c(8,8),
c(5.5, 4.5), c(3.5, 4.5), c(1,1))
p2 <- rbind(c(2,3), c(2,6), c(3, 4.5), c(6, 4.5), c(7,3), c(7,6),
c(6, 4.5), c(3, 4.5), c(2,3))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Exverted shell, line touch; exverted hole, line touch")
errors[[pol_sf1$id]] <- pol_sf1
## 18. Polygon/Hole - Adjacent
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(5, 3), c(5,6), c(8,6), c(8, 3), c(5,3))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Adjacent")
errors[[pol_sf1$id]] <- pol_sf1
## 19. Polygon/Holes - Adjacent holes
p2 <- rbind(c(3, 3), c(3,6), c(4.5,6), c(4.5, 3), c(3,3))
p3 <- rbind(c(4.5, 4), c(4.5, 5), c(5.5, 5), c(5.5, 4), c(4.5, 4))
pol <-st_polygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Adjacent holes")
errors[[pol_sf1$id]] <- pol_sf1
## 20. Polygon/Holes - Exverted holes crossing at point
# I think it is two inner rings but could be wrong
# I should check if middle point is needed
p2 <- rbind(c(4, 7), c(5, 7), c(4.5, 4.5), c(4,2), c(5,2), c(4.5, 4.5), c(4, 7))
p3 <- rbind(c(2, 4), c(2, 5), c(4.5, 4.5), c(7, 4), c(7,5), c(4.5, 4.5), c(2,4))
pol <-st_polygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Exverted holes crossing at point")
errors[[pol_sf1$id]] <- pol_sf1
## 21. Polygon/Holes - Exverted holes crossing at line
p2 <- rbind(c(4, 7), c(5, 7),c(4.5, 6), c(4.5, 3),
c(4,2), c(5,2), c(4.5, 3), c(4.5, 6), c(4,7))
p3 <- rbind(c(2, 4), c(2, 5), c(3, 4.5), c(6, 4.5),
c(7, 4), c(7,5), c(6, 4.5), c(3, 4.5), c(2,4))
pol <-st_polygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Exverted holes crossing at line")
errors[[pol_sf1$id]] <- pol_sf1
## 22. Polygon - Zero area
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(1,8), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Zero area")
errors[[pol_sf1$id]] <- pol_sf1
## 23. Polygon - Zero-width gore
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(4.5, 4.5), c(8,8), c(8,1), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Zero-width gore")
errors[[pol_sf1$id]] <- pol_sf1
## 24. Polygon - Zero-width gore splitting
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(1, 1), c(8,8), c(8,1), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Zero-width gore splitting")
errors[[pol_sf1$id]] <- pol_sf1
## 25. Polygon - Zero-width spike
p1 <- rbind(c(4,1), c(1,1), c(1,4), c(4,4), c(8, 8), c(4,4), c(4,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Zero-width spike")
errors[[pol_sf1$id]] <- pol_sf1
## 26. Zero-width spike along boundary
p1 <- rbind(c(1,1), c(1,8), c(6,8), c(3,8), c(8,8), c(8,1), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Zero-width spike along boundary")
errors[[pol_sf1$id]] <- pol_sf1
## 27. Polygon/Hole - Zero-width spike splitting hole
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(3,3), c(3, 6), c(6,6), c(6,3), c(5,3), c(3,5), c(5,3), c(3,3))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Zero-width spike splitting hole")
errors[[pol_sf1$id]] <- pol_sf1
## 28. Polygon - Zero-width spike enclosing area
# unsure of this one
p1 <- rbind(c(1,1), c(1,8), c(4,8), c(8,5), c(4,1), c(4,8), c(4,1), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Zero-width spike enclosing area")
errors[[pol_sf1$id]] <- pol_sf1
## 29. MultiPolygon - Adjacent
df <- data.frame(
id = c(1,1,1,1,2,2,2,2)
, x = c(1,1,4,4,4,4,6,6)
, y = c(1,8,8,1,3,6,6,3)
)
multipol <- sfheaders::sf_multipolygon(df,
multipolygon_id = "id",
polygon_id = "id",
linestring_id = "id")
df$id <- "MultiPolygon - Adjacent"
errors[["MultiPolygon - Adjacent"]] <- multipol
## 30. MultiPolygon - Exverted crossing at point
df <- data.frame(
id = c(1,1,1 ,1,1, 2,2,2 ,2,2)
, x = c(2,7,4.5,2,7, 2,2,4.5,7,7)
, y = c(1,1,4.5,8,8, 2,7,4.5,2,7)
)
multipol <- sfheaders::sf_multipolygon(df,
multipolygon_id = "id",
polygon_id = "id",
linestring_id = "id")
errors[["MultiPolygon - Exverted crossing at point"]] <- multipol
## 31. MultiPolygon - Exverted crossing at line
df <- data.frame(
id = c(1, 1, 1 ,1 , 1 ,1 ,1 ,1 ,2 ,2,2,2 ,2 ,2,2,2 )
, x = c(3.5, 1, 1 ,3.5, 5.5,8 ,8 ,5.5,4.5,2,7,4.5,4.5,2,7,4.5 )
, y = c(4.5, 1.5,7.5,4.5, 4.5,7.5,1.5,4.5,3.5,1,1,3.5,5.5,8,8,5.5 )
)
multipol <- sfheaders::sf_multipolygon(df,
multipolygon_id = "id",
polygon_id = "id",
linestring_id = "id")
errors[["MultiPolygon - Exverted crossing at line"]] <- multipol
## 32. Polygon - Bowtie (Figure 8)
p1 <- rbind(c(1,1), c(1,8), c(8,1), c(8,8), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Bowtie (Figure 8)")
errors[[pol_sf1$id]] <- pol_sf1
## 33. Polygon - Bowtie Multiple
p1 <- rbind(c(1,4), c(1,5), c(5,1), c(4,1), c(8,5), c(8,4), c(4,8), c(5,8), c(1,4))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Bowtie Multiple")
errors[[pol_sf1$id]] <- pol_sf1
## 34. Polygon - Bowtie, self-overlap
p1 <- rbind(c(1,1.5), c(1,8), c(6,8), c(6,1), c(8,1), c(8,3), c(4,3)
, c(4,2), c(6.5,2), c(6.5, 1.5), c(1, 1.5))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Bowtie, self-overlap")
errors[[pol_sf1$id]] <- pol_sf1
## 35. Polygon - Self-overlap Multiple
p1 <- rbind(c(4,8), c(4,2), c(2,2), c(2,3), c(8,3), c(8,7), c(2.5,7)
, c(2.5,2.5), c(3.5,2.5), c(3.5, 6), c(7, 6), c(7,4), c(1,4),
c(1,1), c(5,1), c(5,8), c(4,8))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Self-overlap Multiple")
errors[[pol_sf1$id]] <- pol_sf1
## 36. Polygon - Self-overlap; Pos and Neg winding
p1 <- rbind(c(1,1), c(8,1), c(8,7), c(3,7), c(3,5), c(7,5), c(7,3)
, c(5,3), c(5,8), c(1, 8), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Self-overlap; Pos. and Neg. winding")
errors[[pol_sf1$id]] <- pol_sf1
## 37. Polygon - Self-overlap; double Pos and single Neg winding
p1 <- rbind(c(2,1), c(2,7), c(6,7), c(6,2), c(3,2), c(3,6), c(5,6)
, c(5,3), c(8,3), c(8, 5), c(1,5), c(1,8),c(7,8), c(7,1), c(2,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Self-overlap; double Pos. and single Neg. winding")
errors[[pol_sf1$id]] <- pol_sf1
## 38. Polygon - Self-overlap - Pos and Neg winding
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(6,1), c(3,3), c(7,6)
, c(6,7.5), c(3.5, 5.5), c(5.5,5.5), c(3,7.5),c(2,6)
, c(6,3), c(3,1), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Self-overlap; Pos. and Neg. winding")
errors[[pol_sf1$id]] <- pol_sf1
## 39. Polygon - Self-overlap; exterior
p1 <- rbind(c(1,1), c(1,3), c(7,3), c(7,6), c(1,6), c(1,8), c(3,8)
, c(3,2), c(5,2), c(5, 8), c(8,8), c(8,1), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Self-overlap; exterior")
errors[[pol_sf1$id]] <- pol_sf1
## 40. Polygon - Self-overlap; Spiral with Pos winding
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,2), c(2,2), c(2,7), c(7,7)
, c(7,3), c(3,3), c(3, 6), c(6,6), c(6,4), c(4,4), c(4,5), c(5,5),
c(5,1), c(1,1))
pol <-st_polygon(list(p1))
pol_sf1 <- transform_in_sf(pol, "Polygon - Self-overlap; Spiral with Pos. winding")
errors[[pol_sf1$id]] <- pol_sf1
## 41. Polygon/Hole - Bowties
p1 <- rbind(c(1,1), c(8,8), c(1,8), c(8,1), c(1,1))
p2 <- rbind(c(3,2), c(6,7), c(3,7), c(6,2), c(3,2))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Bowties")
errors[[pol_sf1$id]] <- pol_sf1
## 42. Polygon/Hole - Bowties, overlap
p1 <- rbind(c(2,1), c(8,8), c(2,8), c(8,1), c(2,1))
p2 <- rbind(c(1,2), c(4.5,7), c(1,7), c(4.5,2), c(1,2))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Bowties, overlap")
errors[[pol_sf1$id]] <- pol_sf1
## 43. Polygon/Hole - Hole Self-overlap - interior
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,2), c(2,6), c(7,6), c(7,4.5), c(3,4.5)
, c(3, 3), c(4.5, 3), c(4.5,7), c(6,7), c(6,2), c(2,2))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Hole Self-overlap - interior")
errors[[pol_sf1$id]] <- pol_sf1
## 44. Polygon/Hole - Hole Self-overlap - Spiral with Neg winding
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,2), c(2,7), c(7,7), c(7,2.5), c(2.5,2.5)
, c(2.5, 6.5), c(6.5, 6.5), c(6.5,3), c(3,3), c(3,6), c(6,6),
c(6,3.5), c(3.5,3.5), c(3.5,5.5), c(5.5,5.5), c(5.5,2), c(2,2))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Hole Self-overlap - Spiral with Neg. winding")
errors[[pol_sf1$id]] <- pol_sf1
## 45. Polygon/Hole - Hole Self-overlap - exterior
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,2), c(2,7), c(3.5,7), c(3.5,3.5), c(5,3.5)
, c(5, 7), c(7, 7), c(7,6), c(3,6), c(3,5), c(7,5),
c(7,2), c(2,2))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Hole Self-overlap - exterior")
errors[[pol_sf1$id]] <- pol_sf1
## XX. Polygon/Hole - Outside
# no idea
## XX. Polygon/Hole - Overlap
# no idea
## 46. Polygon/Hole - Equal
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Equal")
errors[[pol_sf1$id]] <- pol_sf1
##. Polygon/Hole - Disconnected interior
# no idea
## 47. Polygon/Hole - Collapsed shell
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(1,8), c(1,1))
p2 <- rbind(c(2,4), c(2,6), c(4,6), c(4,4), c(2,4))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Collapsed shell")
errors[[pol_sf1$id]] <- pol_sf1
## 48. Polygon/Hole - Collapsed hole
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,4), c(2,6), c(4,6), c(2,6), c(2,4))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Hole - Collapsed hole")
errors[[pol_sf1$id]] <- pol_sf1
## 49. Polygon/Holes - Overlap
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,2), c(2,6), c(6,6), c(6,2), c(2,2))
p3 <- rbind(c(3,3), c(3,7), c(7,7), c(7,3), c(3,3))
pol <-st_polygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Overlap")
errors[[pol_sf1$id]] <- pol_sf1
## 50. Polygon/Holes - Cover Exactly
p2 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(1,1), c(1,4.5), c(4.5,4.5), c(4.5,1), c(1,1))
p3 <- rbind(c(1,4.5), c(1,8), c(4.5,8), c(4.5,4.5), c(1,4.5))
p4 <- rbind(c(4.5,4.5), c(4.5,8), c(8,8), c(8,4.5), c(4.5,4.5))
p5 <- rbind(c(4.5,1), c(4.5,4.5), c(8,4.5), c(8,1), c(4.5,1))
pol <-st_polygon(list(p1, p2, p3, p4, p5))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Cover Exactly")
errors[[pol_sf1$id]] <- pol_sf1
## 51. Polygon/Holes - Nested
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,2), c(2,7), c(7,7), c(7,2), c(2,2))
p3 <- rbind(c(3,3), c(3,6), c(6,6), c(6,3), c(3,3))
pol <-st_polygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Nested")
errors[[pol_sf1$id]] <- pol_sf1
## 52. Polygon/Holes - Disconnected interior, point touch
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,4.5), c(4.5,7), c(7,4.5), c(4.5,2), c(6,5.5),
c(3, 5.5), c(4.5,2), c(2,4.5))
pol <-st_polygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Disconnected interior, point touch")
errors[[pol_sf1$id]] <- pol_sf1
## 53. Polygon/Holes - Disconnected interior, point-line touch
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,5), c(6,7), c(6,5), c(2,5))
p3 <- rbind(c(3,5), c(3,2), c(6,2), c(3,5))
p4 <- rbind(c(7,6), c(7,3.5), c(4.5,3.5), c(7,6))
pol <-st_polygon(list(p1, p2, p3, p4))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Disconnected interior, point-line touch")
errors[[pol_sf1$id]] <- pol_sf1
## 54. Polygon/Holes - Disconnected interior, line touch
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,2), c(2,7), c(4.5,4.5), c(4.5,2), c(2,2))
p3 <- rbind(c(4.5,2), c(4.5,4.5), c(7,7), c(7,2), c(4.5,2))
p4 <- rbind(c(2,7), c(4.5,7.5), c(7,7), c(6,6), c(3,6), c(2,7))
pol <-st_polygon(list(p1, p2, p3, p4))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Disconnected interior, line touch")
errors[[pol_sf1$id]] <- pol_sf1
## 55. Polygon/Holes - Disconnected interior, overlapping bowtie holes
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2,2), c(6,2), c(2,7), c(6,7), c(2,2))
p3 <- rbind(c(4,3), c(7,3), c(4,6), c(7,6), c(4,3))
pol <-st_polygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Disconnected interior, overlapping bowtie holes")
errors[[pol_sf1$id]] <- pol_sf1
## 56. Polygon/Holes - Disconnected interior, overlapping zero-area holes
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(3,2), c(3,6), c(7,6), c(3,6), c(3,2))
p3 <- rbind(c(2,3), c(6,3), c(6,7), c(6,3), c(2,3))
pol <-st_polygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Disconnected interior, overlapping zero-area holes")
errors[[pol_sf1$id]] <- pol_sf1
## 57. Polygon/Holes - Disconnected interior, overlapping holes
p1 <- rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1))
p2 <- rbind(c(2.5,1.5), c(2.5,6.5), c(7,6.5), c(7,6), c(3,6), c(3,1.5), c(2.5, 1.5))
p3 <- rbind(c(2,2), c(6.5,2), c(6.5,7), c(6,7), c(6,2.5), c(2, 2.5), c(2,2))
pol <-st_polygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "Polygon/Holes - Disconnected interior, overlapping holes")
errors[[pol_sf1$id]] <- pol_sf1
## 58. MultiPolygon - Nested Polygons
p1 <- list(rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1)))
p2 <- list(rbind(c(3,3), c(3,6), c(6,6), c(6,3), c(3,3)))
pol <-st_multipolygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Nested Polygons")
errors[[pol_sf1$id]] <- pol_sf1
## 59. MultiPolygon - Multiple Nested Polygons
# not sure it can be well display
# check also the sfg object
p1 <- list(rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1)))
p2 <- list(rbind(c(3,3), c(3,6), c(6,6), c(6,3), c(3,3)))
p3 <- list(rbind(c(2,2), c(2,7), c(7,7), c(7,2), c(2,2)))
pol <-st_multipolygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Multiple Nested Polygons")
errors[[pol_sf1$id]] <- pol_sf1
## 60. MultiPolygon - Overlapping Polygons
p1 <- list(rbind(c(1,1), c(1,8), c(5,8), c(5,1), c(1,1)))
p2 <- list(rbind(c(3,2), c(3,7), c(7,7), c(7,2), c(3,2)))
pol <-st_multipolygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Overlapping Polygons")
errors[[pol_sf1$id]] <- pol_sf1
## 61. MultiPolygon - Multiple Overlapping Polygons
p1 <- list(rbind(c(1,1), c(1,6), c(6,6), c(6,1), c(1,1)))
p2 <- lapply(p1, function(x) x + 1 )
p3 <- lapply(p1, function(x) x + 2 )
pol <-st_multipolygon(list(p1, p2, p3))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Multiple Overlapping Polygons")
errors[[pol_sf1$id]] <- pol_sf1
## 62. MultiPolygon - Multiple Overlapping Polygons (5)
p1 <- list(rbind(c(1,2), c(1,7), c(3,7), c(3,2), c(1,2)))
p2 <- list(rbind(c(5,2), c(5,7), c(7,7), c(7,2), c(5,2)))
p3 <- list(rbind(c(2,6), c(2,8), c(6,8), c(6,6), c(2,6)))
p4 <- list(rbind(c(2,1), c(2,3), c(6,3), c(6,1), c(2,1)))
p5 <- list(rbind(c(2.5,2.5), c(2.5,6.5), c(5.5,6.5), c(5.5,2.5), c(2.5,2.5)))
pol <-st_multipolygon(list(p1, p2, p3, p4, p5))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Multiple Overlapping Polygons (5)")
errors[[pol_sf1$id]] <- pol_sf1
## 63. MultiPolygon - Polygon/Hole-overlap overlaps Polygon covering hole
# unsure if correct
p1 <- list(rbind(c(1,1), c(1,8), c(5,8), c(5,1), c(1,1)))
p2_holes <- rbind(c(4,3), c(4,6), c(6,6), c(6,3), c(4,3))
p2 <- list(rbind(c(3,2), c(3,7), c(7,7), c(7,2), c(3,2)), p2_holes)
pol <-st_multipolygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Polygon/Hole-overlap overlaps Polygon covering hole")
errors[[pol_sf1$id]] <- pol_sf1
## XX. MultiPolygon - Polygon/Hole-overlap overlaps Polygon inside hole
# no idea
## 64. MultiPolygon - Polygon/Hole-overlap hole overlaps Polygon
# unsure
p1 <- list(rbind(c(1,2), c(1,7), c(3,7), c(3,2), c(1,2)))
p2 <- list(rbind(c(5,2), c(5,7), c(7,7), c(7,2), c(5,2)))
t3 <- rbind(c(2,3), c(2,6), c(6,6), c(6,3), c(2,3))
p3 <- list(t3,t3)
pol <-st_multipolygon(list(p1, p2,p3))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Polygon/Hole-overlap hole overlaps Polygon")
errors[[pol_sf1$id]] <- pol_sf1
## 65. MultiPolygon - Polygon overlaps Polygon/Hole
# unsure
p1 <- list(rbind(c(1,1), c(1,8), c(5,8), c(5,1), c(1,1)))
p2_holes <- rbind(c(4,3), c(4,6), c(6,6), c(6,3), c(4,3))
p2 <- list(rbind(c(3,2), c(3,7), c(7,7), c(7,2), c(3,2)), p2_holes)
p3 <- list(p2_holes)
pol <-st_multipolygon(list(p1, p2,p3))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Polygon overlaps Polygon/Hole")
errors[[pol_sf1$id]] <- pol_sf1
## XX. MultiPolygon - Polygon/Hole-overlap overlaps Polygon
# out of idea
## 66. MultiPolygon - Polygon partially fills Polygon/Hole
p1_holes <- rbind(c(3,2), c(3,7), c(6,7), c(6,2), c(3,2))
p1 <- list(rbind(c(1,1), c(1,8), c(8,8), c(8,1), c(1,1)), p1_holes)
p2 <- list(rbind(c(3,3), c(3,6), c(6,6),c(6,3), c(3,3)))
pol <-st_multipolygon(list(p1, p2))
pol_sf1 <- transform_in_sf(pol, "MultiPolygon - Polygon partially fills Polygon/Hole")
errors[[pol_sf1$id]] <- pol_sf1
## XX. MultiPolygon - Grid of adjacent Polygons
## no idea
## XX. MultiPolygon - Ring of adjacent Polygons
#no idea
## 2.2 Table to filter data ====================================================
filter_data <- data.frame(
id = 1:length(errors),
features = sapply(names(errors), function(x) extract_first_word(x)),
errors = names(errors)
)
row.names(filter_data) <- NULL
return(errors)
}
errors <- create_my_errors()
#saveRDS(errors,"data/errors")
#saveRDS(filter_data, "data/filter_data")