-
Notifications
You must be signed in to change notification settings - Fork 80
/
Atlas.java
1004 lines (898 loc) · 33.1 KB
/
Atlas.java
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
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package org.openstreetmap.atlas.geography.atlas;
import java.io.Serializable;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
import java.util.function.BiConsumer;
import java.util.function.LongFunction;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import org.openstreetmap.atlas.geography.GeometricSurface;
import org.openstreetmap.atlas.geography.Located;
import org.openstreetmap.atlas.geography.Location;
import org.openstreetmap.atlas.geography.Rectangle;
import org.openstreetmap.atlas.geography.atlas.builder.AtlasSize;
import org.openstreetmap.atlas.geography.atlas.items.Area;
import org.openstreetmap.atlas.geography.atlas.items.AtlasEntity;
import org.openstreetmap.atlas.geography.atlas.items.AtlasItem;
import org.openstreetmap.atlas.geography.atlas.items.Edge;
import org.openstreetmap.atlas.geography.atlas.items.ItemType;
import org.openstreetmap.atlas.geography.atlas.items.Line;
import org.openstreetmap.atlas.geography.atlas.items.LineItem;
import org.openstreetmap.atlas.geography.atlas.items.LocationItem;
import org.openstreetmap.atlas.geography.atlas.items.Node;
import org.openstreetmap.atlas.geography.atlas.items.Point;
import org.openstreetmap.atlas.geography.atlas.items.Relation;
import org.openstreetmap.atlas.geography.atlas.items.SnappedEdge;
import org.openstreetmap.atlas.geography.atlas.items.SnappedLineItem;
import org.openstreetmap.atlas.geography.atlas.packed.PackedAtlas;
import org.openstreetmap.atlas.geography.atlas.packed.PackedAtlasCloner;
import org.openstreetmap.atlas.geography.atlas.sub.AtlasCutType;
import org.openstreetmap.atlas.geography.geojson.GeoJsonFeatureCollection;
import org.openstreetmap.atlas.geography.geojson.GeoJsonObject;
import org.openstreetmap.atlas.streaming.resource.WritableResource;
import org.openstreetmap.atlas.utilities.scalars.Distance;
import com.google.gson.JsonObject;
/**
* Atlas is a representation of an OpenStreetMap region in memory. It is a navigable collection of
* unidirectional {@link Edge}s and {@link Node}s. It is designed to be close to the OpenStreetMap
* model. It also contains a collection of non-navigable geolocated items that can be {@link Point}
* s, {@link Line}s or {@link Area}s. All can be members of {@link Relation}s.
*
* @author matthieun
* @author tony
*/
public interface Atlas
extends Located, Iterable<AtlasEntity>, Serializable, GeoJsonFeatureCollection<AtlasEntity>
{
static <E extends AtlasEntity> Iterable<E> entitiesMatchingId(final Long[] identifiers,
final LongFunction<E> function)
{
return Arrays.stream(identifiers).map(function::apply).filter(Objects::nonNull)
.collect(Collectors.toSet());
}
/**
* @param identifier
* The {@link Area}'s identifier
* @return The {@link Area} that corresponds to the provided identifier
*/
Area area(long identifier);
/**
* @return All the {@link Area}s in this {@link Atlas}
*/
Iterable<Area> areas();
/**
* A wrapper over {@link #area(long)} for multiple ids.
*
* @param identifiers
* - The area identifiers to fetch.
* @return The {@link Area}s that corresponds to the provided identifier.
*/
default Iterable<Area> areas(final Long... identifiers)
{
return entitiesMatchingId(identifiers, this::area);
}
/**
* Return all the {@link Area}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link Area}s matching the {@link Predicate}.
*/
Iterable<Area> areas(Predicate<Area> matcher);
/**
* Return all the {@link Area}s covering some {@link Location}.
*
* @param location
* The {@link Location} to consider
* @return All the {@link Area}s covering the {@link Location}.
*/
Iterable<Area> areasCovering(Location location);
/**
* Return all the {@link Area}s matching a {@link Predicate} and covering some {@link Location}.
*
* @param matcher
* The matcher to consider
* @param location
* The {@link Location} to consider
* @return All the {@link Area}s matching the {@link Predicate} and covering the
* {@link Location}.
*/
Iterable<Area> areasCovering(Location location, Predicate<Area> matcher);
/**
* Return all the {@link Area}s within and/or intersecting some surface.
*
* @param surface
* The surface to consider
* @return All the {@link Area}s within and/or intersecting the surface.
*/
Iterable<Area> areasIntersecting(GeometricSurface surface);
/**
* Return all the {@link Area}s matching a {@link Predicate}, and within and/or intersecting
* some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link Area}s matching the {@link Predicate}, and within and/or intersecting
* the surface.
*/
Iterable<Area> areasIntersecting(GeometricSurface surface, Predicate<Area> matcher);
/**
* Return all the {@link Area}s fully within some surface.
*
* @param surface
* The surface to consider
* @return All the {@link Area}s fully within the surface.
*/
Iterable<Area> areasWithin(GeometricSurface surface);
/**
* @param matcher
* The matcher to consider
* @return A {@link GeoJsonObject} that contains part the features in this {@link Atlas} which
* matches the given matcher
*/
JsonObject asGeoJson(Predicate<AtlasEntity> matcher);
/**
* Clone this {@link Atlas} to a {@link PackedAtlas}. Do not uses "clone" so as not to be
* confused with the clone function in {@link Cloneable}, which this interface does not extend.
*
* @return The {@link PackedAtlas} copy of this {@link Atlas}.
*/
default PackedAtlas cloneToPackedAtlas()
{
return new PackedAtlasCloner().cloneFrom(this);
}
/**
* @param identifier
* The {@link Edge}'s identifier
* @return The {@link Edge} that corresponds to the provided identifier
*/
Edge edge(long identifier);
/**
* @return All the {@link Edge}s in this {@link Atlas}
*/
Iterable<Edge> edges();
/**
* A wrapper over {@link #edge(long)} for multiple ids.
*
* @param identifiers
* - The edge identifiers to fetch.
* @return The {@link Edge}s that corresponds to the provided identifier.
*/
default Iterable<Edge> edges(final Long... identifiers)
{
return entitiesMatchingId(identifiers, this::edge);
}
/**
* Return all the {@link Edge}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link Edge}s matching the {@link Predicate}.
*/
Iterable<Edge> edges(Predicate<Edge> matcher);
/**
* Return all the {@link Edge}s containing some {@link Location}.
*
* @param location
* The {@link Location} to consider
* @return All the {@link Edge}s containing the {@link Location}.
*/
Iterable<Edge> edgesContaining(Location location);
/**
* Return all the {@link Edge}s matching a {@link Predicate} and containing some
* {@link Location}.
*
* @param matcher
* The matcher to consider
* @param location
* The {@link Location} to consider
* @return All the {@link Edge}s matching the {@link Predicate} and containing the
* {@link Location}.
*/
Iterable<Edge> edgesContaining(Location location, Predicate<Edge> matcher);
/**
* Return all the {@link Edge}s within and/or intersecting some surface.
*
* @param surface
* The surface to consider
* @return All the {@link Edge}s within and/or intersecting the surface.
*/
Iterable<Edge> edgesIntersecting(GeometricSurface surface);
/**
* Return all the {@link Edge}s matching a {@link Predicate}, and within and/or intersecting
* some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link Edge}s matching the {@link Predicate}, and within and/or intersecting
* the surface.
*/
Iterable<Edge> edgesIntersecting(GeometricSurface surface, Predicate<Edge> matcher);
/**
* Return all the {@link Edge}s fully within some surface.
*
* @param surface
* The surface to consider
* @return All the {@link Edge}s fully within the surface.
*/
Iterable<Edge> edgesWithin(GeometricSurface surface);
/**
* Return all the {@link AtlasEntity}s
*
* @return All the {@link AtlasEntity}s
*/
Iterable<AtlasEntity> entities();
/**
* Return all the {@link AtlasEntity}s of a specific type
*
* @param type
* The type to restrain to
* @param memberClass
* The class of the member
* @param <M>
* The AtlasEntity type
* @return All the {@link AtlasEntity}s of a specific type
*/
<M extends AtlasEntity> Iterable<M> entities(ItemType type, Class<M> memberClass);
/**
* Return all the {@link AtlasEntity}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link AtlasEntity}s matching the {@link Predicate}.
*/
Iterable<AtlasEntity> entities(Predicate<AtlasEntity> matcher);
/**
* Return all the {@link AtlasEntity}s within and/or intersecting some surface.
*
* @param surface
* The {@link GeometricSurface} to consider
* @return All the {@link AtlasEntity}s within and/or intersecting the {@link GeometricSurface}.
*/
Iterable<AtlasEntity> entitiesIntersecting(GeometricSurface surface);
/**
* Return all the {@link AtlasEntity}s matching a {@link Predicate}, and within and/or
* intersecting some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link AtlasEntity}s matching the {@link Predicate}, and within and/or
* intersecting the surface.
*/
Iterable<AtlasEntity> entitiesIntersecting(GeometricSurface surface,
Predicate<AtlasEntity> matcher);
/**
* Return all the {@link AtlasEntity}s fully within some surface.
*
* @param surface
* The {@link GeometricSurface} to consider
* @return All the {@link AtlasEntity}s fully within the {@link GeometricSurface}.
*/
Iterable<AtlasEntity> entitiesWithin(GeometricSurface surface);
/**
* Return all the {@link AtlasEntity}s matching a {@link Predicate}, and fully within some
* surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The {@link GeometricSurface} to consider
* @return All the {@link AtlasEntity}s fully within the {@link GeometricSurface}.
*/
Iterable<AtlasEntity> entitiesWithin(GeometricSurface surface, Predicate<AtlasEntity> matcher);
/**
* Get an entity from identifier and type
*
* @param identifier
* the identifier
* @param type
* The type
* @return The corresponding AtlasEntity, null if any.
*/
AtlasEntity entity(long identifier, ItemType type);
/**
* @return This Atlas' identifier
*/
UUID getIdentifier();
/**
* @return This Atlas' optional name. If not specified, should return a String version of the
* identifier.
*/
String getName();
/**
* Return all the {@link AtlasItem}s
*
* @return All the {@link AtlasItem}s
*/
Iterable<AtlasItem> items();
/**
* Return all the {@link AtlasItem}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link AtlasItem}s matching the {@link Predicate}.
*/
Iterable<AtlasItem> items(Predicate<AtlasItem> matcher);
/**
* Return all the {@link AtlasItem}s containing some {@link Location}.
*
* @param location
* The {@link Location} to consider
* @return All the {@link AtlasItem}s containing the {@link Location}.
*/
Iterable<AtlasItem> itemsContaining(Location location);
/**
* Return all the {@link AtlasItem}s matching a {@link Predicate} and containing some
* {@link Location}.
*
* @param matcher
* The matcher to consider
* @param location
* The {@link Location} to consider
* @return All the {@link AtlasItem}s matching the {@link Predicate} and containing the
* {@link Location}.
*/
Iterable<AtlasItem> itemsContaining(Location location, Predicate<AtlasItem> matcher);
/**
* Return all the {@link AtlasItem}s within and/or intersecting some surface.
*
* @param surface
* The {@link GeometricSurface} to consider
* @return All the {@link AtlasItem}s within and/or intersecting the {@link GeometricSurface}.
*/
Iterable<AtlasItem> itemsIntersecting(GeometricSurface surface);
/**
* Return all the {@link AtlasItem}s matching a {@link Predicate}, and within and/or
* intersecting some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link AtlasItem}s matching the {@link Predicate}, and within and/or
* intersecting the surface.
*/
Iterable<AtlasItem> itemsIntersecting(GeometricSurface surface, Predicate<AtlasItem> matcher);
/**
* Return all the {@link AtlasItem}s fully within some surface.
*
* @param surface
* The surface to consider
* @return All the {@link AtlasItem}s fully within the surface.
*/
Iterable<AtlasItem> itemsWithin(GeometricSurface surface);
/**
* @param identifier
* The {@link Line}'s identifier
* @return The {@link Line} that corresponds to the provided identifier
*/
Line line(long identifier);
/**
* Return all the {@link LineItem}s
*
* @return All the {@link LineItem}s
*/
Iterable<LineItem> lineItems();
/**
* Return all the {@link LineItem}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link LineItem}s matching the {@link Predicate}.
*/
Iterable<LineItem> lineItems(Predicate<LineItem> matcher);
/**
* Return all the {@link LineItem}s containing some {@link Location}.
*
* @param location
* The {@link Location} to consider
* @return All the {@link LineItem}s containing the {@link Location}.
*/
Iterable<LineItem> lineItemsContaining(Location location);
/**
* Return all the {@link LineItem}s matching a {@link Predicate} and containing some
* {@link Location}.
*
* @param matcher
* The matcher to consider
* @param location
* The {@link Location} to consider
* @return All the {@link LineItem}s matching the {@link Predicate} and containing the
* {@link Location}.
*/
Iterable<LineItem> lineItemsContaining(Location location, Predicate<LineItem> matcher);
/**
* Return all the {@link LineItem}s within and/or intersecting some surface.
*
* @param surface
* The {@link GeometricSurface} to consider
* @return All the {@link LineItem}s within and/or intersecting the {@link GeometricSurface}.
*/
Iterable<LineItem> lineItemsIntersecting(GeometricSurface surface);
/**
* Return all the {@link LineItem}s matching a {@link Predicate}, and within and/or intersecting
* some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link LineItem}s matching the {@link Predicate}, and within and/or
* intersecting the surface.
*/
Iterable<LineItem> lineItemsIntersecting(GeometricSurface surface, Predicate<LineItem> matcher);
/**
* Return all the {@link LineItem}s fully within some surface.
*
* @param surface
* The {@link GeometricSurface} to consider
* @return All the {@link LineItem}s within and/or intersecting the {@link GeometricSurface}.
*/
Iterable<LineItem> lineItemsWithin(GeometricSurface surface);
/**
* @return All the {@link Line}s in this {@link Atlas}
*/
Iterable<Line> lines();
/**
* A wrapper over {@link #line(long)} for multiple ids.
*
* @param identifiers
* - The line identifiers to fetch.
* @return The {@link Line}s that corresponds to the provided identifier.
*/
default Iterable<Line> lines(final Long... identifiers)
{
return entitiesMatchingId(identifiers, this::line);
}
/**
* Return all the {@link Line}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link Line}s matching the {@link Predicate}.
*/
Iterable<Line> lines(Predicate<Line> matcher);
/**
* Return all the {@link Line}s containing some {@link Location}.
*
* @param location
* The {@link Location} to consider
* @return All the {@link Line}s containing the location.
*/
Iterable<Line> linesContaining(Location location);
/**
* Return all the {@link Line}s matching a {@link Predicate} and containing some
* {@link Location}.
*
* @param matcher
* The matcher to consider
* @param location
* The {@link Location} to consider
* @return All the {@link Line}s matching the {@link Predicate} and containing the
* {@link Location}.
*/
Iterable<Line> linesContaining(Location location, Predicate<Line> matcher);
/**
* Return all the {@link Line}s within and/or intersecting some surface.
*
* @param surface
* The surface to consider
* @return All the {@link Line}s within and/or intersecting the surface.
*/
Iterable<Line> linesIntersecting(GeometricSurface surface);
/**
* Return all the {@link Line}s matching a {@link Predicate}, and within and/or intersecting
* some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link Line}s matching the {@link Predicate}, and within and/or intersecting
* the surface.
*/
Iterable<Line> linesIntersecting(GeometricSurface surface, Predicate<Line> matcher);
/**
* Return all the {@link Line}s fully within some surface.
*
* @param surface
* The surface to consider
* @return All the {@link Line}s fully within the surface.
*/
Iterable<Line> linesWithin(GeometricSurface surface);
/**
* Return all the {@link LocationItem}s
*
* @return All the {@link LocationItem}s
*/
Iterable<LocationItem> locationItems();
/**
* Return all the {@link LocationItem}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link LocationItem}s matching the {@link Predicate}.
*/
Iterable<LocationItem> locationItems(Predicate<LocationItem> matcher);
/**
* Return all the {@link LocationItem}s within and/or intersecting some surface.
*
* @param surface
* The {@link GeometricSurface} to consider
* @return All the {@link LocationItem}s within and/or intersecting the
* {@link GeometricSurface}.
*/
Iterable<LocationItem> locationItemsWithin(GeometricSurface surface);
/**
* Return all the {@link LocationItem}s matching a {@link Predicate}, and within and/or
* intersecting some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link LocationItem}s matching the {@link Predicate}, and within and/or
* intersecting the surface.
*/
Iterable<LocationItem> locationItemsWithin(GeometricSurface surface,
Predicate<LocationItem> matcher);
/**
* @return The meta data for this {@link Atlas}.
*/
AtlasMetaData metaData();
/**
* @param identifier
* The {@link Node}'s identifier
* @return The {@link Node} that corresponds to the provided identifier
*/
Node node(long identifier);
/**
* @return All the {@link Node}s in this Atlas
*/
Iterable<Node> nodes();
/**
* A wrapper over {@link #node(long)} for multiple ids.
*
* @param identifiers
* - The node identifiers to fetch.
* @return The {@link Node}s that corresponds to the provided identifier.
*/
default Iterable<Node> nodes(final Long... identifiers)
{
return entitiesMatchingId(identifiers, this::node);
}
/**
* Return all the {@link Node}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link Node}s matching the {@link Predicate}.
*/
Iterable<Node> nodes(Predicate<Node> matcher);
/**
* Return all the {@link Node}s at some {@link Location}.
*
* @param location
* The {@link Location} to consider
* @return All the {@link Node}s at the {@link Location}.
*/
Iterable<Node> nodesAt(Location location);
/**
* Return all the {@link Node}s within and/or intersecting some surface. Note: results may vary,
* for an identical boundary, depending on the type, {@link Rectangle} or
* {@link GeometricSurface} of the input. This is due to an underlying dependency on the awt
* definition of insideness.
*
* @param surface
* The surface to consider
* @return All the {@link Node}s within and/or intersecting the surface.
*/
Iterable<Node> nodesWithin(GeometricSurface surface);
/**
* Return all the {@link Node}s matching a {@link Predicate}, and within and/or intersecting
* some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link Node}s matching the {@link Predicate}, and within and/or intersecting
* the surface.
*/
Iterable<Node> nodesWithin(GeometricSurface surface, Predicate<Node> matcher);
/**
* @return The number of {@link Area}s
*/
long numberOfAreas();
/**
* @return The number of {@link Edge}s
*/
long numberOfEdges();
/**
* @return The number of {@link Line}s
*/
long numberOfLines();
/**
* @return The number of {@link Node}s
*/
long numberOfNodes();
/**
* @return The number of {@link Point}s
*/
long numberOfPoints();
/**
* @return The number of {@link Relation}s
*/
long numberOfRelations();
/**
* @param identifier
* The {@link Point}'s identifier
* @return The {@link Point} that corresponds to the provided identifier
*/
Point point(long identifier);
/**
* @return All the {@link Point}s in this Atlas
*/
Iterable<Point> points();
/**
* A wrapper over {@link #point(long)} for multiple ids.
*
* @param identifiers
* - The point identifiers to fetch.
* @return The {@link Point}s that corresponds to the provided identifier.
*/
default Iterable<Point> points(final Long... identifiers)
{
return entitiesMatchingId(identifiers, this::point);
}
/**
* Return all the {@link Point}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link Point}s matching the {@link Predicate}.
*/
Iterable<Point> points(Predicate<Point> matcher);
/**
* Return all the {@link Point}s at some {@link Location}.
*
* @param location
* The {@link Location} to consider
* @return All the {@link Point}s at the {@link Location}.
*/
Iterable<Point> pointsAt(Location location);
/**
* Return all the {@link Point}s within some surface. Note: results may vary, for an identical
* boundary, depending on the type, {@link Rectangle} or {@link GeometricSurface} of the input.
* This is due to an underlying dependency on the awt definition of insideness.
*
* @param surface
* The surface to consider
* @return All the {@link Point}s within the surface.
*/
Iterable<Point> pointsWithin(GeometricSurface surface);
/**
* Return all the {@link Point}s matching a {@link Predicate}. Note: results may vary, for an
* identical boundary, depending on the type, {@link Rectangle} or {@link GeometricSurface} of
* the input. This is due to an underlying dependency on the awt definition of insideness.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link Point}s matching the {@link Predicate}, and within and/or intersecting
* the surface.
*/
Iterable<Point> pointsWithin(GeometricSurface surface, Predicate<Point> matcher);
/**
* @param identifier
* The {@link Relation}'s identifier
* @return The {@link Relation} that corresponds to the provided identifier
*/
Relation relation(long identifier);
/**
* @return All the {@link Relation}s in this Atlas
*/
Iterable<Relation> relations();
/**
* A wrapper over {@link #relation(long)} for multiple ids.
*
* @param identifiers
* - The relation identifiers to fetch.
* @return The {@link Relation}s that corresponds to the provided identifier.
*/
default Iterable<Relation> relations(final Long... identifiers)
{
return entitiesMatchingId(identifiers, this::relation);
}
/**
* Return all the {@link Relation}s matching a {@link Predicate}.
*
* @param matcher
* The matcher to consider
* @return All the {@link Relation}s matching the {@link Predicate}.
*/
Iterable<Relation> relations(Predicate<Relation> matcher);
/**
* @return All the {@link Relation}s in this Atlas, with the lower order relations first. This
* means at any point, if a relation is returned by this {@link Iterable}, then all the
* relations that belong to this relation have already been returned.
*/
Iterable<Relation> relationsLowerOrderFirst();
/**
* Return all the {@link Relation}s which have at least one feature intersecting some surface.
*
* @param surface
* The surface to consider
* @return All the {@link Relation}s which have at least one feature intersecting the surface.
*/
Iterable<Relation> relationsWithEntitiesIntersecting(GeometricSurface surface);
/**
* Return all the {@link Relation}s which have at least one feature intersecting some surface.
*
* @param matcher
* The matcher to consider
* @param surface
* The surface to consider
* @return All the {@link Relation}s matching the {@link Predicate}, and which have at least one
* feature intersecting the surface.
*/
Iterable<Relation> relationsWithEntitiesIntersecting(GeometricSurface surface,
Predicate<Relation> matcher);
/**
* Return all the {@link Relation}s which have all features within some surface.
*
* @param surface
* The surface to consider
* @return All the {@link Relation}s which have all features within the surface.
*/
Iterable<Relation> relationsWithEntitiesWithin(GeometricSurface surface);
/**
* Serialize this {@link Atlas} to a {@link WritableResource}
*
* @param writableResource
* The resource to write to
*/
void save(WritableResource writableResource);
/**
* Save as GeoJSON
*
* @param resource
* The resource to write to
*/
void saveAsGeoJson(WritableResource resource);
/**
* Save as GeoJSON with matcher
*
* @param resource
* The resource to write to
* @param matcher
* The matcher to consider
*/
void saveAsGeoJson(WritableResource resource, Predicate<AtlasEntity> matcher);
/**
* Save as line-delimited GeoJSON. This is one feature per line, with no wrapping
* FeatureCollection.
*
* @param resource
* The resource to write to
* @param jsonMutator
* The callback function that will let you change what is in the Feature's JSON.
*/
void saveAsLineDelimitedGeoJsonFeatures(WritableResource resource,
BiConsumer<AtlasEntity, JsonObject> jsonMutator);
/**
* Save as line-delimited GeoJSON with a matcher. This is one feature per line, with no wrapping
* FeatureCollection.
*
* @param resource
* The resource to write to
* @param matcher
* The matcher to consider
* @param jsonMutator
* The callback function that will let you change what is in the Feature's JSON.
*/
void saveAsLineDelimitedGeoJsonFeatures(WritableResource resource,
Predicate<AtlasEntity> matcher, BiConsumer<AtlasEntity, JsonObject> jsonMutator);
/**
* Save as list of items
*
* @param resource
* The resource to write to
*/
void saveAsList(WritableResource resource);
/**
* Save as a naive proto file
*
* @param resource
* The resource to write to
*/
void saveAsProto(WritableResource resource);
/**
* Save as a text file
*
* @param resource
* The resource to write to
*/
void saveAsText(WritableResource resource);
/**
* @return The size for this {@link Atlas}.
*/
default AtlasSize size()
{
return new AtlasSize(numberOfEdges(), numberOfNodes(), numberOfAreas(), numberOfLines(),
numberOfPoints(), numberOfRelations());
}
/**
* @param point
* A {@link Location} to snap
* @param threshold
* A {@link Distance} threshold to look for edges around the {@link Location}
* @return The best snapped result, or null if there is no valid snap
*/
SnappedEdge snapped(Location point, Distance threshold);
/**
* @param point
* A {@link Location} to snap
* @param threshold
* A {@link Distance} threshold to look for edges around the {@link Location}
* @return A sorted {@link List} of all the candidate snaps. The list is empty if there are no
* candidates.
*/
List<SnappedEdge> snaps(Location point, Distance threshold);
/**
* @param point
* A {@link Location} to snap
* @param threshold
* A {@link Distance} threshold to look for edges around the {@link Location}
* @return A sorted {@link List} of all the candidate snaps. The list is empty if there are no
* candidates.
*/
List<SnappedLineItem> snapsLineItem(Location point, Distance threshold);
/**
* Return a sub-atlas from this Atlas.
*
* @param boundary
* The boundary within which the sub atlas will be built
* @param cutType
* The type of cut to perform
* @return An optional sub-atlas. The optional will be empty in case there is nothing in the
* {@link GeometricSurface} after the cut was applied. Returning an empty atlas is not
* allowed.
*/
Optional<Atlas> subAtlas(GeometricSurface boundary, AtlasCutType cutType);
/**
* Return a sub-atlas from this Atlas.
*
* @param matcher
* The matcher to consider
* @param cutType
* The type of cut to perform
* @return An optional sub-atlas. The optional will be empty in case the matcher and cut-type
* return an empty atlas, which is not allowed.
*/
Optional<Atlas> subAtlas(Predicate<AtlasEntity> matcher, AtlasCutType cutType);
/**
* Get a summary of this {@link Atlas}. This string should be relatively compact, for e.g. just
* the entity counts.
*
* @return A summary of this {@link Atlas}.
*/
String summary();
/**
* Get a complete string representation of this {@link Atlas}. This string may include details
* on all contained entities.
*