New upstream version 0.0.0+svn4323
Bas Couwenberg
4 years ago
267 | 267 | <p> |
268 | 268 | If the street is not given with addr:housenumber, mkgmap uses heuristics |
269 | 269 | to find the best match. |
270 | <p> | |
271 | Tells mkgmap to write NET data. If you specify this option, you do not need to | |
272 | specify --net and option -no-net is ignored. | |
270 | 273 | |
271 | 274 | === Overview map options === |
272 | 275 | ;--overview-mapname=name |
522 | 525 | <p> |
523 | 526 | ;--net |
524 | 527 | : Tells mkgmap to write NET data, which is needed for address search |
525 | and routing. Use this option if you want full address search, but do | |
526 | not need a map that supports routing. | |
528 | and routing. Use this option if you want address search, but do | |
529 | not need a map that supports routing or house number search. | |
527 | 530 | <p> |
528 | 531 | ;--route |
529 | 532 | : Tells mkgmap to write NET and NOD data, which are needed in maps |
530 | 533 | that support routing. If you specify this option, you do not need |
531 | to specify --net. | |
534 | to specify --net and --no-net is ignored. | |
532 | 535 | <p> |
533 | 536 | ;--add-boundary-nodes-at-admin-boundaries=NUM |
534 | 537 | : This option controls how mkgmap calculates special routing nodes which |
260 | 260 | the addr:street tag value of the house number node. |
261 | 261 | If the street is not given with addr:housenumber, mkgmap uses heuristics |
262 | 262 | to find the best match. |
263 | Tells mkgmap to write NET data. If you specify this option, you do not need | |
264 | to specify --net and option -no-net is ignored. | |
263 | 265 | |
264 | 266 | Overview map options: |
265 | 267 | --overview-mapname=name |
514 | 516 | will ask you to try a value for this option. |
515 | 517 | |
516 | 518 | --net |
517 | Tells mkgmap to write NET data, which is needed for address search | |
518 | and routing. Use this option if you want full address search, but do | |
519 | not need a map that supports routing. | |
519 | Tells mkgmap to write NET data, which is needed for address search | |
520 | and routing. Use this option if you want address search, but do | |
521 | not need a map that supports routing or house number search. | |
520 | 522 | |
521 | 523 | --route |
522 | 524 | Tells mkgmap to write NET and NOD data, which are needed in maps |
523 | 525 | that support routing. If you specify this option, you do not need |
524 | to specify --net. | |
526 | to specify --net and option -no-net is ignored. | |
525 | 527 | |
526 | 528 | --drive-on=left|right|detect|detect,left|detect,right |
527 | 529 | Explicitly specify which side of the road vehicles are |
0 | svn.version: 4294 | |
1 | build.timestamp: 2019-09-28T07:25:58+0100 | |
0 | svn.version: 4323 | |
1 | build.timestamp: 2019-10-26T09:00:42+0100 |
16 | 16 | package uk.me.parabola.imgfmt.app.lbl; |
17 | 17 | |
18 | 18 | import java.util.ArrayList; |
19 | import java.util.Collections; | |
20 | 19 | import java.util.List; |
21 | 20 | |
22 | 21 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
64 | 63 | if(extraData) { |
65 | 64 | writer.put1u(0); |
66 | 65 | writer.put2u(region == null? 0 : region.getIndex()); |
67 | Collections.sort(exits); | |
66 | exits.sort(null); | |
68 | 67 | for(ExitPoint ep : exits) { |
69 | 68 | writer.put1u(ep.index); |
70 | 69 | writer.put2u(ep.div.getNumber()); |
34 | 34 | this.name = name; |
35 | 35 | this.poiIndex = poiIndex; |
36 | 36 | this.group = group; |
37 | this.subType = subType; | |
37 | this.subType = subType & 0xff; | |
38 | 38 | } |
39 | 39 | |
40 | 40 | void write(ImgFileWriter writer) { |
16 | 16 | package uk.me.parabola.imgfmt.app.lbl; |
17 | 17 | |
18 | 18 | import java.util.ArrayList; |
19 | import java.util.Collections; | |
20 | 19 | import java.util.LinkedHashMap; |
21 | 20 | import java.util.List; |
22 | 21 | import java.util.Map; |
97 | 96 | SortKey<POIIndex> sortKey = sort.createSortKey(index, index.getName()); |
98 | 97 | sorted.add(sortKey); |
99 | 98 | } |
100 | Collections.sort(sorted); | |
99 | sorted.sort(null); | |
101 | 100 | |
102 | 101 | for (SortKey<POIIndex> key : sorted) { |
103 | 102 | key.getObject().write(writer); |
341 | 340 | SortKey<Country> key = sort.createSortKey(c, c.getLabel()); |
342 | 341 | keys.add(key); |
343 | 342 | } |
344 | Collections.sort(keys); | |
343 | keys.sort(null); | |
345 | 344 | |
346 | 345 | countryList.clear(); |
347 | 346 | int index = 1; |
361 | 360 | SortKey<Region> key = sort.createSortKey(r, r.getLabel(), r.getCountry().getIndex()); |
362 | 361 | keys.add(key); |
363 | 362 | } |
364 | Collections.sort(keys); | |
363 | keys.sort(null); | |
365 | 364 | |
366 | 365 | regionList.clear(); |
367 | 366 | int index = 1; |
382 | 381 | sortKey = new CombinedSortKey<>(sortKey, c.getRegionNumber(), c.getCountryNumber()); |
383 | 382 | keys.add(sortKey); |
384 | 383 | } |
385 | Collections.sort(keys); | |
384 | keys.sort(null); | |
386 | 385 | |
387 | 386 | cityList.clear(); |
388 | 387 | int index = 1; |
399 | 398 | SortKey<Zip> sortKey = sort.createSortKey(c, c.getLabel()); |
400 | 399 | keys.add(sortKey); |
401 | 400 | } |
402 | Collections.sort(keys); | |
401 | keys.sort(null); | |
403 | 402 | |
404 | 403 | zipList.clear(); |
405 | 404 | int index = 1; |
120 | 120 | // we don't want routing info in the overview map (for now) |
121 | 121 | if (!OverviewBuilder.isOverviewImg(mapName)){ |
122 | 122 | try { |
123 | if (props.containsKey("route") || props.containsKey("net") || props.containsKey("housenumbers")) { | |
124 | addNet(); | |
125 | } | |
123 | 126 | if (props.containsKey("route")) { |
124 | addNet(); | |
125 | 127 | addNod(); |
126 | } else if (props.containsKey("net")) { | |
127 | addNet(); | |
128 | 128 | } |
129 | 129 | } catch (FileExistsException e) { |
130 | 130 | log.warn("Could not add NET and/or NOD sections"); |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.HashMap; |
17 | 16 | import java.util.List; |
18 | 17 | import java.util.Map; |
65 | 64 | keys.add(makeKey(list.get(i), sort, cache)); |
66 | 65 | } |
67 | 66 | cache = null; |
68 | Collections.sort(keys); | |
67 | keys.sort(null); | |
69 | 68 | |
70 | 69 | for (int i = 0; i < keys.size(); i++){ |
71 | 70 | SortKey<T> sk = keys.get(i); |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.LinkedHashMap; |
17 | 16 | import java.util.List; |
18 | 17 | import java.util.Map; |
69 | 68 | if (poiGroup == null) |
70 | 69 | continue; |
71 | 70 | |
72 | Collections.sort(poiGroup); | |
71 | poiGroup.sort(null); | |
73 | 72 | |
74 | 73 | String lastName = null; |
75 | 74 | int lastSub = -1; |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.List; |
17 | 16 | |
18 | 17 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
34 | 33 | } |
35 | 34 | |
36 | 35 | public void writeSectData(ImgFileWriter writer) { |
37 | Collections.sort(regions); | |
36 | regions.sort(null); | |
38 | 37 | |
39 | 38 | for (Mdr13Record region : regions) { |
40 | 39 | putMapIndex(writer, region.getMapIndex()); |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.List; |
17 | 16 | |
18 | 17 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
30 | 29 | } |
31 | 30 | |
32 | 31 | public void writeSectData(ImgFileWriter writer) { |
33 | Collections.sort(countries); | |
32 | countries.sort(null); | |
34 | 33 | |
35 | 34 | for (Mdr14Record country : countries) { |
36 | 35 | putMapIndex(writer, country.getMapIndex()); |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | import java.util.Comparator; | |
17 | 15 | import java.util.List; |
18 | 16 | |
19 | 17 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
25 | 23 | */ |
26 | 24 | public class Mdr19 extends MdrSection implements HasHeaderFlags { |
27 | 25 | private List<Mdr11Record> pois; |
28 | private final List<Mdr18Record> poiTypes = new ArrayList<Mdr18Record>(); | |
26 | private final List<Mdr18Record> poiTypes = new ArrayList<>(); | |
29 | 27 | |
30 | 28 | public Mdr19(MdrConfig config) { |
31 | 29 | setConfig(config); |
34 | 32 | /** |
35 | 33 | * Sort the pois by type. |
36 | 34 | */ |
35 | @Override | |
37 | 36 | public void preWriteImpl() { |
38 | Collections.sort(pois, new Comparator<Mdr11Record>() { | |
39 | public int compare(Mdr11Record o1, Mdr11Record o2) { | |
40 | // For mainly historical reasons, we keep the element type in a number of different | |
41 | // formats. Need to normalise it before sorting. | |
42 | int t1 = MdrUtils.fullTypeToNaturalType(o1.getType()); | |
43 | int t2 = MdrUtils.fullTypeToNaturalType(o2.getType()); | |
44 | ||
45 | if (t1 == t2) return 0; | |
46 | else if (t1 < t2) return -1; | |
47 | else return 1; | |
48 | } | |
49 | }); | |
37 | // For mainly historical reasons, we keep the element type in a number | |
38 | // of different formats. Need to normalise it before sorting. | |
39 | pois.sort((o1, o2) -> Integer.compare(MdrUtils.fullTypeToNaturalType(o1.getType()), | |
40 | MdrUtils.fullTypeToNaturalType(o2.getType()))); | |
50 | 41 | } |
51 | 42 | |
52 | 43 | /** |
91 | 82 | * Release the copy of the pois. The other index is small and not worth |
92 | 83 | * worrying about. |
93 | 84 | */ |
85 | @Override | |
94 | 86 | protected void releaseMemory() { |
95 | 87 | pois = null; |
96 | 88 | } |
14 | 14 | |
15 | 15 | import java.text.Collator; |
16 | 16 | import java.util.ArrayList; |
17 | import java.util.Collections; | |
18 | import java.util.Comparator; | |
19 | 17 | import java.util.List; |
20 | 18 | |
21 | 19 | /** |
49 | 47 | */ |
50 | 48 | public void buildFromStreets(List<Mdr7Record> inStreets) { |
51 | 49 | ArrayList<Mdr7Record> sorted = new ArrayList<>(inStreets); |
52 | Collections.sort(sorted, new Comparator<Mdr7Record>() { | |
53 | public int compare(Mdr7Record o1, Mdr7Record o2) { | |
54 | int d = Integer.compare(o1.getCity().getMdr20SortPos(), o2.getCity().getMdr20SortPos()); | |
55 | if (d != 0) | |
56 | return d; | |
57 | return Integer.compare(o1.getIndex(), o2.getIndex()); | |
58 | } | |
50 | sorted.sort((o1, o2) -> { | |
51 | int d = Integer.compare(o1.getCity().getMdr20SortPos(), o2.getCity().getMdr20SortPos()); | |
52 | if (d != 0) | |
53 | return d; | |
54 | return Integer.compare(o1.getIndex(), o2.getIndex()); | |
59 | 55 | }); |
60 | 56 | |
61 | 57 | Collator collator = getConfig().getSort().getCollator(); |
95 | 91 | * Two streets are in the same group if they have the same mdr20 id. |
96 | 92 | */ |
97 | 93 | protected boolean sameGroup(Mdr7Record street1, Mdr7Record street2) { |
98 | if (street2 != null && street1.getCity().getMdr20() == street2.getCity().getMdr20()) | |
99 | return true; | |
100 | return false; | |
94 | return street2 != null && street1.getCity().getMdr20() == street2.getCity().getMdr20(); | |
101 | 95 | } |
102 | 96 | |
103 | 97 | /** |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | import java.util.Comparator; | |
17 | 15 | import java.util.List; |
18 | 16 | |
19 | 17 | /** |
41 | 39 | if (street.getCity() != null && street.getCity().getMdrRegion() != null) |
42 | 40 | sorted.add(street); |
43 | 41 | } |
44 | Collections.sort(sorted, new Comparator<Mdr7Record>() { | |
45 | public int compare(Mdr7Record o1, Mdr7Record o2) { | |
46 | int d = Integer.compare(o1.getCity().getMdr21SortPos(), o2.getCity().getMdr21SortPos()); | |
47 | if (d != 0) | |
48 | return d; | |
49 | return Integer.compare(o1.getIndex(), o2.getIndex()); | |
50 | } | |
42 | sorted.sort((o1, o2) -> { | |
43 | int d = Integer.compare(o1.getCity().getMdr21SortPos(), o2.getCity().getMdr21SortPos()); | |
44 | if (d != 0) | |
45 | return d; | |
46 | return Integer.compare(o1.getIndex(), o2.getIndex()); | |
51 | 47 | }); |
52 | ||
53 | 48 | |
54 | 49 | int lastIndex = -1; |
55 | 50 | int record = 0; |
14 | 14 | |
15 | 15 | import java.util.ArrayList; |
16 | 16 | import java.util.Collections; |
17 | import java.util.Comparator; | |
18 | 17 | import java.util.List; |
19 | 18 | |
20 | 19 | /** |
49 | 48 | sorted.add(street); |
50 | 49 | } |
51 | 50 | } |
52 | Collections.sort(sorted, new Comparator<Mdr7Record>() { | |
53 | public int compare(Mdr7Record o1, Mdr7Record o2) { | |
54 | int d = Integer.compare(o1.getCity().getMdr22SortPos(), o2.getCity().getMdr22SortPos()); | |
55 | if (d != 0) | |
56 | return d; | |
57 | return Integer.compare(o1.getIndex(), o2.getIndex()); | |
58 | } | |
51 | sorted.sort((o1, o2) -> { | |
52 | int d = Integer.compare(o1.getCity().getMdr22SortPos(), o2.getCity().getMdr22SortPos()); | |
53 | if (d != 0) | |
54 | return d; | |
55 | return Integer.compare(o1.getIndex(), o2.getIndex()); | |
59 | 56 | }); |
60 | ||
61 | 57 | |
62 | 58 | int lastIndex = -1; |
63 | 59 | int record = 0; |
76 | 72 | lastIndex = street.getIndex(); |
77 | 73 | } |
78 | 74 | } |
79 | return; | |
80 | 75 | } |
81 | 76 | |
82 | 77 | protected boolean sameGroup(Mdr7Record street1, Mdr7Record street2) { |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.List; |
17 | 16 | |
18 | 17 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
25 | 24 | * @author Steve Ratcliffe |
26 | 25 | */ |
27 | 26 | public class Mdr23 extends MdrSection { |
28 | private final List<Mdr13Record> regions = new ArrayList<Mdr13Record>(); | |
27 | private final List<Mdr13Record> regions = new ArrayList<>(); | |
29 | 28 | |
30 | 29 | public Mdr23(MdrConfig config) { |
31 | 30 | setConfig(config); |
38 | 37 | public void sortRegions(List<Mdr13Record> list) { |
39 | 38 | Sort sort = getConfig().getSort(); |
40 | 39 | List<SortKey<Mdr13Record>> keys = MdrUtils.sortList(sort, list); |
41 | Collections.sort(keys); | |
42 | 40 | |
43 | 41 | String lastName = null; |
44 | 42 | int lastMapIndex = 0; |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.List; |
17 | 16 | |
18 | 17 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
25 | 24 | * @author Steve Ratcliffe |
26 | 25 | */ |
27 | 26 | public class Mdr24 extends MdrSection { |
28 | private final List<Mdr14Record> countries = new ArrayList<Mdr14Record>(); | |
27 | private final List<Mdr14Record> countries = new ArrayList<>(); | |
29 | 28 | |
30 | 29 | public Mdr24(MdrConfig config) { |
31 | 30 | setConfig(config); |
38 | 37 | public void sortCountries(List<Mdr14Record> list) { |
39 | 38 | Sort sort = getConfig().getSort(); |
40 | 39 | List<SortKey<Mdr14Record>> keys = MdrUtils.sortList(sort, list); |
41 | ||
42 | Collections.sort(keys); | |
43 | 40 | |
44 | 41 | String lastName = null; |
45 | 42 | int lastMapIndex = 0; |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.List; |
17 | 16 | |
18 | 17 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
44 | 43 | keys.add(key); |
45 | 44 | } |
46 | 45 | |
47 | Collections.sort(keys); | |
46 | keys.sort(null); | |
48 | 47 | |
49 | 48 | String lastName = null; |
50 | 49 | Mdr5Record lastCity = null; |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.List; |
17 | 16 | |
18 | 17 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
40 | 39 | SortKey<Mdr28Record> key = sort.createSortKey(mdr28, mdr28.getMdr14().getName(), ++record); |
41 | 40 | sortList.add(key); |
42 | 41 | } |
43 | Collections.sort(sortList); | |
42 | sortList.sort(null); | |
44 | 43 | |
45 | 44 | addToIndex(sortList); |
46 | 45 | } |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.List; |
17 | 16 | |
18 | 17 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
47 | 46 | } |
48 | 47 | } |
49 | 48 | |
50 | Collections.sort(keys); | |
49 | keys.sort(null); | |
51 | 50 | |
52 | 51 | String lastName = null; |
53 | 52 | int record = 0; |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.HashSet; |
17 | 16 | import java.util.List; |
18 | 17 | import java.util.Set; |
36 | 35 | |
37 | 36 | public void writeSectData(ImgFileWriter writer) { |
38 | 37 | List<Mdr4Record> list = new ArrayList<Mdr4Record>(poiTypes); |
39 | Collections.sort(list); | |
38 | list.sort(null); | |
40 | 39 | |
41 | 40 | for (Mdr4Record r : list) { |
42 | 41 | writer.put1u(r.getType()); |
67 | 67 | sortKey = new MultiSortKey<>(sortKey, regionKey, countryKey); |
68 | 68 | sortKeys.add(sortKey); |
69 | 69 | } |
70 | Collections.sort(sortKeys); | |
70 | sortKeys.sort(null); | |
71 | 71 | |
72 | 72 | Collator collator = getConfig().getSort().getCollator(); |
73 | 73 | |
120 | 120 | sortKey = new MultiSortKey<>(sortKey, regionKey, countryKey); |
121 | 121 | sortKeys.add(sortKey); |
122 | 122 | } |
123 | Collections.sort(sortKeys); | |
123 | sortKeys.sort(null); | |
124 | 124 | |
125 | 125 | SortKey<Mdr5Record> lastKey = null; |
126 | 126 | int pos = 0; |
146 | 146 | // Sort by region name. |
147 | 147 | sortKeys.add(sort.createSortKey(m, m.getRegionName())); |
148 | 148 | } |
149 | Collections.sort(sortKeys); | |
149 | sortKeys.sort(null); | |
150 | 150 | |
151 | 151 | SortKey<Mdr5Record> lastKey = null; |
152 | 152 | int pos = 0; |
174 | 174 | SortKey<Mdr5Record> countryKey = sort.createSortKey(m, m.getCountryName()); |
175 | 175 | sortKeys.add(countryKey); |
176 | 176 | } |
177 | Collections.sort(sortKeys); | |
177 | sortKeys.sort(null); | |
178 | 178 | |
179 | 179 | SortKey<Mdr5Record> lastKey = null; |
180 | 180 | int pos = 0; |
247 | 247 | // This sometimes presents search results in the wrong order. The partial sort fields allow to |
248 | 248 | // tell the right order. |
249 | 249 | |
250 | // LargeListSorter<Mdr7Record> initalPartSorter = new LargeListSorter<Mdr7Record>(sort) { | |
251 | // @Override | |
252 | // protected SortKey<Mdr7Record> makeKey(Mdr7Record r, Sort sort, Map<String, byte[]> cache) { | |
253 | // return sort.createSortKey(r, r.getInitialPart(), r.getMapIndex(), cache); | |
254 | // } | |
255 | // }; | |
256 | // LargeListSorter<Mdr7Record> suffixSorter = new LargeListSorter<Mdr7Record>(sort) { | |
257 | // @Override | |
258 | // protected SortKey<Mdr7Record> makeKey(Mdr7Record r, Sort sort, Map<String, byte[]> cache) { | |
259 | // return sort.createSortKey(r, r.getSuffix(), r.getMapIndex(), cache); | |
260 | // } | |
261 | // }; | |
262 | 250 | LargeListSorter<Mdr7Record> fullNameSorter = new LargeListSorter<Mdr7Record>(sort) { |
263 | 251 | @Override |
264 | 252 | protected SortKey<Mdr7Record> makeKey(Mdr7Record r, Sort sort, Map<String, byte[]> cache) { |
267 | 255 | }; |
268 | 256 | |
269 | 257 | |
270 | // List<Mdr7Record> sortedByInitial = new ArrayList<>(samePartial); | |
271 | // List<Mdr7Record> sortedBySuffix = new ArrayList<>(samePartial); | |
272 | // initalPartSorter.sort(sortedByInitial); | |
273 | // suffixSorter.sort(sortedBySuffix); | |
274 | ||
275 | // Mdr7Record last = null; | |
276 | // for (int i = 0; i < samePartial.size(); i++) { | |
277 | // Mdr7Record r = samePartial.get(i); | |
278 | // if (i > 0) { | |
279 | // int repeat = r.checkRepeat(last, collator); | |
280 | // int b = 0; | |
281 | // if (repeat == 0) { | |
282 | // } else if (repeat == 3) | |
283 | // b = last.getB(); | |
284 | // else if (repeat == 1) { | |
285 | // b = last.getB() + 1; | |
286 | // } | |
287 | // if (b != 0) { | |
288 | // if (b > maxPrefixCount) | |
289 | // maxPrefixCount = b; | |
290 | // r.setB(b); | |
291 | // } | |
292 | // } | |
293 | // last = r; | |
294 | // } | |
295 | // suffixSorter.sort(samePartial); | |
296 | // last = null; | |
297 | // int s = 0; | |
298 | // for (int i = 0; i < samePartial.size(); i++) { | |
299 | // Mdr7Record r = samePartial.get(i); | |
300 | // if (i > 0) { | |
301 | // int cmp = collator.compare(last.getSuffix(), r.getSuffix()); | |
302 | // if (cmp == 0) | |
303 | // s = last.getS(); | |
304 | // else | |
305 | // s = last.getS() + 1; | |
306 | // if (s != 0) { | |
307 | // if (s > maxSuffixCount) | |
308 | // maxSuffixCount = s; | |
309 | // r.setB(s); | |
310 | // } | |
311 | // } | |
312 | // last = r; | |
313 | // } | |
314 | // | |
315 | // | |
316 | 258 | fullNameSorter.sort(samePartial); |
317 | 259 | Mdr7Record last = null; |
318 | 260 | int recordNumber = streets.size(); |
319 | 261 | |
320 | 262 | // list is now sorted by partial name, name, and map index |
321 | // // De-duplicate the street names so that there is only one entry | |
322 | // // per map for the same name. | |
263 | // De-duplicate the street names so that there is only one entry | |
264 | // per map for the same name. | |
323 | 265 | for (int i = 0; i < samePartial.size(); i++) { |
324 | 266 | Mdr7Record r = samePartial.get(i); |
325 | 267 | if (last != null && r.getMapIndex() == last.getMapIndex() && r.getName().equals(last.getName())) { |
342 | 284 | boolean hasStrings = hasFlag(MDR7_HAS_STRING); |
343 | 285 | boolean hasNameOffset = hasFlag(MDR7_HAS_NAME_OFFSET); |
344 | 286 | Collator collator = sort.getCollator(); |
345 | // int partialBShift = ((getExtraValue() >> 9) & 0xf); | |
346 | 287 | collator.setStrength(Collator.SECONDARY); |
347 | 288 | Mdr7Record last = null; |
348 | 289 | for (Mdr7Record s : streets) { |
363 | 304 | writer.put1u(s.getOutNameOffset()); |
364 | 305 | if (partialInfoSize > 0) { |
365 | 306 | int trailingFlags = ((rr & 1) == 0) ? 1 : 0; |
366 | // trailingFlags |= s.getB() << 1; | |
367 | // trailingFlags |= s.getS() << (1 + partialBShift); | |
368 | 307 | writer.putNu(partialInfoSize, trailingFlags); |
369 | 308 | } |
370 | 309 | last = s; |
12 | 12 | package uk.me.parabola.imgfmt.app.mdr; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | 15 | import java.util.List; |
17 | 16 | |
18 | 17 | import uk.me.parabola.imgfmt.app.srt.Sort; |
85 | 84 | } |
86 | 85 | |
87 | 86 | /** |
88 | * Sort records that are sorted by a name. They appropriate sort order will be used. | |
87 | * Sort records that are to be sorted by a name. The appropriate sort order will be used. | |
89 | 88 | * @param sort The sort to be applied. |
90 | 89 | * @param list The list to be sorted. |
91 | 90 | * @param <T> One of the Mdr?Record types that need to be sorted on a text field, eg street name. |
93 | 92 | * by calling getObject(). |
94 | 93 | */ |
95 | 94 | public static <T extends NamedRecord> List<SortKey<T>> sortList(Sort sort, List<T> list) { |
96 | List<SortKey<T>> toSort = new ArrayList<SortKey<T>>(list.size()); | |
95 | List<SortKey<T>> toSort = new ArrayList<>(list.size()); | |
97 | 96 | for (T m : list) { |
98 | 97 | SortKey<T> sortKey = sort.createSortKey(m, m.getName(), m.getMapIndex()); |
99 | 98 | toSort.add(sortKey); |
100 | 99 | } |
101 | Collections.sort(toSort); | |
100 | toSort.sort(null); | |
102 | 101 | return toSort; |
103 | 102 | } |
104 | 103 |
12 | 12 | package uk.me.parabola.imgfmt.app.net; |
13 | 13 | |
14 | 14 | import java.util.ArrayList; |
15 | import java.util.Collections; | |
16 | import java.util.Comparator; | |
17 | 15 | import java.util.HashSet; |
18 | 16 | import java.util.Iterator; |
19 | 17 | import java.util.List; |
149 | 147 | if (n <= 1) |
150 | 148 | return; |
151 | 149 | // sort the arcs by initial heading |
152 | Collections.sort(arcGroups, new Comparator<ArcGroup>() { | |
153 | public int compare(ArcGroup ag1, ArcGroup ag2) { | |
154 | if (ag1.initialHeading < ag2.initialHeading) | |
155 | return -1; | |
156 | if (ag1.initialHeading > ag2.initialHeading) | |
157 | return 1; | |
158 | return 0; | |
159 | } | |
160 | }); | |
150 | arcGroups.sort((ag1, ag2) -> Float.compare(ag1.initialHeading, ag2.initialHeading)); | |
161 | 151 | |
162 | 152 | class AngleAttr { |
163 | 153 | int angle; |
359 | 349 | return arcGroups; // should not happen |
360 | 350 | |
361 | 351 | // sort the arcs by initial heading |
362 | Collections.sort(directArcs, new Comparator<RouteArc>() { | |
363 | public int compare(RouteArc ra1, RouteArc ra2) { | |
364 | if (ra1.getInitialHeading() < ra2.getInitialHeading()) | |
365 | return -1; | |
366 | if (ra1.getInitialHeading() > ra2.getInitialHeading()) | |
367 | return 1; | |
368 | int d = Integer.compare(ra1.getPointsHash(), ra2.getPointsHash()); | |
369 | if (d != 0) | |
370 | return d; | |
371 | d = Long.compare(ra1.getRoadDef().getId() , ra2.getRoadDef().getId()); | |
372 | if (d != 0) | |
373 | return d; | |
374 | return d; | |
375 | } | |
376 | }); | |
377 | ||
352 | directArcs.sort((ra1,ra2) -> { | |
353 | int d = Float.compare(ra1.getInitialHeading(), ra2.getInitialHeading()); | |
354 | if (d != 0) | |
355 | return d; | |
356 | d = Integer.compare(ra1.getPointsHash(), ra2.getPointsHash()); | |
357 | if (d != 0) | |
358 | return d; | |
359 | d = Long.compare(ra1.getRoadDef().getId() , ra2.getRoadDef().getId()); | |
360 | if (d != 0) | |
361 | return d; | |
362 | return d; | |
363 | }); | |
364 | ||
378 | 365 | Iterator<RouteArc> iter = directArcs.listIterator(); |
379 | 366 | RouteArc arc1 = iter.next(); |
380 | 367 | boolean addArc1 = false; |
16 | 16 | package uk.me.parabola.imgfmt.app.net; |
17 | 17 | |
18 | 18 | import java.util.ArrayList; |
19 | import java.util.Collections; | |
20 | import java.util.Comparator; | |
21 | 19 | import java.util.HashMap; |
22 | 20 | import java.util.List; |
23 | 21 | import java.util.Map; |
125 | 123 | |
126 | 124 | // Sort by name, city, region/country and subdivision number. |
127 | 125 | LabeledRoadDef lrd = new LabeledRoadDef(label, rd); |
128 | SortKey<LabeledRoadDef> nameKey = new IntegerSortKey<NETFile.LabeledRoadDef>(lrd, label.getOffset(), 0); | |
126 | SortKey<LabeledRoadDef> nameKey = new IntegerSortKey<>(lrd, label.getOffset(), 0); | |
129 | 127 | // If there is a city add it to the sort. |
130 | 128 | City city = (rd.getCities().isEmpty() ? null : rd.getCities().get(0)); // what if we more than one? |
131 | 129 | SortKey<LabeledRoadDef> cityKey; |
144 | 142 | } |
145 | 143 | } |
146 | 144 | |
147 | Collections.sort(sortKeys); | |
145 | sortKeys.sort(null); | |
148 | 146 | |
149 | 147 | List<LabeledRoadDef> out = new ArrayList<>(sortKeys.size()); |
150 | 148 | |
193 | 191 | SortKey<LabeledRoadDef> sk2 = sort.createSortKey(null, lrd.label, 0, cacheFull); |
194 | 192 | sortKeys.add(new DoubleSortKey<>(sk1, sk2)); |
195 | 193 | } |
196 | Collections.sort(sortKeys); | |
194 | sortKeys.sort(null); | |
197 | 195 | roads.clear(); |
198 | 196 | for (SortKey<LabeledRoadDef> key : sortKeys) { |
199 | 197 | roads.add(key.getObject()); |
278 | 276 | * @param out List to add the discovered groups. |
279 | 277 | */ |
280 | 278 | private void addDisconnectedLarge(List<LabeledRoadDef> in, List<LabeledRoadDef> out) { |
281 | Collections.sort(in, new Comparator<LabeledRoadDef>() { | |
282 | public int compare(LabeledRoadDef o1, LabeledRoadDef o2) { | |
283 | Integer i1 = o1.roadDef.getStartSubdivNumber(); | |
284 | Integer i2 = o2.roadDef.getStartSubdivNumber(); | |
285 | return i1.compareTo(i2); | |
286 | } | |
287 | }); | |
279 | in.sort((o1, o2) -> Integer.compare(o1.roadDef.getStartSubdivNumber(), o2.roadDef.getStartSubdivNumber())); | |
288 | 280 | |
289 | 281 | int lastDiv = 0; |
290 | 282 | List<LabeledRoadDef> dupes = new ArrayList<>(); |
11 | 11 | */ |
12 | 12 | package uk.me.parabola.imgfmt.app.net; |
13 | 13 | |
14 | import it.unimi.dsi.fastutil.ints.IntArrayList; | |
15 | ||
16 | 14 | import java.util.ArrayList; |
17 | import java.util.Collections; | |
18 | 15 | import java.util.HashMap; |
19 | 16 | import java.util.HashSet; |
20 | 17 | import java.util.List; |
21 | 18 | import java.util.Map; |
22 | 19 | import java.util.Set; |
23 | 20 | |
21 | import it.unimi.dsi.fastutil.ints.IntArrayList; | |
24 | 22 | import uk.me.parabola.imgfmt.Utils; |
25 | 23 | import uk.me.parabola.imgfmt.app.BufferedImgFileReader; |
26 | 24 | import uk.me.parabola.imgfmt.app.ImgFile; |
286 | 284 | // Sort in address order in the hope of speeding up reading. |
287 | 285 | List<Integer> offsets = new ArrayList<>(allOffsets); |
288 | 286 | allOffsets = null; |
289 | Collections.sort(offsets); | |
287 | offsets.sort(null); | |
290 | 288 | return offsets; |
291 | 289 | } |
292 | 290 |
16 | 16 | package uk.me.parabola.imgfmt.app.net; |
17 | 17 | |
18 | 18 | import java.util.ArrayList; |
19 | import java.util.Collections; | |
20 | import java.util.Comparator; | |
21 | 19 | import java.util.LinkedHashMap; |
22 | 20 | import java.util.LinkedList; |
23 | 21 | import java.util.List; |
328 | 326 | * be a legal RouteCenter. |
329 | 327 | */ |
330 | 328 | private RouteCenter toRouteCenter() { |
331 | Collections.sort(nodes, new Comparator<RouteNode>() { | |
332 | public int compare(RouteNode n1, RouteNode n2) { | |
333 | return n1.getCoord().compareTo(n2.getCoord()); | |
334 | } | |
335 | }); | |
329 | nodes.sort((n1, n2) -> n1.getCoord().compareTo(n2.getCoord())); | |
336 | 330 | TableB tabB = new TableB(); |
337 | 331 | for (RouteNode rn : destNodes.keySet()) |
338 | 332 | tabB.addNode(rn); |
16 | 16 | package uk.me.parabola.imgfmt.app.net; |
17 | 17 | |
18 | 18 | import java.util.ArrayList; |
19 | import java.util.Collections; | |
20 | 19 | import java.util.List; |
21 | 20 | |
22 | 21 | import uk.me.parabola.imgfmt.app.BufferedImgFileReader; |
134 | 133 | private void writeBoundary() { |
135 | 134 | log.info("writeBoundary"); |
136 | 135 | |
137 | Collections.sort(boundary); | |
136 | boundary.sort(null); | |
138 | 137 | |
139 | 138 | ImgFileWriter writer = new SectionWriter(getWriter(), nodHeader.getBoundarySection()); |
140 | 139 | |
155 | 154 | */ |
156 | 155 | private void writeHighClassBoundary() { |
157 | 156 | log.info("writeBoundary"); |
158 | ||
159 | // Collections.sort(boundary); // already sorted for NOD3 | |
160 | 157 | |
161 | 158 | Section section = nodHeader.getHighClassBoundary(); |
162 | 159 | int pos = section.getPosition(); |
28 | 28 | import uk.me.parabola.imgfmt.MapFailedException; |
29 | 29 | import uk.me.parabola.imgfmt.Utils; |
30 | 30 | import uk.me.parabola.imgfmt.app.BitWriter; |
31 | import uk.me.parabola.imgfmt.app.Coord; | |
32 | 31 | import uk.me.parabola.imgfmt.app.ImgFileWriter; |
33 | 32 | import uk.me.parabola.imgfmt.app.Label; |
34 | 33 | import uk.me.parabola.imgfmt.app.lbl.City; |
617 | 617 | return added; |
618 | 618 | } |
619 | 619 | |
620 | public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) { | |
621 | RouteNode node = nodes.get(junctionNodeId); | |
622 | assert node != null : "Can't find node with id " + junctionNodeId; | |
623 | ||
624 | node.addThroughRoute(roadIdA, roadIdB); | |
625 | } | |
626 | ||
627 | 620 | /** |
628 | 621 | * Calculate the "angle" between to arcs. The arcs may not be connected. |
629 | 622 | * We do this by "virtually" moving the toArc so that its source |
64 | 64 | private final CoordNode coord; |
65 | 65 | private int latOff; |
66 | 66 | private int lonOff; |
67 | private List<RouteArc[]> throughRoutes; | |
68 | 67 | |
69 | 68 | // contains the maximum of roads this node is on, written with the flags |
70 | 69 | // field. It is also used for the calculation of the destination class on |
673 | 672 | } |
674 | 673 | } |
675 | 674 | } |
676 | } | |
677 | ||
678 | public void addThroughRoute(long roadIdA, long roadIdB) { | |
679 | if(throughRoutes == null) | |
680 | throughRoutes = new ArrayList<>(); | |
681 | boolean success = false; | |
682 | for(RouteArc arc1 : arcs) { | |
683 | if(arc1.getRoadDef().getId() == roadIdA) { | |
684 | for(RouteArc arc2 : arcs) { | |
685 | if(arc2.getRoadDef().getId() == roadIdB) { | |
686 | throughRoutes.add(new RouteArc[] { arc1.getReverseArc(), arc2 }); | |
687 | success = true; | |
688 | break; | |
689 | } | |
690 | } | |
691 | } | |
692 | else if(arc1.getRoadDef().getId() == roadIdB) { | |
693 | for(RouteArc arc2 : arcs) { | |
694 | if(arc2.getRoadDef().getId() == roadIdA) { | |
695 | throughRoutes.add(new RouteArc[] { arc1.getReverseArc(), arc2 }); | |
696 | success = true; | |
697 | break; | |
698 | } | |
699 | } | |
700 | } | |
701 | } | |
702 | /* | |
703 | for(RouteArc arc1 : incomingArcs) { | |
704 | if(arc1.getRoadDef().getId() == roadIdA) { | |
705 | for(RouteArc arc2 : arcs) { | |
706 | if(arc2.getRoadDef().getId() == roadIdB) { | |
707 | throughRoutes.add(new RouteArc[] { arc1, arc2 }); | |
708 | success = true; | |
709 | break; | |
710 | } | |
711 | } | |
712 | } | |
713 | else if(arc1.getRoadDef().getId() == roadIdB) { | |
714 | for(RouteArc arc2 : arcs) { | |
715 | if(arc2.getRoadDef().getId() == roadIdA) { | |
716 | throughRoutes.add(new RouteArc[] { arc1, arc2 }); | |
717 | success = true; | |
718 | break; | |
719 | } | |
720 | } | |
721 | } | |
722 | } | |
723 | */ | |
724 | if(success) | |
725 | log.info("Added through route between ways " + roadIdA + " and " + roadIdB + " at " + coord.toOSMURL()); | |
726 | else | |
727 | log.warn("Failed to add through route between ways " + roadIdA + " and " + roadIdB + " at " + coord.toOSMURL() + " - perhaps they don't meet here?"); | |
728 | 675 | } |
729 | 676 | |
730 | 677 | /** |
18 | 18 | import java.text.DecimalFormat; |
19 | 19 | import java.text.ParsePosition; |
20 | 20 | import java.util.ArrayList; |
21 | import java.util.Collections; | |
22 | 21 | import java.util.List; |
23 | 22 | import java.util.Map; |
24 | 23 | |
410 | 409 | break; |
411 | 410 | } |
412 | 411 | // sort the lights by increasing sector start angle |
413 | Collections.sort(lights); | |
412 | lights.sort(null); | |
414 | 413 | // generate the descriptor string - each light is |
415 | 414 | // specified as color,range,sectorStartAngle |
416 | 415 | String light = null; |
16 | 16 | package uk.me.parabola.imgfmt.app.trergn; |
17 | 17 | |
18 | 18 | import java.util.ArrayList; |
19 | import java.util.Collections; | |
20 | 19 | import java.util.Iterator; |
21 | 20 | import java.util.List; |
22 | 21 | |
225 | 224 | header.setPointPos(position()); |
226 | 225 | |
227 | 226 | // Point overview section |
228 | Collections.sort(pointOverviews); | |
227 | pointOverviews.sort(null); | |
229 | 228 | for (Overview ov : pointOverviews) { |
230 | 229 | if(!ov.hasExtType()) { |
231 | 230 | ov.setMaxLevel(decodeLevel(ov.getMinResolution())); |
236 | 235 | |
237 | 236 | // Line overview section. |
238 | 237 | header.setPolylinePos(position()); |
239 | Collections.sort(polylineOverviews); | |
238 | polylineOverviews.sort(null); | |
240 | 239 | for (Overview ov : polylineOverviews) { |
241 | 240 | if(!ov.hasExtType()) { |
242 | 241 | ov.setMaxLevel(decodeLevel(ov.getMinResolution())); |
247 | 246 | |
248 | 247 | // Polygon overview section |
249 | 248 | header.setPolygonPos(position()); |
250 | Collections.sort(polygonOverviews); | |
249 | polygonOverviews.sort(null); | |
251 | 250 | for (Overview ov : polygonOverviews) { |
252 | 251 | if(!ov.hasExtType()) { |
253 | 252 | ov.setMaxLevel(decodeLevel(ov.getMinResolution())); |
21 | 21 | import java.nio.charset.CharacterCodingException; |
22 | 22 | import java.nio.charset.CharsetEncoder; |
23 | 23 | import java.util.ArrayList; |
24 | import java.util.Collections; | |
25 | 24 | import java.util.List; |
26 | 25 | import java.util.Map; |
27 | 26 | import java.util.TreeMap; |
100 | 99 | keys.add(key); |
101 | 100 | } |
102 | 101 | } |
103 | Collections.sort(keys); | |
102 | keys.sort(null); | |
104 | 103 | |
105 | 104 | // Offset 0 is reserved to mean no label. |
106 | 105 | writer.put1u(0); |
159 | 158 | private void writeSection(ImgFileWriter writer, Section dataSection, Section indexSection, |
160 | 159 | List<? extends TypElement> elementData) |
161 | 160 | { |
162 | Collections.sort(elementData); | |
161 | elementData.sort(null); | |
163 | 162 | |
164 | 163 | SectionWriter subWriter = dataSection.makeSectionWriter(writer); |
165 | 164 | CharsetEncoder encoder = data.getEncoder(); |
20 | 20 | import java.nio.channels.FileChannel; |
21 | 21 | import java.nio.channels.WritableByteChannel; |
22 | 22 | import java.util.ArrayList; |
23 | import java.util.Collections; | |
24 | import java.util.Comparator; | |
25 | 23 | import java.util.List; |
26 | 24 | |
27 | 25 | /** |
36 | 34 | private final char familyId; |
37 | 35 | private final char productId; |
38 | 36 | |
39 | private final List<MapInfo> maps = new ArrayList<MapInfo>(); | |
37 | private final List<MapInfo> maps = new ArrayList<>(); | |
40 | 38 | |
41 | 39 | /** |
42 | 40 | * Create with default family and product ids. |
98 | 96 | |
99 | 97 | private void writeBody(WritableByteChannel chan, ByteBuffer buf) throws IOException { |
100 | 98 | // Sort the maps by the hex number. |
101 | Collections.sort(maps, new Comparator<MapInfo>() { | |
102 | public int compare(MapInfo o1, MapInfo o2) { | |
103 | if (o1.getHexMapname() == o2.getHexMapname()) | |
104 | return 0; | |
105 | else if (o1.getHexMapname() < o2.getHexMapname()) | |
106 | return -1; | |
107 | else | |
108 | return 1; | |
109 | } | |
110 | }); | |
99 | maps.sort((o1, o2) -> Integer.compare(o1.getHexMapname(), o2.getHexMapname())); | |
111 | 100 | |
112 | 101 | for (MapInfo info : maps) { |
113 | 102 | // Although its not necessarily wrong for them to be zero, it probably |
23 | 23 | import java.util.ArrayList; |
24 | 24 | import java.util.Arrays; |
25 | 25 | import java.util.Collections; |
26 | import java.util.Comparator; | |
27 | 26 | import java.util.HashMap; |
28 | 27 | import java.util.IdentityHashMap; |
29 | 28 | import java.util.List; |
30 | 29 | import java.util.Set; |
31 | 30 | import java.util.function.UnaryOperator; |
32 | 31 | |
32 | import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; | |
33 | 33 | import uk.me.parabola.imgfmt.ExitException; |
34 | 34 | import uk.me.parabola.imgfmt.MapFailedException; |
35 | 35 | import uk.me.parabola.imgfmt.Utils; |
103 | 103 | import uk.me.parabola.util.Configurable; |
104 | 104 | import uk.me.parabola.util.EnhancedProperties; |
105 | 105 | import uk.me.parabola.util.Java2DConverter; |
106 | import it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap; | |
107 | 106 | |
108 | 107 | /** |
109 | 108 | * This is the core of the code to translate from the general representation |
1225 | 1224 | |
1226 | 1225 | if (orderByDecreasingArea && shapes.size() > 1) { |
1227 | 1226 | // sort so that the shape with the largest area is processed first |
1228 | Collections.sort(shapes, new Comparator<MapShape>() { | |
1229 | public int compare(MapShape s1, MapShape s2) { | |
1230 | return Long.compare(Math.abs(s2.getFullArea()), Math.abs(s1.getFullArea())); | |
1231 | } | |
1232 | }); | |
1227 | shapes.sort((s1,s2) -> Long.compare(Math.abs(s2.getFullArea()), Math.abs(s1.getFullArea()))); | |
1233 | 1228 | } |
1234 | 1229 | |
1235 | 1230 | preserveHorizontalAndVerticalLines(res, shapes); |
75 | 75 | * @param exceptMask For exceptions eg. no-left-turn except for buses. |
76 | 76 | */ |
77 | 77 | public int addRestriction(GeneralRouteRestriction grr); |
78 | } | |
78 | 79 | |
79 | /** | |
80 | * Add a through route to the map. | |
81 | * | |
82 | */ | |
83 | public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB); | |
84 | } |
129 | 129 | return roadNetwork.addRestriction(grr); |
130 | 130 | } |
131 | 131 | |
132 | public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) { | |
133 | roadNetwork.addThroughRoute(junctionNodeId, roadIdA, roadIdB); | |
134 | } | |
135 | ||
136 | 132 | /** |
137 | 133 | * Add the given point to the total bounds for the map. |
138 | 134 | * |
27 | 27 | import java.time.Instant; |
28 | 28 | import java.util.ArrayList; |
29 | 29 | import java.util.Arrays; |
30 | import java.util.Comparator; | |
31 | 30 | import java.util.Date; |
32 | 31 | import java.util.HashMap; |
33 | 32 | import java.util.HashSet; |
603 | 602 | for (Combiner c : combiners) |
604 | 603 | c.init(args); |
605 | 604 | |
606 | filenames.sort(new Comparator<FilenameTask>() { | |
607 | public int compare(FilenameTask o1, FilenameTask o2) { | |
608 | if (!o1.getFilename().endsWith(".img") || !o2.getFilename().endsWith(".img")) | |
609 | return o1.getFilename().compareTo(o2.getFilename()); | |
610 | ||
611 | // Both end in .img | |
612 | try { | |
613 | int id1 = FileInfo.getFileInfo(o1.getFilename()).getHexname(); | |
614 | int id2 = FileInfo.getFileInfo(o2.getFilename()).getHexname(); | |
615 | if (id1 == id2) | |
616 | return 0; | |
617 | else if (id1 < id2) | |
618 | return -1; | |
619 | else | |
620 | return 1; | |
621 | } catch (FileNotFoundException ignored) { | |
622 | } | |
623 | return 0; | |
624 | } | |
625 | ||
605 | filenames.sort((o1, o2) -> { | |
606 | if (!o1.getFilename().endsWith(".img") || !o2.getFilename().endsWith(".img")) | |
607 | return o1.getFilename().compareTo(o2.getFilename()); | |
608 | ||
609 | // Both end in .img | |
610 | try { | |
611 | return Integer.compare(FileInfo.getFileInfo(o1.getFilename()).getHexname(), | |
612 | FileInfo.getFileInfo(o2.getFilename()).getHexname()); | |
613 | } catch (FileNotFoundException ignored) { | |
614 | } | |
615 | return 0; | |
626 | 616 | }); |
627 | 617 | |
628 | 618 | // will contain img files for which an additional ovm file was found |
35 | 35 | import javax.xml.parsers.ParserConfigurationException; |
36 | 36 | import javax.xml.parsers.SAXParser; |
37 | 37 | import javax.xml.parsers.SAXParserFactory; |
38 | ||
39 | import org.xml.sax.SAXException; | |
38 | 40 | |
39 | 41 | import uk.me.parabola.imgfmt.FormatException; |
40 | 42 | import uk.me.parabola.imgfmt.Utils; |
78 | 80 | import uk.me.parabola.mkgmap.scan.TokenScanner; |
79 | 81 | import uk.me.parabola.util.EnhancedProperties; |
80 | 82 | |
81 | import org.xml.sax.SAXException; | |
82 | ||
83 | 83 | |
84 | 84 | /** |
85 | 85 | * Test style rules by converting to a text format, rather than a .img file. |
391 | 391 | */ |
392 | 392 | private static List<String> formatResults(String prefix, List<MapElement> lines) { |
393 | 393 | List<String> result = new ArrayList<>(); |
394 | int i = 0; | |
395 | 394 | for (MapElement el : lines) { |
396 | 395 | String s; |
397 | 396 | // So we can run against versions that do not have toString() methods |
838 | 837 | public int addRestriction(GeneralRouteRestriction grr) { |
839 | 838 | return 0; |
840 | 839 | } |
841 | ||
842 | public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) { | |
843 | } | |
844 | 840 | } |
845 | 841 | |
846 | 842 | /** |
882 | 878 | return 0; |
883 | 879 | } |
884 | 880 | |
885 | public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) { | |
886 | } | |
887 | ||
888 | 881 | public long getStart() { |
889 | 882 | return start; |
890 | 883 | } |
18 | 18 | import java.util.ArrayList; |
19 | 19 | import java.util.Arrays; |
20 | 20 | import java.util.Collections; |
21 | import java.util.Comparator; | |
22 | 21 | import java.util.HashMap; |
23 | 22 | import java.util.HashSet; |
24 | 23 | import java.util.LinkedHashSet; |
313 | 312 | * @param strings |
314 | 313 | */ |
315 | 314 | private void sortByLength(List<String> strings) { |
316 | strings.sort(new Comparator<String>() { | |
317 | @Override | |
318 | public int compare(String o1, String o2) { | |
319 | return Integer.compare(o2.length(), o1.length()); | |
320 | } | |
321 | }); | |
315 | strings.sort((o1, o2) -> Integer.compare(o2.length(), o1.length())); | |
322 | 316 | } |
323 | 317 | } |
15 | 15 | import java.util.ArrayList; |
16 | 16 | import java.util.Arrays; |
17 | 17 | import java.util.Collections; |
18 | import java.util.Comparator; | |
19 | 18 | import java.util.HashSet; |
20 | 19 | import java.util.IdentityHashMap; |
21 | 20 | import java.util.List; |
27 | 26 | import uk.me.parabola.imgfmt.app.Coord; |
28 | 27 | import uk.me.parabola.imgfmt.app.net.AccessTagsAndBits; |
29 | 28 | import uk.me.parabola.log.Logger; |
30 | import uk.me.parabola.mkgmap.reader.osm.Element; | |
31 | 29 | import uk.me.parabola.mkgmap.reader.osm.GType; |
32 | import uk.me.parabola.mkgmap.reader.osm.Node; | |
33 | import uk.me.parabola.mkgmap.reader.osm.Relation; | |
34 | 30 | import uk.me.parabola.mkgmap.reader.osm.RestrictionRelation; |
35 | 31 | import uk.me.parabola.mkgmap.reader.osm.Way; |
36 | 32 | import uk.me.parabola.util.MultiIdentityHashMap; |
57 | 53 | /** |
58 | 54 | * For these tags two ways need to have an equal value so that their roads can be merged. |
59 | 55 | */ |
60 | private final static Set<String> mergeTagsEqualValue = new HashSet<>(Arrays.asList( | |
56 | private static final Set<String> mergeTagsEqualValue = new HashSet<>(Arrays.asList( | |
61 | 57 | "mkgmap:label:1", |
62 | 58 | "mkgmap:label:2", |
63 | 59 | "mkgmap:label:3", |
109 | 105 | } |
110 | 106 | } |
111 | 107 | |
112 | private void workoutThroughRoutes(List<Relation> throughRouteRelations) { | |
113 | for (Relation relation : throughRouteRelations) { | |
114 | Node node = null; | |
115 | Way w1 = null; | |
116 | Way w2 = null; | |
117 | for (Map.Entry<String, Element> member : relation.getElements()) { | |
118 | if (member.getValue() instanceof Node) { | |
119 | if (node == null) | |
120 | node = (Node) member.getValue(); | |
121 | else | |
122 | log.warn("Through route relation " | |
123 | + relation.toBrowseURL() | |
124 | + " has more than 1 node"); | |
125 | } else if (member.getValue() instanceof Way) { | |
126 | Way w = (Way) member.getValue(); | |
127 | if (w1 == null) | |
128 | w1 = w; | |
129 | else if (w2 == null) | |
130 | w2 = w; | |
131 | else | |
132 | log.warn("Through route relation " | |
133 | + relation.toBrowseURL() | |
134 | + " has more than 2 ways"); | |
135 | } | |
136 | } | |
137 | ||
138 | if (node == null) | |
139 | log.warn("Through route relation " + relation.toBrowseURL() | |
140 | + " is missing the junction node"); | |
141 | ||
142 | if (w1 == null || w2 == null) | |
143 | log.warn("Through route relation " | |
144 | + relation.toBrowseURL() | |
145 | + " should reference 2 ways that meet at the junction node"); | |
146 | ||
147 | if (node != null && w1 != null && w2 != null) { | |
148 | restrictions.add(node.getLocation(), w1.getId()); | |
149 | restrictions.add(node.getLocation(), w2.getId()); | |
150 | } | |
151 | } | |
152 | } | |
153 | ||
154 | 108 | private boolean hasRestriction(Coord c, Way w) { |
155 | 109 | if (w.isViaWay()) |
156 | 110 | return true; |
170 | 124 | private void mergeRoads(ConvertedWay road1, ConvertedWay road2) { |
171 | 125 | // Removes the second line, |
172 | 126 | // Merges the points in the first one |
173 | List<Coord> points1 = road1.getWay().getPoints(); | |
174 | 127 | List<Coord> points2 = road2.getWay().getPoints(); |
175 | ||
176 | 128 | Coord mergePoint = points2.get(0); |
177 | 129 | Coord endPoint= points2.get(points2.size()-1); |
178 | 130 | |
180 | 132 | endPoints.removeMapping(endPoint, road2); |
181 | 133 | endPoints.removeMapping(mergePoint, road1); |
182 | 134 | |
183 | points1.addAll(points2.subList(1, points2.size())); | |
135 | road1.getPoints().addAll(points2.subList(1, points2.size())); | |
184 | 136 | endPoints.add(endPoint, road1); |
185 | 137 | |
186 | 138 | // merge the POI info |
187 | 139 | String wayPOI2 = road2.getWay().getTag(StyledConverter.WAY_POI_NODE_IDS); |
188 | 140 | if (wayPOI2 != null){ |
189 | String WayPOI1 = road1.getWay().getTag(StyledConverter.WAY_POI_NODE_IDS); | |
190 | if (wayPOI2.equals(WayPOI1) == false){ | |
191 | if (WayPOI1 == null) | |
192 | WayPOI1 = ""; | |
141 | String wayPOI1 = road1.getWay().getTag(StyledConverter.WAY_POI_NODE_IDS); | |
142 | if (!wayPOI2.equals(wayPOI1)){ | |
143 | if (wayPOI1 == null) | |
144 | wayPOI1 = ""; | |
193 | 145 | // store combination of both ways. This might contain |
194 | 146 | // duplicates, but that is not a problem. |
195 | road1.getWay().addTag(StyledConverter.WAY_POI_NODE_IDS, WayPOI1 + wayPOI2); | |
196 | } | |
197 | } | |
198 | ||
199 | // // the mergePoint is now used by one highway less | |
147 | road1.getWay().addTag(StyledConverter.WAY_POI_NODE_IDS, wayPOI1 + wayPOI2); | |
148 | } | |
149 | } | |
150 | ||
151 | // the mergePoint is now used by one highway less | |
200 | 152 | mergePoint.decHighwayCount(); |
201 | 153 | |
202 | 154 | // road2 is removed - it must not be part of a restriction |
203 | assert (restrictions.get(endPoint).contains(road2.getWay().getId()) == false); | |
155 | assert !restrictions.get(endPoint).contains(road2.getWay().getId()); | |
204 | 156 | |
205 | 157 | } |
206 | 158 | |
210 | 162 | * @param resultingGTypes list for the merged (and not mergeable) GTypes |
211 | 163 | */ |
212 | 164 | public List<ConvertedWay> merge(List<ConvertedWay> convertedWays, |
213 | List<RestrictionRelation> restrictions, | |
214 | List<Relation> throughRouteRelations) { | |
165 | List<RestrictionRelation> restrictions) { | |
215 | 166 | List<ConvertedWay> result = new ArrayList<>(); |
216 | 167 | List<ConvertedWay> roadsToMerge = new ArrayList<>(convertedWays.size()); |
217 | 168 | for (int i = 0; i < convertedWays.size(); i++) { |
221 | 172 | } |
222 | 173 | |
223 | 174 | int noRoadsBeforeMerge = roadsToMerge.size(); |
224 | int noMerges = 0; | |
175 | int numMerges = 0; | |
225 | 176 | |
226 | 177 | List<Coord> mergePoints = new ArrayList<>(); |
227 | 178 | |
228 | 179 | // first add all roads with their start and end points to the |
229 | 180 | // start/endpoint lists |
230 | 181 | for (ConvertedWay road : roadsToMerge) { |
231 | List<Coord> points = road.getWay().getPoints(); | |
232 | Coord start = points.get(0); | |
233 | Coord end = points.get(points.size() - 1); | |
182 | Coord start = road.getWay().getFirstPoint(); | |
183 | Coord end = road.getWay().getLastPoint(); | |
234 | 184 | |
235 | 185 | if (start == end) { |
236 | 186 | // do not merge closed roads |
244 | 194 | endPoints.add(end, road); |
245 | 195 | } |
246 | 196 | workoutRestrictionRelations(restrictions); |
247 | workoutThroughRoutes(throughRouteRelations); | |
248 | 197 | |
249 | 198 | // a set of all points where no more merging is possible |
250 | 199 | Set<Coord> mergeCompletedPoints = Collections.newSetFromMap(new IdentityHashMap<Coord, Boolean>()); |
280 | 229 | continue; |
281 | 230 | } |
282 | 231 | |
283 | List<Coord> points1 = road1.getWay().getPoints(); | |
232 | List<Coord> points1 = road1.getPoints(); | |
284 | 233 | |
285 | 234 | // go through all candidates to merge |
286 | 235 | for (ConvertedWay road2 : startRoads) { |
287 | if (hasRestriction(mergePoint, road2.getWay())) { | |
288 | continue; | |
289 | } | |
290 | List<Coord> points2 = road2.getWay().getPoints(); | |
291 | 236 | |
292 | 237 | // the second road is merged into the first road |
293 | 238 | // so only the id of the first road is kept |
294 | 239 | // This also means that the second road must not have a restriction on |
295 | 240 | // both start and end point |
296 | if (hasRestriction(points2.get(points2.size()-1), road2.getWay())) { | |
241 | if (hasRestriction(mergePoint, road2.getWay()) | |
242 | || hasRestriction(road2.getWay().getLastPoint(), road2.getWay())) { | |
297 | 243 | continue; |
298 | 244 | } |
299 | 245 | |
302 | 248 | // yes they might be merged |
303 | 249 | // calculate the angle between them |
304 | 250 | // if there is more then one road to merge the one with the lowest angle is merged |
305 | double angle = Math.abs(Utils.getAngle(points1.get(points1.size()-2), mergePoint, points2.get(1))); | |
251 | double angle = Math.abs(Utils.getAngle(points1.get(points1.size()-2), mergePoint, road2.getPoints().get(1))); | |
306 | 252 | log.debug("Road",road1.getWay().getId(),"and road",road2.getWay().getId(),"are mergeable with angle",angle); |
307 | 253 | if (angle < bestAngle) { |
308 | 254 | mergeRoad1 = road1; |
318 | 264 | // yes!! => merge them |
319 | 265 | log.debug("Merge",mergeRoad1.getWay().getId(),"and",mergeRoad2.getWay().getId(),"with angle",bestAngle); |
320 | 266 | mergeRoads(mergeRoad1, mergeRoad2); |
321 | noMerges++; | |
267 | numMerges++; | |
322 | 268 | } else { |
323 | // no => do not check again this point again | |
269 | // no => do not check this point again | |
324 | 270 | mergeCompletedPoints.add(mergePoint); |
325 | 271 | } |
326 | 272 | } |
331 | 277 | } |
332 | 278 | |
333 | 279 | // sort the roads to ensure that the order of roads is constant for two runs |
334 | Collections.sort(result, new Comparator<ConvertedWay>() { | |
335 | public int compare(ConvertedWay o1, ConvertedWay o2) { | |
336 | return Integer.compare(o1.getIndex(), o2.getIndex()); | |
337 | } | |
338 | }); | |
280 | result.sort((o1, o2) -> Integer.compare(o1.getIndex(), o2.getIndex())); | |
339 | 281 | |
340 | 282 | // print out some statistics |
341 | 283 | int noRoadsAfterMerge = result.size(); |
343 | 285 | noRoadsAfterMerge); |
344 | 286 | int percentage = (int) Math.round((noRoadsBeforeMerge - noRoadsAfterMerge) * 100.0d |
345 | 287 | / noRoadsBeforeMerge); |
346 | log.info("Road network reduced by", percentage, "%",noMerges,"merges"); | |
288 | log.info("Road network reduced by", percentage, "%",numMerges,"merges"); | |
347 | 289 | return result; |
348 | 290 | } |
349 | 291 | |
358 | 300 | */ |
359 | 301 | private static boolean isMergeable(Coord mergePoint, ConvertedWay road1, ConvertedWay road2) { |
360 | 302 | // check if basic road attributes match |
361 | if (road1.getRoadClass() != road2.getRoadClass()) | |
362 | return false; | |
363 | if (road1.getRoadSpeed() != road2.getRoadSpeed()) | |
364 | return false; | |
303 | if (road1.getRoadClass() != road2.getRoadClass() || road1.getRoadSpeed() != road2.getRoadSpeed()) { | |
304 | return false; | |
305 | } | |
365 | 306 | Way way1 = road1.getWay(); |
366 | 307 | Way way2 = road2.getWay(); |
367 | 308 | |
380 | 321 | return false; |
381 | 322 | } |
382 | 323 | |
324 | if (!checkGeometry(mergePoint, road1, road2)) | |
325 | return false; | |
326 | ||
327 | if (!isGTypeMergeable(road1.getGType(), road2.getGType())) { | |
328 | return false; | |
329 | } | |
330 | ||
331 | if (!isWayTagsMergeable(way1, way2)) | |
332 | return false; | |
333 | ||
334 | return isAngleOK(mergePoint, way1, way2); | |
335 | } | |
336 | ||
337 | ||
338 | /** | |
339 | * Check if roads meet at the given point and don't form a loop or a bad oneway combination | |
340 | * @param mergePoint the mergePoint | |
341 | * @param road1 first road | |
342 | * @param road2 second road | |
343 | * @return true if roads can be merged, else false | |
344 | */ | |
345 | private static boolean checkGeometry(Coord mergePoint, ConvertedWay road1, ConvertedWay road2) { | |
346 | Way way1 = road1.getWay(); | |
347 | Way way2 = road2.getWay(); | |
383 | 348 | // now check if this road starts or stops at the mergePoint |
384 | Coord cStart = road1.getWay().getPoints().get(0); | |
385 | Coord cEnd = road1.getWay().getPoints().get(road1.getWay().getPoints().size() - 1); | |
349 | Coord cStart = way1.getFirstPoint(); | |
350 | Coord cEnd = way1.getLastPoint(); | |
386 | 351 | if (cStart != mergePoint && cEnd != mergePoint) { |
387 | 352 | // it doesn't => roads not mergeable at mergePoint |
388 | 353 | return false; |
389 | 354 | } |
390 | 355 | |
391 | 356 | // do the same check for the otherRoad |
392 | Coord cOtherStart = way2.getPoints().get(0); | |
393 | Coord cOtherEnd = way2.getPoints() | |
394 | .get(way2.getPoints().size() - 1); | |
357 | Coord cOtherStart = way2.getFirstPoint(); | |
358 | Coord cOtherEnd = way2.getLastPoint(); | |
395 | 359 | if (cOtherStart != mergePoint && cOtherEnd != mergePoint) { |
396 | 360 | // otherRoad does not start or stop at mergePoint => |
397 | 361 | // roads not mergeable at mergePoint |
401 | 365 | // check if merging would create a closed way - which should not |
402 | 366 | // be done (why? WanMil) |
403 | 367 | if (cStart == cOtherEnd) { |
404 | return false; | |
405 | } | |
406 | ||
407 | // check if certain fields in the GType objects are the same | |
408 | if (isGTypeMergeable(road1.getGType(), road2.getGType()) == false) { | |
409 | 368 | return false; |
410 | 369 | } |
411 | 370 | |
419 | 378 | return false; |
420 | 379 | } |
421 | 380 | } |
422 | ||
423 | // checks if the tag values of both ways match so that the ways | |
424 | // can be merged | |
425 | if (isWayMergeable(mergePoint, way1, way2) == false) | |
426 | return false; | |
427 | ||
428 | ||
429 | // check if the angle between the two ways is not too sharp | |
430 | if (isAngleOK(mergePoint, way1, way2) == false) | |
431 | return false; | |
432 | ||
433 | 381 | return true; |
434 | 382 | } |
435 | 383 | |
465 | 413 | * objects do not match and must not be merged |
466 | 414 | */ |
467 | 415 | private static boolean isGTypeMergeable(GType type1, GType type2) { |
468 | if (type1.getType() != type2.getType()) { | |
469 | return false; | |
470 | } | |
471 | if (type1.getMinResolution() != type2.getMinResolution()) { | |
472 | return false; | |
473 | } | |
474 | if (type1.getMaxResolution() != type2.getMaxResolution()) { | |
475 | return false; | |
476 | } | |
477 | if (type1.getMinLevel() != type2.getMinLevel()) { | |
478 | return false; | |
479 | } | |
480 | if (type1.getMaxLevel() != type2.getMaxLevel()) { | |
481 | return false; | |
482 | } | |
416 | return type1.getType() == type2.getType() | |
417 | && type1.getMinResolution() == type2.getMinResolution() | |
418 | && type1.getMaxResolution() == type2.getMaxResolution() | |
419 | && type1.getMinLevel() == type2.getMinLevel() | |
420 | && type1.getMaxLevel() == type2.getMaxLevel(); | |
483 | 421 | // roadClass and roadSpeed are taken from the ConvertedWay objects |
484 | // | |
485 | //default name is applied before the RoadMerger starts | |
486 | //so they needn't be equal | |
487 | // if (stringEquals(gtype.getDefaultName(), | |
488 | // otherGType.getDefaultName()) == false) { | |
489 | // return false; | |
490 | // } | |
491 | ||
492 | // log.info("Matches"); | |
493 | return true; | |
494 | 422 | } |
495 | 423 | |
496 | 424 | /** |
497 | 425 | * Checks if the tag values of the {@link Way} objects of both roads |
498 | 426 | * match so that both roads can be merged. |
499 | * @param mergePoint the coord where both roads should be merged | |
500 | 427 | * @param way1 1st way |
501 | 428 | * @param way2 2nd way |
502 | 429 | * @return {@code true} tag values match so that both roads might be merged; |
503 | 430 | * {@code false} tag values differ so that road must not be merged |
504 | 431 | */ |
505 | private static boolean isWayMergeable(Coord mergePoint, Way way1, Way way2) { | |
432 | private static boolean isWayTagsMergeable(Way way1, Way way2) { | |
506 | 433 | // tags that need to have an equal value |
507 | 434 | for (String tagname : mergeTagsEqualValue) { |
508 | 435 | String tag1 = way1.getTag(tagname); |
509 | 436 | String tag2 = way2.getTag(tagname); |
510 | if (stringEquals(tag1, tag2) == false) { | |
437 | if (!stringEquals(tag1, tag2)) { | |
511 | 438 | if (log.isDebugEnabled()){ |
512 | 439 | log.debug(tagname, "does not match", way1.getId(), "(" |
513 | 440 | + tag1 + ")", way2.getId(), "(" + tag2 |
531 | 458 | private static boolean isAngleOK(Coord mergePoint, Way way1, Way way2) { |
532 | 459 | // Check the angle of the two ways |
533 | 460 | Coord cOnWay1; |
534 | if (way1.getPoints().get(0) == mergePoint) { | |
461 | if (way1.getFirstPoint() == mergePoint) { | |
535 | 462 | cOnWay1 = way1.getPoints().get(1); |
536 | 463 | } else { |
537 | 464 | cOnWay1 = way1.getPoints().get(way1.getPoints().size() - 2); |
538 | 465 | } |
539 | 466 | Coord cOnWay2; |
540 | if (way2.getPoints().get(0) == mergePoint) { | |
467 | if (way2.getFirstPoint() == mergePoint) { | |
541 | 468 | cOnWay2 = way2.getPoints().get(1); |
542 | 469 | } else { |
543 | cOnWay2 = way2.getPoints().get( | |
544 | way2.getPoints().size() - 2); | |
470 | cOnWay2 = way2.getPoints().get(way2.getPoints().size() - 2); | |
545 | 471 | } |
546 | 472 | |
547 | 473 | double angle = Math.abs(Utils.getAngle(cOnWay1, mergePoint, cOnWay2)); |
101 | 101 | |
102 | 102 | private Map<Node, List<Way>> poiRestrictions = new LinkedHashMap<>(); |
103 | 103 | |
104 | private final List<Relation> throughRouteRelations = new ArrayList<>(); | |
105 | ||
106 | 104 | // limit line length to avoid problems with portions of really |
107 | 105 | // long lines being assigned to the wrong subdivision |
108 | 106 | private static final int MAX_LINE_LENGTH = 40000; |
340 | 338 | rules = polygonRules; |
341 | 339 | else { |
342 | 340 | if (way.isClosedInOSM() && !way.isComplete() && !way.hasIdenticalEndPoints()) |
343 | way.getPoints().add(way.getPoints().get(0)); | |
341 | way.getPoints().add(way.getFirstPoint()); | |
344 | 342 | |
345 | if (way.hasIdenticalEndPoints() == false || way.getPoints().size() < 4) | |
343 | if (!way.hasIdenticalEndPoints() || way.getPoints().size() < 4) | |
346 | 344 | rules = lineRules; |
347 | 345 | else |
348 | 346 | rules = wayRules; |
457 | 455 | } |
458 | 456 | if (cw.isRoundabout()) { |
459 | 457 | if (wasReversed) |
460 | log.warn("Roundabout", way.getId(), "has reverse oneway tag (" + way.getPoints().get(0).toOSMURL() + ")"); | |
458 | log.warn("Roundabout", way.getId(), "has reverse oneway tag (" + way.getFirstPoint().toOSMURL() + ")"); | |
461 | 459 | } |
462 | 460 | lastRoadId = way.getId(); |
463 | 461 | } |
655 | 653 | continue; |
656 | 654 | |
657 | 655 | // the bounding box of the road intersects with one or more bounding boxes of borders |
658 | Coord pw1 = way.getPoints().get(0); | |
656 | Coord pw1 = way.getFirstPoint(); | |
659 | 657 | int pos = 1; |
660 | 658 | while (pos < way.getPoints().size()) { |
661 | 659 | boolean changed = false; |
748 | 746 | } |
749 | 747 | |
750 | 748 | RoadMerger merger = new RoadMerger(); |
751 | roads = merger.merge(roads, restrictions, throughRouteRelations); | |
749 | roads = merger.merge(roads, restrictions); | |
752 | 750 | } |
753 | 751 | |
754 | 752 | public void end() { |
824 | 822 | rr.addRestriction(collector, nodeIdMap); |
825 | 823 | } |
826 | 824 | } |
825 | // return memory to GC | |
827 | 826 | roads = null; |
828 | if (routable){ | |
829 | for(Relation relation : throughRouteRelations) { | |
830 | Node node = null; | |
831 | Way w1 = null; | |
832 | Way w2 = null; | |
833 | for(Map.Entry<String,Element> member : relation.getElements()) { | |
834 | if(member.getValue() instanceof Node) { | |
835 | if(node == null) | |
836 | node = (Node)member.getValue(); | |
837 | else | |
838 | log.warn("Through route relation", relation.toBrowseURL(), "has more than 1 node"); | |
839 | } | |
840 | else if(member.getValue() instanceof Way) { | |
841 | Way w = (Way)member.getValue(); | |
842 | if(w1 == null) | |
843 | w1 = w; | |
844 | else if(w2 == null) | |
845 | w2 = w; | |
846 | else | |
847 | log.warn("Through route relation", relation.toBrowseURL(), "has more than 2 ways"); | |
848 | } | |
849 | } | |
850 | ||
851 | CoordNode coordNode = null; | |
852 | if(node == null) | |
853 | log.warn("Through route relation", relation.toBrowseURL(), "is missing the junction node"); | |
854 | else { | |
855 | Coord junctionPoint = node.getLocation(); | |
856 | if(bbox != null && !bbox.contains(junctionPoint)) { | |
857 | // junction is outside of the tile - ignore it | |
858 | continue; | |
859 | } | |
860 | coordNode = nodeIdMap.get(junctionPoint); | |
861 | if(coordNode == null) | |
862 | log.warn("Through route relation", relation.toBrowseURL(), "junction node at", junctionPoint.toOSMURL(), "is not a routing node"); | |
863 | } | |
864 | ||
865 | if(w1 == null || w2 == null) | |
866 | log.warn("Through route relation", relation.toBrowseURL(), "should reference 2 ways that meet at the junction node"); | |
867 | ||
868 | if(coordNode != null && w1 != null && w2 != null) | |
869 | collector.addThroughRoute(coordNode.getId(), w1.getId(), w2.getId()); | |
870 | } | |
871 | } | |
872 | // return memory to GC | |
873 | 827 | nodeIdMap = null; |
874 | throughRouteRelations.clear(); | |
875 | 828 | restrictions.clear(); |
876 | ||
877 | 829 | } |
878 | 830 | |
879 | 831 | /** |
1115 | 1067 | for (long id : rr.getWayIds()) |
1116 | 1068 | wayRelMap.add(id, rr); |
1117 | 1069 | } |
1118 | } | |
1119 | else if("through_route".equals(relation.getTag("type"))) { | |
1120 | throughRouteRelations.add(relation); | |
1121 | 1070 | } else if (addBoundaryNodesAtAdminBoundaries) { |
1122 | 1071 | if (relation instanceof MultiPolygonRelation || "boundary".equals(relation.getTag("type"))) { |
1123 | 1072 | if (isNod3Border(relation)) { |
1419 | 1368 | String roadClass = node.getTag("mkgmap:road-class"); |
1420 | 1369 | String roadSpeed = node.getTag("mkgmap:road-speed"); |
1421 | 1370 | if(roadClass != null || roadSpeed != null) { |
1422 | // find good split point after POI | |
1423 | Coord splitPoint; | |
1424 | double segmentLength = 0; | |
1425 | int splitPos = i+1; | |
1426 | while( splitPos+1 < points.size()){ | |
1427 | splitPoint = points.get(splitPos); | |
1428 | segmentLength += splitPoint.distance(points.get(splitPos - 1)); | |
1429 | if (splitPoint.getHighwayCount() > 1 | |
1430 | || segmentLength > stubSegmentLength - 5) | |
1431 | break; | |
1432 | splitPos++; | |
1433 | } | |
1434 | if (segmentLength > stubSegmentLength + 10){ | |
1435 | // insert a new point after the POI to | |
1436 | // make a short stub segment | |
1437 | splitPoint = points.get(splitPos); | |
1438 | Coord prev = points.get(splitPos-1); | |
1439 | double dist = splitPoint.distance(prev); | |
1440 | double neededLength = stubSegmentLength - (segmentLength - dist); | |
1441 | ||
1442 | splitPoint = prev.makeBetweenPoint(splitPoint, neededLength / dist); | |
1443 | double newDist = splitPoint.distance(prev); | |
1444 | segmentLength += newDist - dist; | |
1445 | splitPoint.incHighwayCount(); | |
1446 | points.add(splitPos, splitPoint); | |
1447 | } | |
1448 | if((splitPos + 1) < points.size() && way.isViaWay() == false && | |
1449 | safeToSplitWay(points, splitPos, i, points.size() - 1)) { | |
1450 | Way tail = splitWayAt(way, splitPos); | |
1451 | // recursively process tail of way | |
1452 | addRoad(new ConvertedWay(cw, tail)); | |
1371 | if (!way.isViaWay()) { | |
1372 | // find good split point after POI | |
1373 | Coord splitPoint; | |
1374 | double segmentLength = 0; | |
1375 | int splitPos = i + 1; | |
1376 | while (splitPos + 1 < points.size()) { | |
1377 | splitPoint = points.get(splitPos); | |
1378 | segmentLength += splitPoint.distance(points.get(splitPos - 1)); | |
1379 | if (splitPoint.getHighwayCount() > 1 || segmentLength > stubSegmentLength - 5) | |
1380 | break; | |
1381 | splitPos++; | |
1382 | } | |
1383 | if (segmentLength > stubSegmentLength + 10) { | |
1384 | // insert a new point after the POI to | |
1385 | // make a short stub segment | |
1386 | splitPoint = points.get(splitPos); | |
1387 | Coord prev = points.get(splitPos - 1); | |
1388 | double dist = splitPoint.distance(prev); | |
1389 | double neededLength = stubSegmentLength - (segmentLength - dist); | |
1390 | ||
1391 | splitPoint = prev.makeBetweenPoint(splitPoint, neededLength / dist); | |
1392 | double newDist = splitPoint.distance(prev); | |
1393 | segmentLength += newDist - dist; | |
1394 | splitPoint.incHighwayCount(); | |
1395 | points.add(splitPos, splitPoint); | |
1396 | } | |
1397 | if ((splitPos + 1) < points.size() | |
1398 | && safeToSplitWay(points, splitPos, i, points.size() - 1)) { | |
1399 | Way tail = splitWayAt(way, splitPos); | |
1400 | // recursively process tail of way | |
1401 | addRoad(new ConvertedWay(cw, tail)); | |
1402 | } | |
1453 | 1403 | } |
1454 | 1404 | boolean classChanged = cw.recalcRoadClass(node); |
1455 | 1405 | if (classChanged && log.isInfoEnabled()){ |
1467 | 1417 | // and the next point modifies the way's speed/class, |
1468 | 1418 | // split the way at this point to limit the size of |
1469 | 1419 | // the affected region |
1470 | if (i + 1 < points.size() | |
1420 | if (!way.isViaWay() && i + 1 < points.size() | |
1471 | 1421 | && points.get(i + 1) instanceof CoordPOI) { |
1472 | 1422 | CoordPOI cp = (CoordPOI) points.get(i + 1); |
1473 | 1423 | Node node = cp.getNode(); |
1554 | 1504 | private void addRoadAfterSplittingLoops(ConvertedWay cw) { |
1555 | 1505 | Way way = cw.getWay(); |
1556 | 1506 | // make sure the way has nodes at each end |
1557 | way.getPoints().get(0).incHighwayCount(); | |
1558 | way.getPoints().get(way.getPoints().size() - 1).incHighwayCount(); | |
1507 | way.getFirstPoint().incHighwayCount(); | |
1508 | way.getLastPoint().incHighwayCount(); | |
1559 | 1509 | |
1560 | 1510 | // check if the way is a loop or intersects with itself |
1561 | 1511 | |
1951 | 1901 | * @return true if fixme flag was found |
1952 | 1902 | */ |
1953 | 1903 | private static boolean checkFixmeCoords(Way way) { |
1954 | if (way.getPoints().get(0).isFixme()) | |
1955 | return true; | |
1956 | if (way.getPoints().get(way.getPoints().size()-1).isFixme()) | |
1957 | return true; | |
1958 | return false; | |
1904 | return way.getFirstPoint().isFixme() || way.getLastPoint().isFixme(); | |
1959 | 1905 | } |
1960 | 1906 | |
1961 | 1907 | /** |
1965 | 1911 | * @param index the split position. |
1966 | 1912 | * @return the trailing part of the way |
1967 | 1913 | */ |
1968 | private static Way splitWayAt(Way way, int index) { | |
1914 | private Way splitWayAt(Way way, int index) { | |
1969 | 1915 | if (way.isViaWay()){ |
1970 | log.warn("via way of restriction is split, restriction will be ignored",way); | |
1916 | removeRestrictionsWithWay(Level.WARNING, way, "is split, restriction will be ignored"); | |
1971 | 1917 | } |
1972 | 1918 | Way trailingWay = new Way(way.getId()); |
1973 | 1919 | List<Coord> wayPoints = way.getPoints(); |
1486 | 1486 | if (way.equals(lastWay)) |
1487 | 1487 | continue; |
1488 | 1488 | lastWay = way; |
1489 | List<Coord> points = way.getPoints(); | |
1490 | points.get(0).setEndOfWay(true); | |
1491 | points.get(points.size()-1).setEndOfWay(true); | |
1489 | way.getFirstPoint().setEndOfWay(true); | |
1490 | way.getLastPoint().setEndOfWay(true); | |
1492 | 1491 | } |
1493 | 1492 | } |
1494 | 1493 |
556 | 556 | List<HousenumberMatch> testOrder = new ArrayList<>(); |
557 | 557 | testOrder.add(house1); |
558 | 558 | testOrder.add(house2); |
559 | Collections.sort(testOrder, new HousenumberMatchByPosComparator()); | |
559 | testOrder.sort(new HousenumberMatchByPosComparator()); | |
560 | 560 | if (testOrder.get(0) != house1){ |
561 | 561 | log.info("order indicates random case or missing road!",this); |
562 | 562 | housenumberRoad.setRandom(true); |
1053 | 1053 | HousenumberGenerator.findClosestRoadSegment(house, getRoad(), startInRoad, endInRoad); |
1054 | 1054 | } |
1055 | 1055 | if (houses.size() > 1) |
1056 | Collections.sort(houses, new HousenumberMatchByPosComparator()); | |
1056 | houses.sort(new HousenumberMatchByPosComparator()); | |
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | |
1456 | 1456 | from.housenumberRoad.getHouses().remove(bestMoveOrig); |
1457 | 1457 | fromHouses.remove(bestMoveOrig); |
1458 | 1458 | toHouses.add(bestMoveOrig); |
1459 | Collections.sort(toHouses, new HousenumberMatchByPosComparator()); | |
1459 | toHouses.sort(new HousenumberMatchByPosComparator()); | |
1460 | 1460 | en1.reset(); |
1461 | 1461 | en2.reset(); |
1462 | 1462 | en1.setNumbers(houses1, en1.startInRoad, en1.endInRoad, left1); |
825 | 825 | for (Entry<CityInfo, MultiHashMap<String, HousenumberMatch>> topEntry : cityPlaceHouseMap.entrySet()){ |
826 | 826 | CityInfo cityInfo = topEntry.getKey(); |
827 | 827 | List<String> placeNames = new ArrayList<>(topEntry.getValue().keySet()); |
828 | Collections.sort(placeNames); | |
828 | placeNames.sort(null); | |
829 | 829 | for (String placeName : placeNames){ |
830 | 830 | List<HousenumberMatch> placeHouses = topEntry.getValue().get(placeName); |
831 | 831 | HashSet<HousenumberRoad> roads = new LinkedHashSet<>(); |
1232 | 1232 | List<HousenumberRoad> roadsInCluster) { |
1233 | 1233 | if (houses.isEmpty()) |
1234 | 1234 | return; |
1235 | Collections.sort(houses, new HousenumberMatchByNumComparator()); | |
1235 | houses.sort(new HousenumberMatchByNumComparator()); | |
1236 | 1236 | |
1237 | 1237 | HousenumberMatch prev = null; |
1238 | 1238 | for (HousenumberMatch house : houses) { |
1267 | 1267 | // multiple roads, we assume that the closest is the best |
1268 | 1268 | // but we may have to check the alternatives as well |
1269 | 1269 | |
1270 | Collections.sort(matches, new HousenumberGenerator.HousenumberMatchByDistComparator()); | |
1270 | matches.sort(new HousenumberGenerator.HousenumberMatchByDistComparator()); | |
1271 | 1271 | closest = matches.get(0); |
1272 | 1272 | best = checkAngle(closest, matches); |
1273 | 1273 | } |
1306 | 1306 | |
1307 | 1307 | private static void markSimpleDuplicates(String streetName, List<HousenumberMatch> housesNearCluster) { |
1308 | 1308 | List<HousenumberMatch> sortedHouses = new ArrayList<>(housesNearCluster); |
1309 | Collections.sort(sortedHouses, new HousenumberMatchByNumComparator()); | |
1309 | sortedHouses.sort(new HousenumberMatchByNumComparator()); | |
1310 | 1310 | int n = sortedHouses.size(); |
1311 | 1311 | for (int i = 1; i < n; i++){ |
1312 | 1312 | HousenumberMatch house1 = sortedHouses.get(i-1); |
1472 | 1472 | if (o1 == o2) { |
1473 | 1473 | return 0; |
1474 | 1474 | } |
1475 | if (o1.getRoad() == null || o2.getRoad() == null){ | |
1476 | log.error("road is null in sort comparator",o1,o2); | |
1477 | throw new MapFailedException("internal error in housenumber processing"); | |
1475 | if (o1.getRoad() == null || o2.getRoad() == null) { | |
1476 | log.error("road is null in sort comparator", o1, o2); | |
1477 | throw new MapFailedException("internal error in housenumber processing"); | |
1478 | 1478 | } |
1479 | 1479 | if (o1.getRoad() != o2.getRoad()) { |
1480 | 1480 | // should not happen |
1527 | 1527 | } |
1528 | 1528 | } |
1529 | 1529 | /** |
1530 | * Sorts house numbers by distance. If eqaul, compare segment and road to produce | |
1530 | * Sorts house numbers by distance. If equal, compare segment and road to produce | |
1531 | 1531 | * predictable results. |
1532 | 1532 | * @author Gerd Petermann |
1533 | 1533 | */ |
1779 | 1779 | } |
1780 | 1780 | |
1781 | 1781 | public List<RoadPoint> getCLoseRoadPoints(HousenumberElem house){ |
1782 | Set<RoadPoint> closeRoadPoints = kdTree.findNextPoint(house, kdSearchRange); | |
1782 | Set<RoadPoint> closeRoadPoints = kdTree.findClosePoints(house, kdSearchRange); | |
1783 | 1783 | List<RoadPoint> result = new ArrayList<>(); |
1784 | 1784 | for (RoadPoint rp : closeRoadPoints){ |
1785 | 1785 | int id = rp.p.getId(); |
1801 | 1801 | List<RoadPoint> closeRoadPoints = getCLoseRoadPoints(house); |
1802 | 1802 | if (closeRoadPoints.isEmpty()) |
1803 | 1803 | return closest; |
1804 | Collections.sort(closeRoadPoints, new Comparator<RoadPoint>() { | |
1805 | // sort by distance (smallest first) | |
1806 | public int compare(RoadPoint o1, RoadPoint o2) { | |
1804 | closeRoadPoints.sort((o1,o2)-> { | |
1807 | 1805 | if (o1 == o2) |
1808 | 1806 | return 0; |
1809 | 1807 | int d = Integer.compare(o1.r.getRoadId(), o2.r.getRoadId()); |
1814 | 1812 | return d; |
1815 | 1813 | return Integer.compare(o1.partOfSeg, o2.partOfSeg); |
1816 | 1814 | } |
1817 | }); | |
1815 | ); | |
1818 | 1816 | |
1819 | 1817 | List<HousenumberMatch> matches = new ArrayList<>(40); |
1820 | 1818 | BitSet testedSegments = new BitSet(); |
1855 | 1853 | if (matches.isEmpty()) |
1856 | 1854 | return closest; // closest has not yet a road |
1857 | 1855 | |
1858 | Collections.sort(matches, new HousenumberGenerator.HousenumberMatchByDistComparator()); | |
1856 | matches.sort(new HousenumberGenerator.HousenumberMatchByDistComparator()); | |
1859 | 1857 | closest = matches.get(0); |
1860 | 1858 | closest = checkAngle(closest, matches); |
1861 | 1859 | closest.calcRoadSide(); |
76 | 76 | } |
77 | 77 | |
78 | 78 | public void buildIntervals() { |
79 | Collections.sort(houseNumbers, new HousenumberMatchByNumComparator()); | |
79 | houseNumbers.sort(new HousenumberMatchByNumComparator()); | |
80 | 80 | if (log.isInfoEnabled()) |
81 | 81 | log.info("Initial housenumbers for",road,"in",road.getCity(),houseNumbers); |
82 | 82 | |
101 | 101 | } |
102 | 102 | } |
103 | 103 | detectGroups(leftNumbers, rightNumbers); |
104 | Collections.sort(leftNumbers, new HousenumberMatchByPosComparator()); | |
105 | Collections.sort(rightNumbers, new HousenumberMatchByPosComparator()); | |
104 | leftNumbers.sort(new HousenumberMatchByPosComparator()); | |
105 | rightNumbers.sort(new HousenumberMatchByPosComparator()); | |
106 | 106 | |
107 | 107 | |
108 | 108 | int currNodePos = 0; |
306 | 306 | return "http://www.openstreetmap.org/" + kind() + "/" + id; |
307 | 307 | } |
308 | 308 | |
309 | /** | |
310 | * Create a copy of the element. | |
311 | * @return | |
312 | */ | |
309 | 313 | public Element copy() { |
310 | 314 | // Can be implemented in subclasses |
311 | 315 | throw new UnsupportedOperationException("unsupported element copy"); |
12 | 12 | package uk.me.parabola.mkgmap.reader.osm; |
13 | 13 | |
14 | 14 | import java.util.AbstractMap; |
15 | import java.util.ArrayList; | |
16 | 15 | import java.util.HashMap; |
16 | import java.util.Iterator; | |
17 | 17 | import java.util.LinkedHashMap; |
18 | import java.util.Iterator; | |
19 | 18 | import java.util.List; |
20 | 19 | import java.util.Map; |
20 | ||
21 | 21 | import uk.me.parabola.imgfmt.Utils; |
22 | 22 | import uk.me.parabola.imgfmt.app.Area; |
23 | 23 | import uk.me.parabola.imgfmt.app.Coord; |
24 | 24 | import uk.me.parabola.log.Logger; |
25 | 25 | import uk.me.parabola.mkgmap.general.LineClipper; |
26 | 26 | import uk.me.parabola.util.EnhancedProperties; |
27 | import uk.me.parabola.util.MultiHashMap; | |
27 | 28 | |
28 | 29 | /** |
29 | 30 | * This is where we save the elements read from any of the file formats that |
45 | 46 | public class ElementSaver { |
46 | 47 | private static final Logger log = Logger.getLogger(ElementSaver.class); |
47 | 48 | |
48 | protected OSMId2ObjectMap<Coord> coordMap = new OSMId2ObjectMap<Coord>(); | |
49 | protected OSMId2ObjectMap<Coord> coordMap = new OSMId2ObjectMap<>(); | |
49 | 50 | |
50 | 51 | protected Map<Long, Node> nodeMap; |
51 | 52 | protected Map<Long, Way> wayMap; |
52 | 53 | protected Map<Long, Relation> relationMap; |
53 | 54 | |
54 | protected final Map<Long, List<Map.Entry<String,Relation>>> deferredRelationMap = new HashMap<Long, List<Map.Entry<String,Relation>>>(); | |
55 | protected final MultiHashMap<Long, Map.Entry<String, Relation>> deferredRelationMap = new MultiHashMap<>(); | |
55 | 56 | |
56 | 57 | // This is an explicitly given bounding box from the input file command line etc. |
57 | 58 | private Area boundingBox; |
70 | 71 | |
71 | 72 | public ElementSaver(EnhancedProperties args) { |
72 | 73 | if (args.getProperty("preserve-element-order", false)) { |
73 | nodeMap = new LinkedHashMap<Long, Node>(5000); | |
74 | wayMap = new LinkedHashMap<Long, Way>(5000); | |
75 | relationMap = new LinkedHashMap<Long, Relation>(); | |
74 | nodeMap = new LinkedHashMap<>(5000); | |
75 | wayMap = new LinkedHashMap<>(5000); | |
76 | relationMap = new LinkedHashMap<>(); | |
76 | 77 | } else { |
77 | nodeMap = new HashMap<Long, Node>(); | |
78 | wayMap = new HashMap<Long, Way>(); | |
79 | relationMap = new HashMap<Long, Relation>(); | |
80 | } | |
81 | ||
82 | ignoreTurnRestrictions = args.getProperty("ignore-turn-restrictions", false); | |
78 | nodeMap = new HashMap<>(); | |
79 | wayMap = new HashMap<>(); | |
80 | relationMap = new HashMap<>(); | |
81 | } | |
82 | ||
83 | ignoreTurnRestrictions = args.getProperty("ignore-turn-restrictions", false) || !args.containsKey("route"); | |
83 | 84 | } |
84 | 85 | |
85 | 86 | /** |
139 | 140 | public void addRelation(Relation rel) { |
140 | 141 | String type = rel.getTag("type"); |
141 | 142 | if (type == null) { |
143 | // maybe set rel to null? | |
142 | 144 | } else if ("multipolygon".equals(type) || "boundary".equals(type)) { |
143 | 145 | rel = createMultiPolyRelation(rel); |
144 | 146 | } else if("restriction".equals(type) || type.startsWith("restriction:")) { |
145 | 147 | if (ignoreTurnRestrictions) |
146 | 148 | rel = null; |
147 | else if (rel.getTag("restriction") == null && rel.getTagsWithPrefix("restriction:", false).isEmpty()) | |
149 | else if (rel.getTag("restriction") == null && rel.getTagsWithPrefix("restriction:", false).isEmpty()) { | |
148 | 150 | log.warn("ignoring unspecified/unsupported restriction " + rel.toBrowseURL()); |
149 | else | |
151 | } else { | |
150 | 152 | rel = new RestrictionRelation(rel); |
153 | } | |
151 | 154 | } |
152 | 155 | |
153 | 156 | if(rel != null) { |
156 | 159 | |
157 | 160 | rel.processElements(); |
158 | 161 | |
159 | List<Map.Entry<String,Relation>> entries = deferredRelationMap.remove(id); | |
160 | if (entries != null) | |
161 | for (Map.Entry<String,Relation> entry : entries) | |
162 | List<Map.Entry<String, Relation>> entries = deferredRelationMap.remove(id); | |
163 | if (entries != null) { | |
164 | for (Map.Entry<String, Relation> entry : entries) { | |
162 | 165 | entry.getValue().addElement(entry.getKey(), rel); |
166 | } | |
167 | } | |
163 | 168 | } |
164 | 169 | } |
165 | 170 | |
273 | 278 | // insert boundary point before the second point |
274 | 279 | points.add(i, clippedPair[1]); |
275 | 280 | ++numBoundaryNodesAdded; |
276 | } else if(clippedPair[1].getOnBoundary()) | |
281 | } else if (clippedPair[1].getOnBoundary()) { | |
277 | 282 | ++numBoundaryNodesDetected; |
278 | ||
283 | } | |
279 | 284 | |
280 | 285 | if (clippedPair[0] != points.get(i - 1)) { |
281 | 286 | // the first point in the segment is outside |
284 | 289 | // insert boundary point after the first point |
285 | 290 | points.add(i, clippedPair[0]); |
286 | 291 | ++numBoundaryNodesAdded; |
287 | } else if (clippedPair[0].getOnBoundary()) | |
292 | } else if (clippedPair[0].getOnBoundary()) { | |
288 | 293 | ++numBoundaryNodesDetected; |
294 | } | |
289 | 295 | } |
290 | 296 | } |
291 | 297 | } |
335 | 341 | } |
336 | 342 | } |
337 | 343 | |
338 | public void deferRelation(long id, Relation rel, String role) { | |
339 | // The relation may be defined later in the input. | |
340 | // Defer the lookup. | |
341 | Map.Entry<String,Relation> entry = | |
342 | new AbstractMap.SimpleEntry<String,Relation>(role, rel); | |
343 | ||
344 | List<Map.Entry<String,Relation>> entries = deferredRelationMap.get(id); | |
345 | if (entries == null) { | |
346 | entries = new ArrayList<Map.Entry<String,Relation>>(); | |
347 | deferredRelationMap.put(id, entries); | |
348 | } | |
349 | ||
350 | entries.add(entry); | |
344 | /** | |
345 | * Handle the case that a relation refers to another relation which was not yet found in the input. | |
346 | * The relation may be defined later in the input. Defer the lookup. | |
347 | * @param id the id of the not yet known relation | |
348 | * @param parentRel the parent relation | |
349 | * @param role the role of the not yet known relation in the parent relation | |
350 | */ | |
351 | public void deferRelation(long id, Relation parentRel, String role) { | |
352 | deferredRelationMap.add(id, new AbstractMap.SimpleEntry<>(role, parentRel)); | |
351 | 353 | } |
352 | 354 | } |
224 | 224 | if (wayRestrictions.isEmpty()) { |
225 | 225 | return; |
226 | 226 | } |
227 | if (oldWay.isViaWay()) | |
228 | newWay.setViaWay(true); | |
227 | if (oldWay.isViaWay()) { | |
228 | log.error("internal error: via way is split in", this.getClass().getSimpleName()); | |
229 | } | |
229 | 230 | // create a copy because original list may be modified within the loop |
230 | 231 | for (RestrictionRelation rr : new ArrayList<>(wayRestrictions)) { |
231 | Coord lastPointNewWay = newWay.getPoints().get(0); | |
232 | Coord lastPointNewWay = newWay.getFirstPoint(); | |
232 | 233 | List<Coord> viaCoords = rr.getViaCoords(); |
233 | 234 | for (Coord via : viaCoords){ |
234 | 235 | if (via == lastPointNewWay) { |
296 | 297 | |
297 | 298 | double startSegmentLength = 0; |
298 | 299 | |
299 | Coord lastC = w.getPoints().get(0); | |
300 | Coord lastC = w.getFirstPoint(); | |
300 | 301 | for (int i = 1; i < w.getPoints().size(); i++) { |
301 | 302 | Coord c = w.getPoints().get(i); |
302 | 303 | double segmentLength = lastC.distance(c); |
461 | 462 | log.debug("Check way",linkWay.getId(),linkWay.toTagString()); |
462 | 463 | |
463 | 464 | // Retrieve all adjacent ways of the current link |
464 | Coord c = linkWay.getPoints().get(linkWay.getPoints().size()-1); | |
465 | Coord c = linkWay.getLastPoint(); | |
465 | 466 | if (isOnewayOppositeDirection(linkWay)) { |
466 | c = linkWay.getPoints().get(0); | |
467 | c = linkWay.getFirstPoint(); | |
467 | 468 | } |
468 | 469 | |
469 | 470 | Set<Way> nextWays = adjacentWays.get(c); |
476 | 477 | |
477 | 478 | // remove the way from destination handling only if both ways are connected with start/end points |
478 | 479 | // otherwise it is a crossroads and therefore both ways need to be handled |
479 | boolean startEndConnection = connectedWay.getPoints().isEmpty()==false && connectedWay.getPoints().get(0).equals(c); | |
480 | boolean startEndConnection = connectedWay.getPoints().isEmpty()==false && connectedWay.getFirstPoint().equals(c); | |
480 | 481 | if (startEndConnection && connectedWay.equals(linkWay) == false |
481 | 482 | && connectedWay.getTag("highway").endsWith("_link") |
482 | 483 | && destination.equals(nextDest)) { |
181 | 181 | int middle = way.getPoints().size() / 2; |
182 | 182 | Coord midPoint; |
183 | 183 | if (way.getPoints().size() == 2) { |
184 | midPoint = way.getPoints().get(0).makeBetweenPoint(way.getPoints().get(1), 0.5); | |
184 | midPoint = way.getFirstPoint().makeBetweenPoint(way.getLastPoint(), 0.5); | |
185 | 185 | } else { |
186 | 186 | midPoint = way.getPoints().get(middle); |
187 | 187 | } |
188 | 188 | tags = search(midPoint); |
189 | 189 | if (tags == null){ |
190 | 190 | // try 1st point next |
191 | tags = search(way.getPoints().get(0)); | |
191 | tags = search(way.getFirstPoint()); | |
192 | 192 | } |
193 | 193 | if (tags == null){ |
194 | 194 | // try last point next |
195 | tags = search(way.getPoints().get(way.getPoints().size()-1)); | |
195 | tags = search(way.getLastPoint()); | |
196 | 196 | } |
197 | 197 | if (tags == null){ |
198 | 198 | // still not found, try rest |
199 | 199 | for (int i = 1; i < way.getPoints().size()-1; i++){ |
200 | if (i == middle) | |
201 | continue; | |
202 | tags = search(way.getPoints().get(i)); | |
203 | if (tags != null) | |
204 | break; | |
200 | if (i != middle) { | |
201 | tags = search(way.getPoints().get(i)); | |
202 | if (tags != null) | |
203 | break; | |
204 | } | |
205 | 205 | } |
206 | 206 | } |
207 | 207 | if (tags == null) |
292 | 292 | CutPoint edgeCutPoint = new CutPoint(axis, outerBounds); |
293 | 293 | |
294 | 294 | // go through the inner polygon list and use all polygons that intersect the outer polygons bbox at the start |
295 | Collections.sort(innerStart, (axis == CoordinateAxis.LONGITUDE ? COMP_LONG_START: COMP_LAT_START)); | |
295 | innerStart.sort(axis == CoordinateAxis.LONGITUDE ? COMP_LONG_START: COMP_LAT_START); | |
296 | 296 | for (Area anInnerStart : innerStart) { |
297 | 297 | if (axis.getStartHighPrec(anInnerStart) <= axis.getStartHighPrec(outerBounds)) { |
298 | 298 | // found a touching area |
306 | 306 | return edgeCutPoint; |
307 | 307 | } |
308 | 308 | |
309 | Collections.sort(innerStart, (axis == CoordinateAxis.LONGITUDE ? COMP_LONG_STOP: COMP_LAT_STOP)); | |
309 | innerStart.sort(axis == CoordinateAxis.LONGITUDE ? COMP_LONG_STOP: COMP_LAT_STOP); | |
310 | 310 | // go through the inner polygon list and use all polygons that intersect the outer polygons bbox at the stop |
311 | 311 | for (Area anInnerStart : innerStart) { |
312 | 312 | if (axis.getStopHighPrec(anInnerStart) >= axis.getStopHighPrec(outerBounds)) { |
328 | 328 | CutPoint bestCutPoint = new CutPoint(axis, outerBounds); |
329 | 329 | CutPoint currentCutPoint = new CutPoint(axis, outerBounds); |
330 | 330 | |
331 | Collections.sort(innerStart, (axis == CoordinateAxis.LONGITUDE ? COMP_LONG_START: COMP_LAT_START)); | |
331 | innerStart.sort(axis == CoordinateAxis.LONGITUDE ? COMP_LONG_START: COMP_LAT_START); | |
332 | 332 | |
333 | 333 | for (Area anInnerStart : innerStart) { |
334 | 334 | currentCutPoint.addArea(anInnerStart); |
550 | 550 | } |
551 | 551 | |
552 | 552 | areas.add(area); |
553 | Collections.sort(areas, comparator); | |
553 | areas.sort(comparator); | |
554 | 554 | startPoinHp = axis.getStartHighPrec(Collections.max(areas, |
555 | 555 | (axis == CoordinateAxis.LONGITUDE ? COMP_LONG_START |
556 | 556 | : COMP_LAT_START))); |
185 | 185 | boolean joinable = false; |
186 | 186 | |
187 | 187 | // use == or equals as comparator?? |
188 | if (joinWay.getPoints().get(0) == tempWay.getPoints().get(0)) { | |
188 | if (joinWay.getFirstPoint() == tempWay.getFirstPoint()) { | |
189 | 189 | insIdx = 0; |
190 | 190 | reverseTempWay = true; |
191 | 191 | firstTmpIdx = 1; |
192 | 192 | joinable = true; |
193 | } else if (joinWay.getPoints().get(joinWay.getPoints().size() - 1) == tempWay | |
194 | .getPoints().get(0)) { | |
193 | } else if (joinWay.getLastPoint() == tempWay.getFirstPoint()) { | |
195 | 194 | insIdx = joinWay.getPoints().size(); |
196 | 195 | reverseTempWay = false; |
197 | 196 | firstTmpIdx = 1; |
198 | 197 | joinable = true; |
199 | } else if (joinWay.getPoints().get(0) == tempWay.getPoints().get( | |
200 | tempWay.getPoints().size() - 1)) { | |
198 | } else if (joinWay.getFirstPoint() == tempWay.getLastPoint()) { | |
201 | 199 | insIdx = 0; |
202 | 200 | reverseTempWay = false; |
203 | 201 | firstTmpIdx = 0; |
204 | 202 | joinable = true; |
205 | } else if (joinWay.getPoints().get(joinWay.getPoints().size() - 1) == tempWay | |
206 | .getPoints().get(tempWay.getPoints().size() - 1)) { | |
203 | } else if (joinWay.getLastPoint() == tempWay.getLastPoint()) { | |
207 | 204 | insIdx = joinWay.getPoints().size(); |
208 | 205 | reverseTempWay = true; |
209 | 206 | firstTmpIdx = 0; |
383 | 380 | if (way.hasIdenticalEndPoints() || way.getPoints().size() < 3) { |
384 | 381 | continue; |
385 | 382 | } |
386 | Coord p1 = way.getPoints().get(0); | |
387 | Coord p2 = way.getPoints().get(way.getPoints().size() - 1); | |
383 | Coord p1 = way.getFirstPoint(); | |
384 | Coord p2 = way.getLastPoint(); | |
388 | 385 | |
389 | 386 | if (tileBounds.insideBoundary(p1) == false |
390 | 387 | && tileBounds.insideBoundary(p2) == false) { |
437 | 434 | boolean doClose = true; |
438 | 435 | if (maxCloseDist > 0) { |
439 | 436 | // calc the distance to close |
440 | double closeDist = way.getPoints().get(0).distance(way.getPoints().get(way.getPoints().size()-1)); | |
437 | double closeDist = way.getFirstPoint().distance(way.getLastPoint()); | |
441 | 438 | doClose = closeDist < maxCloseDist; |
442 | 439 | } |
443 | 440 | if (doClose) { |
444 | log.info("Closing way", way); | |
445 | log.info("from", way.getPoints().get(0).toOSMURL()); | |
446 | log.info("to", way.getPoints().get(way.getPoints().size() - 1) | |
447 | .toOSMURL()); | |
441 | if (log.isInfoEnabled()) { | |
442 | log.info("Closing way", way); | |
443 | log.info("from", way.getFirstPoint().toOSMURL()); | |
444 | log.info("to", way.getLastPoint().toOSMURL()); | |
445 | } | |
448 | 446 | // mark this ways as artificially closed |
449 | 447 | way.closeWayArtificially(); |
450 | 448 | } |
482 | 480 | |
483 | 481 | // check all ways for endpoints outside or on the bbox |
484 | 482 | for (JoinedWay w : unclosed) { |
485 | Coord c1 = w.getPoints().get(0); | |
486 | Coord c2 = w.getPoints().get(w.getPoints().size()-1); | |
483 | Coord c1 = w.getFirstPoint(); | |
484 | Coord c2 = w.getLastPoint(); | |
487 | 485 | if (tileBounds.insideBoundary(c1)==false) { |
488 | 486 | log.debug("Point",c1,"of way",w.getId(),"outside bbox"); |
489 | 487 | outOfBboxPoints.put(c1, w); |
548 | 546 | } else { |
549 | 547 | // retrieve the connection with the minimum distance |
550 | 548 | ConnectionData minCon = Collections.min(coordPairs, |
551 | new Comparator<ConnectionData>() { | |
552 | public int compare(ConnectionData o1, | |
553 | ConnectionData o2) { | |
554 | return Double.compare(o1.distance, o2.distance); | |
555 | } | |
556 | }); | |
549 | (o1, o2) -> Double.compare(o1.distance, o2.distance)); | |
557 | 550 | |
558 | 551 | if (minCon.w1 == minCon.w2) { |
559 | 552 | log.debug("Close a gap in way",minCon.w1); |
563 | 556 | } else { |
564 | 557 | log.debug("Connect", minCon.w1, "with", minCon.w2); |
565 | 558 | |
566 | if (minCon.w1.getPoints().get(0) == minCon.c1) { | |
559 | if (minCon.w1.getFirstPoint() == minCon.c1) { | |
567 | 560 | Collections.reverse(minCon.w1.getPoints()); |
568 | 561 | } |
569 | if (minCon.w2.getPoints().get(0) != minCon.c2) { | |
562 | if (minCon.w2.getFirstPoint() != minCon.c2) { | |
570 | 563 | Collections.reverse(minCon.w2.getPoints()); |
571 | 564 | } |
572 | 565 | |
727 | 720 | // sort by role and then by number of points, this improves performance |
728 | 721 | // in the routines which add the polygons to areas |
729 | 722 | if (polygonStatusList.size() > 2){ |
730 | Collections.sort(polygonStatusList, new Comparator<PolygonStatus>() { | |
731 | public int compare(PolygonStatus o1, PolygonStatus o2) { | |
732 | if (o1.outer != o2.outer) | |
733 | return (o1.outer) ? -1 : 1; | |
734 | return o1.polygon.getPoints().size() - o2.polygon.getPoints().size(); | |
735 | } | |
723 | polygonStatusList.sort((o1, o2) -> { | |
724 | if (o1.outer != o2.outer) | |
725 | return (o1.outer) ? -1 : 1; | |
726 | return o1.polygon.getPoints().size() - o2.polygon.getPoints().size(); | |
736 | 727 | }); |
737 | 728 | } |
738 | 729 | return polygonStatusList; |
1845 | 1836 | |
1846 | 1837 | for (Way orgWay : fakeWay.getOriginalWays()) { |
1847 | 1838 | log.log(logLevel, " Way",orgWay.getId(),"is composed of other artificial ways. Details:"); |
1848 | log.log(logLevel, " Start:",orgWay.getPoints().get(0).toOSMURL()); | |
1839 | log.log(logLevel, " Start:",orgWay.getFirstPoint().toOSMURL()); | |
1849 | 1840 | if (orgWay.hasEqualEndPoints()) { |
1850 | 1841 | // the way is closed so start and end are equal - log the point in the middle of the way |
1851 | 1842 | int mid = orgWay.getPoints().size()/2; |
1852 | 1843 | log.log(logLevel, " Mid: ",orgWay.getPoints().get(mid).toOSMURL()); |
1853 | 1844 | } else { |
1854 | log.log(logLevel, " End: ",orgWay.getPoints().get(orgWay.getPoints().size()-1).toOSMURL()); | |
1845 | log.log(logLevel, " End: ",orgWay.getLastPoint().toOSMURL()); | |
1855 | 1846 | } |
1856 | 1847 | } |
1857 | 1848 | } |
2025 | 2016 | addWay(originalWay); |
2026 | 2017 | |
2027 | 2018 | // we have to initialize the min/max values |
2028 | Coord c0 = originalWay.getPoints().get(0); | |
2019 | Coord c0 = originalWay.getFirstPoint(); | |
2029 | 2020 | minLat = maxLat = c0.getLatitude(); |
2030 | 2021 | minLon = maxLon = c0.getLongitude(); |
2031 | 2022 |
286 | 286 | prevC = c; |
287 | 287 | } |
288 | 288 | |
289 | Node startNode = createPOI(line, line.getPoints().get(0), LINE2POI_TAG, sumDist); | |
289 | Node startNode = createPOI(line, line.getFirstPoint(), LINE2POI_TAG, sumDist); | |
290 | 290 | startNode.addTag(LINE2POI_TYPE_TAG,"start"); |
291 | 291 | saver.addNode(startNode); |
292 | 292 | |
293 | Node endNode = createPOI(line, line.getPoints().get(line.getPoints().size()-1), LINE2POI_TAG, sumDist); | |
293 | Node endNode = createPOI(line, line.getLastPoint(), LINE2POI_TAG, sumDist); | |
294 | 294 | endNode.addTag(LINE2POI_TYPE_TAG,"end"); |
295 | 295 | saver.addNode(endNode); |
296 | 296 | |
297 | 297 | int noPOIs = 2; |
298 | Coord lastPoint = line.getPoints().get(0); | |
298 | Coord lastPoint = line.getFirstPoint(); | |
299 | 299 | if (line.getPoints().size() > 2) { |
300 | 300 | for (Coord inPoint : line.getPoints().subList(1, line.getPoints().size()-1)) { |
301 | 301 | if (inPoint.equals(lastPoint)){ |
202 | 202 | if(viaCoord != null) |
203 | 203 | location = viaCoord; |
204 | 204 | else if(!fromWays.isEmpty() && !fromWays.get(0).getPoints().isEmpty()) |
205 | location = fromWays.get(0).getPoints().get(0); | |
205 | location = fromWays.get(0).getFirstPoint(); | |
206 | 206 | else if(!toWays.isEmpty() && !toWays.get(0).getPoints().isEmpty()) |
207 | location = toWays.get(0).getPoints().get(0); | |
207 | location = toWays.get(0).getFirstPoint(); | |
208 | 208 | else if(!viaWays.isEmpty() && !viaWays.get(0).getPoints().isEmpty()) |
209 | location = viaWays.get(0).getPoints().get(0); | |
209 | location = viaWays.get(0).getFirstPoint(); | |
210 | 210 | |
211 | 211 | if(location != null) |
212 | 212 | messagePrefix = "Turn restriction (" + restriction + ") " + browseURL + " (at " + location.toOSMURL() + ")"; |
328 | 328 | log.warn(messagePrefix,"way",way.toBrowseURL(),"has less than 2 points, restriction is ignored"); |
329 | 329 | valid = false; |
330 | 330 | } else { |
331 | if (way.getPoints().get(0) == way.getPoints().get(way.getPoints().size()-1)){ | |
331 | if (way.hasIdenticalEndPoints()){ | |
332 | 332 | if (ways == toWays && dirIndicator != '?') |
333 | 333 | continue; // we try to determine the correct part in RoadNetwork |
334 | 334 | log.warn(messagePrefix, "way", way.toBrowseURL(), "starts and ends at same node, don't know which one to use"); |
351 | 351 | Coord v1 = viaCoord; |
352 | 352 | Coord v2 = viaCoord; |
353 | 353 | if (viaWays.isEmpty() == false){ |
354 | v1 = viaWays.get(0).getPoints().get(0); | |
355 | v2 = viaWays.get(0).getPoints().get(viaWays.get(0).getPoints().size()-1); | |
354 | v1 = viaWays.get(0).getFirstPoint(); | |
355 | v2 = viaWays.get(0).getLastPoint(); | |
356 | 356 | } |
357 | 357 | // check if all from ways are connected at the given via point or with the given via ways |
358 | 358 | for (Way fromWay : fromWays){ |
359 | Coord e1 = fromWay.getPoints().get(0); | |
360 | Coord e2 = fromWay.getPoints().get(fromWay.getPoints().size() - 1); | |
359 | Coord e1 = fromWay.getFirstPoint(); | |
360 | Coord e2 = fromWay.getLastPoint(); | |
361 | 361 | if (e1 == v1 || e2 == v1) |
362 | 362 | viaCoord = v1; |
363 | 363 | else if (e1 == v2 || e2 == v2) |
374 | 374 | for (int i = 0; i < viaWays.size();i++){ |
375 | 375 | Way way = viaWays.get(i); |
376 | 376 | Coord v = viaPoints.get(viaPoints.size()-1); |
377 | if (way.getPoints().get(0) == v) | |
378 | v2 = way.getPoints().get(way.getPoints().size()-1); | |
379 | else if (way.getPoints().get(way.getPoints().size()-1) == v) | |
380 | v2 = way.getPoints().get(0); | |
377 | if (way.getFirstPoint() == v) | |
378 | v2 = way.getLastPoint(); | |
379 | else if (way.getLastPoint() == v) | |
380 | v2 = way.getFirstPoint(); | |
381 | 381 | else { |
382 | 382 | log.warn(messagePrefix, "'via' way", way.toBrowseURL(), "doesn't start or end at",v.toDegreeString()); |
383 | 383 | valid = false; |
403 | 403 | // check if all to ways are connected to via point or last via way |
404 | 404 | Coord lastVia = viaPoints.get(viaPoints.size()-1); |
405 | 405 | for (Way toWay : toWays){ |
406 | Coord e1 = toWay.getPoints().get(0); | |
407 | Coord e2 = toWay.getPoints().get(toWay.getPoints().size() - 1); | |
406 | Coord e1 = toWay.getFirstPoint(); | |
407 | Coord e2 = toWay.getLastPoint(); | |
408 | 408 | if(e1 != lastVia && e2 != lastVia) { |
409 | 409 | log.warn(messagePrefix, "'to' way", toWay.toBrowseURL(), "doesn't start or end at 'via' node or way"); |
410 | 410 | valid = false; |
758 | 758 | if (w.hasIdenticalEndPoints()) { |
759 | 759 | joined.add(w); |
760 | 760 | } else if (w.getPoints() != null && w.getPoints().size() > 1){ |
761 | List<Coord> points = w.getPoints(); | |
762 | beginMap.put(points.get(0), w); | |
761 | beginMap.put(w.getFirstPoint(), w); | |
763 | 762 | } else { |
764 | 763 | log.info("Discard coastline way",w.getId(),"because consists of less than 2 points"); |
765 | 764 | } |
800 | 799 | |
801 | 800 | if (wm.hasIdenticalEndPoints()) { |
802 | 801 | joined.add(wm); |
803 | beginMap.remove(wm.getPoints().get(0)); | |
802 | beginMap.remove(wm.getFirstPoint()); | |
804 | 803 | } |
805 | 804 | break; |
806 | 805 | } |
932 | 931 | assert seaRelation != null; |
933 | 932 | seaRelation.addElement("inner", ai); |
934 | 933 | } |
935 | log.warn("Converting anti-island starting at", ai.getPoints().get(0).toOSMURL() , "into an island as it is surrounded by water"); | |
934 | log.warn("Converting anti-island starting at", ai.getFirstPoint().toOSMURL() , "into an island as it is surrounded by water"); | |
936 | 935 | } |
937 | 936 | } |
938 | 937 | |
951 | 950 | se.getLongitude() + 1)); |
952 | 951 | sea.addPoint(new Coord(ne.getLatitude() - 1, |
953 | 952 | ne.getLongitude() + 1)); |
954 | sea.addPoint(sea.getPoints().get(0)); // close shape | |
953 | sea.addPoint(sea.getFirstPoint()); // close shape | |
955 | 954 | sea.addTag("natural", "sea"); |
956 | 955 | sea.setFullArea(SEA_SIZE); |
957 | 956 | |
1071 | 1070 | log.info("adding:", segment); |
1072 | 1071 | for(Coord p : segment.getPoints()) |
1073 | 1072 | w.addPointIfNotEqualToLastPoint(p); |
1074 | hNext = getEdgeHit(seaBounds, segment.getPoints().get(segment.getPoints().size()-1)); | |
1073 | hNext = getEdgeHit(seaBounds, segment.getLastPoint()); | |
1075 | 1074 | } else { |
1076 | 1075 | w.addPointIfNotEqualToLastPoint(hit.getPoint(seaBounds)); |
1077 | 1076 | hNext = hits.higher(hit); |
1109 | 1108 | } while (!hits.isEmpty() && !hit.equals(hFirst)); |
1110 | 1109 | |
1111 | 1110 | if (!w.hasIdenticalEndPoints()) |
1112 | w.addPoint(w.getPoints().get(0)); // close shape | |
1111 | w.addPoint(w.getFirstPoint()); // close shape | |
1113 | 1112 | log.info("adding non-island landmass, hits.size()=" + hits.size()); |
1114 | 1113 | islands.add(w); |
1115 | 1114 | shorelineReachesBoundary = true; |
1415 | 1414 | if(w1.hasIdenticalEndPoints()) |
1416 | 1415 | continue; |
1417 | 1416 | List<Coord> points1 = w1.getPoints(); |
1418 | Coord w1e = points1.get(points1.size() - 1); | |
1417 | Coord w1e = w1.getLastPoint(); | |
1419 | 1418 | if(bounds.onBoundary(w1e)) |
1420 | 1419 | continue; |
1421 | 1420 | Way nearest = null; |
49 | 49 | private boolean isViaWay; |
50 | 50 | |
51 | 51 | public Way(long id) { |
52 | points = new ArrayList<Coord>(5); | |
52 | points = new ArrayList<>(5); | |
53 | 53 | setId(id); |
54 | 54 | } |
55 | 55 | |
56 | 56 | public Way(long id, List<Coord> points) { |
57 | this.points = new ArrayList<Coord>(points); | |
57 | this.points = new ArrayList<>(points); | |
58 | 58 | setId(id); |
59 | 59 | } |
60 | 60 | |
61 | @Override | |
61 | 62 | public Way copy() { |
62 | 63 | Way dup = new Way(getId(), points); |
63 | 64 | dup.copyIds(this); |
77 | 78 | */ |
78 | 79 | public List<Coord> getPoints() { |
79 | 80 | return points; |
81 | } | |
82 | ||
83 | /** | |
84 | * @return first point or null if points is empty | |
85 | */ | |
86 | public Coord getFirstPoint() { | |
87 | return points.isEmpty() ? null:points.get(0); | |
88 | } | |
89 | ||
90 | /** | |
91 | * @return last point or null if points is empty | |
92 | */ | |
93 | public Coord getLastPoint() { | |
94 | return points.isEmpty() ? null:points.get(points.size() - 1); | |
80 | 95 | } |
81 | 96 | |
82 | 97 | public void addPoint(Coord co) { |
206 | 221 | return Coord.makeHighPrecCoord((int)Math.round(lat), (int)Math.round(lon)); |
207 | 222 | } |
208 | 223 | |
224 | @Override | |
209 | 225 | public String kind() { |
210 | 226 | return "way"; |
211 | 227 | } |
271 | 287 | } |
272 | 288 | return this.fullArea; |
273 | 289 | } |
274 | ||
275 | 290 | } |
80 | 80 | if (b1.size() == 0 && b2.size() == 0) |
81 | 81 | return; |
82 | 82 | |
83 | Collections.sort(b1); | |
84 | Collections.sort(b2); | |
83 | b1.sort(null); | |
84 | b2.sort(null); | |
85 | 85 | |
86 | 86 | Queue<String> bounds1 = new LinkedList<>(b1); |
87 | 87 | Queue<String> bounds2 = new LinkedList<>(b2); |
17 | 17 | import java.io.IOException; |
18 | 18 | import java.nio.channels.FileChannel; |
19 | 19 | import java.util.ArrayList; |
20 | import java.util.Collections; | |
21 | 20 | import java.util.List; |
22 | 21 | import java.util.ListIterator; |
23 | 22 | |
53 | 52 | List<String> fl1 = BoundaryUtil.getBoundaryDirContent(dir1.getAbsolutePath()); |
54 | 53 | List<String> fl2 = BoundaryUtil.getBoundaryDirContent(dir2.getAbsolutePath()); |
55 | 54 | |
56 | Collections.sort(fl1); | |
57 | Collections.sort(fl2); | |
55 | fl1.sort(null); | |
56 | fl2.sort(null); | |
58 | 57 | |
59 | 58 | ListIterator<String> fl1Iter = fl1.listIterator(); |
60 | 59 | ListIterator<String> fl2Iter = fl2.listIterator(); |
270 | 270 | private void sortBoundaryTagsMap(){ |
271 | 271 | // make sure that the merged LinkedHashMap is sorted as mergeBoundaries() needs it |
272 | 272 | ArrayList<String> ids = new ArrayList<>(boundaryTags.keySet()); |
273 | Collections.sort(ids, new AdminLevelCollator()); | |
274 | Collections.reverse(ids); | |
273 | ids.sort(new AdminLevelCollator().reversed()); | |
275 | 274 | HashMap<String,Tags> tmp = new LinkedHashMap<>(boundaryTags); |
276 | 275 | boundaryTags.clear(); |
277 | 276 | for (String id: ids){ |
14 | 14 | import java.util.ArrayList; |
15 | 15 | import java.util.BitSet; |
16 | 16 | import java.util.Collections; |
17 | import java.util.Comparator; | |
18 | 17 | import java.util.HashMap; |
19 | 18 | import java.util.HashSet; |
20 | 19 | import java.util.IdentityHashMap; |
323 | 322 | |
324 | 323 | // check all ways for endpoints outside or on the bbox |
325 | 324 | for (JoinedWay w : unclosed) { |
326 | Coord c1 = w.getPoints().get(0); | |
327 | Coord c2 = w.getPoints().get(w.getPoints().size() - 1); | |
325 | Coord c1 = w.getFirstPoint(); | |
326 | Coord c2 = w.getLastPoint(); | |
328 | 327 | outOfBboxPoints.put(c1, w); |
329 | 328 | outOfBboxPoints.put(c2, w); |
330 | 329 | } |
355 | 354 | } else { |
356 | 355 | // retrieve the connection with the minimum distance |
357 | 356 | ConnectionData minCon = Collections.min(coordPairs, |
358 | new Comparator<ConnectionData>() { | |
359 | public int compare(ConnectionData o1, | |
360 | ConnectionData o2) { | |
361 | return Double.compare(o1.distance, o2.distance); | |
362 | } | |
363 | }); | |
357 | (o1, o2) -> Double.compare(o1.distance, o2.distance)); | |
364 | 358 | |
365 | 359 | if (minCon.distance < getMaxCloseDist()) { |
366 | 360 | |
371 | 365 | minCon.w1.closeWayArtificially(); |
372 | 366 | } else { |
373 | 367 | log.debug("Connect", minCon.w1, "with", minCon.w2); |
374 | if (minCon.w1.getPoints().get(0) == minCon.c1) { | |
368 | if (minCon.w1.getFirstPoint() == minCon.c1) { | |
375 | 369 | Collections.reverse(minCon.w1.getPoints()); |
376 | 370 | } |
377 | if (minCon.w2.getPoints().get(0) != minCon.c2) { | |
371 | if (minCon.w2.getFirstPoint() != minCon.c2) { | |
378 | 372 | Collections.reverse(minCon.w2.getPoints()); |
379 | 373 | } |
380 | 374 | |
408 | 402 | ListIterator<JoinedWay> pIter = polygons.listIterator(); |
409 | 403 | while (pIter.hasNext()) { |
410 | 404 | JoinedWay w = pIter.next(); |
411 | Coord first = w.getPoints().get(0); | |
412 | Coord last = w.getPoints().get(w.getPoints().size() - 1); | |
405 | Coord first = w.getFirstPoint(); | |
406 | Coord last = w.getLastPoint(); | |
413 | 407 | if (first != last) { |
414 | 408 | // the way is not closed |
415 | 409 | // check if one of start/endpoint is out of the bounding box |
416 | 410 | // in this case it is too risky to close it |
417 | if (getTileBounds().contains(first) == false || getTileBounds().contains(last) == false) { | |
411 | if (!getTileBounds().contains(first) || !getTileBounds().contains(last)) { | |
418 | 412 | pIter.remove(); |
419 | 413 | } |
420 | 414 | } |
11 | 11 | */ |
12 | 12 | package uk.me.parabola.mkgmap.reader.osm.boundary; |
13 | 13 | |
14 | import it.unimi.dsi.fastutil.ints.IntArrayList; | |
15 | 14 | import java.awt.Shape; |
16 | 15 | import java.awt.geom.PathIterator; |
17 | 16 | import java.io.BufferedOutputStream; |
22 | 21 | import java.io.IOException; |
23 | 22 | import java.io.OutputStream; |
24 | 23 | import java.util.ArrayList; |
25 | import java.util.Collections; | |
26 | import java.util.Comparator; | |
27 | 24 | import java.util.HashMap; |
28 | 25 | import java.util.HashSet; |
29 | 26 | import java.util.Iterator; |
32 | 29 | import java.util.Map.Entry; |
33 | 30 | import java.util.regex.Pattern; |
34 | 31 | |
32 | import it.unimi.dsi.fastutil.ints.IntArrayList; | |
35 | 33 | import uk.me.parabola.log.Logger; |
36 | 34 | import uk.me.parabola.mkgmap.Version; |
37 | 35 | import uk.me.parabola.mkgmap.reader.osm.Tags; |
176 | 174 | return; |
177 | 175 | } |
178 | 176 | |
179 | Collections.sort(openStreams, new Comparator<StreamInfo>() { | |
180 | ||
181 | public int compare(StreamInfo o1, StreamInfo o2) { | |
182 | return o1.lastAccessNo - o2.lastAccessNo; | |
183 | } | |
184 | }); | |
177 | openStreams.sort((o1, o2) -> o1.lastAccessNo - o2.lastAccessNo); | |
185 | 178 | |
186 | 179 | log.debug(openStreams.size(), "open streams."); |
187 | 180 | List<StreamInfo> closingStreams = openStreams.subList(0, |
171 | 171 | seaWay.addPoint(new Coord(90.0d, -180.0d)); |
172 | 172 | seaWay.addPoint(new Coord(90.0d, 180.0d)); |
173 | 173 | seaWay.addPoint(new Coord(-90.0d, 180.0d)); |
174 | seaWay.addPoint(seaWay.getPoints().get(0)); // close shape | |
174 | seaWay.addPoint(seaWay.getFirstPoint()); // close shape | |
175 | 175 | seaWay.setClosedInOSM(true); |
176 | 176 | landWays.put(seaWay.getId(), seaWay); |
177 | 177 |
14 | 14 | |
15 | 15 | import java.util.LinkedHashSet; |
16 | 16 | import java.util.Set; |
17 | ||
17 | 18 | import uk.me.parabola.imgfmt.app.Coord; |
18 | 19 | |
19 | 20 | |
61 | 62 | |
62 | 63 | |
63 | 64 | /** |
64 | * Start the add action with the root | |
65 | * Add a point to the tree. | |
65 | 66 | * @param toAdd |
66 | 67 | */ |
67 | 68 | public void add(T toAdd) { |
86 | 87 | } |
87 | 88 | |
88 | 89 | /** |
89 | * Recursive routine to find the right place for inserting | |
90 | * into the tree. | |
91 | * @param toAdd the point | |
90 | * Recursive routine to find the right place for inserting a point into the tree. | |
91 | * @param toAdd the point to add | |
92 | 92 | * @param tree the subtree root node where to add (maybe <code>null</code>) |
93 | 93 | * @param useLongitude <code>true</code> the tree node uses longitude for comparison; |
94 | 94 | * <code>false</code> the tree node uses latitude for comparison |
95 | 95 | * @return the subtree root node after insertion |
96 | 96 | */ |
97 | private KdNode add( T toAdd, KdNode tree, boolean useLongitude){ | |
98 | if( tree == null ) { | |
99 | tree = new KdNode( toAdd ); | |
100 | } else { | |
101 | if(isSmaller(useLongitude, toAdd.getLocation(), tree.point.getLocation())) { | |
102 | tree.left = add(toAdd, tree.left, !useLongitude); | |
103 | } else { | |
104 | tree.right = add(toAdd, tree.right, !useLongitude); | |
105 | } | |
106 | } | |
107 | return tree; | |
108 | } | |
97 | private KdNode add(T toAdd, KdNode tree, boolean useLongitude) { | |
98 | if (tree == null) { | |
99 | tree = new KdNode(toAdd); | |
100 | } else { | |
101 | if (isSmaller(useLongitude, toAdd.getLocation(), tree.point.getLocation())) { | |
102 | tree.left = add(toAdd, tree.left, !useLongitude); | |
103 | } else { | |
104 | tree.right = add(toAdd, tree.right, !useLongitude); | |
105 | } | |
106 | } | |
107 | return tree; | |
108 | } | |
109 | 109 | |
110 | 110 | /** |
111 | 111 | * Searches for the point that has smallest distance to the given point. |
112 | * @param p the point to search for | |
112 | * @param p the given point | |
113 | 113 | * @return the point with shortest distance to <var>p</var> |
114 | 114 | */ |
115 | 115 | public T findNextPoint(Locatable p) { |
116 | 116 | // reset |
117 | 117 | minDist = Double.MAX_VALUE; |
118 | maxDist = -1; | |
118 | maxDist = -1; | |
119 | 119 | set = null; |
120 | 120 | nextPoint = null; |
121 | 121 | |
122 | 122 | // false => first node is a latitude level |
123 | return findNextPoint(p, root, ROOT_NODE_USES_LONGITUDE); | |
123 | return findNextPoint(p.getLocation(), root, ROOT_NODE_USES_LONGITUDE); | |
124 | 124 | } |
125 | 125 | |
126 | 126 | /** |
127 | * Searches for the point that has smallest distance to the given point. | |
128 | * @param p the point to search for | |
129 | * @return the point with shortest distance to <var>p</var> | |
127 | * Searches for the points that have <var>maxDist</var> distance to the given point. | |
128 | * @param p the given point | |
129 | * @param maxDist the allowed distance | |
130 | * @return the points within distance <var>maxDist</var> to <var>p</var> | |
130 | 131 | */ |
131 | public Set<T> findNextPoint(Locatable p, double maxDist) { | |
132 | public Set<T> findClosePoints(Locatable p, double maxDist) { | |
132 | 133 | // reset |
133 | 134 | minDist = Double.MAX_VALUE; |
134 | 135 | this.maxDist = Math.pow(maxDist * 360 / Coord.U, 2); // convert maxDist in meter to distanceInDegreesSquared |
135 | 136 | nextPoint = null; |
136 | this.set = new LinkedHashSet<>(); | |
137 | set = new LinkedHashSet<>(); | |
137 | 138 | // false => first node is a latitude level |
138 | findNextPoint(p, root, ROOT_NODE_USES_LONGITUDE); | |
139 | findNextPoint(p.getLocation(), root, ROOT_NODE_USES_LONGITUDE); | |
139 | 140 | return set; |
140 | 141 | } |
141 | 142 | |
142 | private T findNextPoint(Locatable p, KdNode tree, boolean useLongitude) { | |
143 | boolean continueWithLeft = false; | |
143 | /** | |
144 | * Recursive routine to find the closest point. If set is not null, all | |
145 | * elements within the range given by maxDist are collected. | |
146 | * | |
147 | * @param p the location of the given point | |
148 | * @param tree the sub tree | |
149 | * @param useLongitude gives the dimension to search in | |
150 | * @return the closest point | |
151 | */ | |
152 | private T findNextPoint(Coord p, KdNode tree, boolean useLongitude) { | |
144 | 153 | if (tree == null) |
145 | 154 | return nextPoint; |
146 | 155 | |
147 | if (tree.left == null && tree.right == null){ | |
148 | double dist = tree.point.getLocation().distanceInDegreesSquared(p.getLocation()); | |
149 | if (dist <= maxDist && set != null){ | |
150 | set.add(tree.point); | |
151 | } | |
152 | if (dist < minDist){ | |
153 | nextPoint = tree.point; | |
154 | if (dist < maxDist) | |
155 | minDist = maxDist; | |
156 | else | |
157 | minDist = dist; | |
158 | } | |
156 | boolean smaller; | |
157 | ||
158 | if (tree.left == null && tree.right == null) { | |
159 | processNode(tree, p); | |
159 | 160 | return nextPoint; |
160 | 161 | } |
161 | else { | |
162 | if (isSmaller(useLongitude, p.getLocation(), tree.point.getLocation())){ | |
163 | continueWithLeft = false; | |
164 | nextPoint = findNextPoint(p, tree.left, !useLongitude); | |
165 | } | |
166 | else { | |
167 | continueWithLeft = true; | |
168 | nextPoint = findNextPoint(p, tree.right, !useLongitude); | |
169 | } | |
170 | } | |
171 | ||
172 | double dist = tree.point.getLocation().distanceInDegreesSquared(p.getLocation()); | |
173 | if (dist <= maxDist && set != null) | |
174 | set.add(tree.point); | |
175 | if (dist < minDist){ | |
176 | nextPoint = tree.point; | |
177 | minDist = dist; | |
178 | if (dist < maxDist) | |
179 | minDist = maxDist; | |
180 | else | |
181 | minDist = dist; | |
182 | } | |
162 | smaller = isSmaller(useLongitude, p, tree.point.getLocation()); | |
163 | nextPoint = findNextPoint(p, smaller ? tree.left : tree.right, !useLongitude); | |
164 | ||
165 | processNode(tree, p); | |
183 | 166 | // do we have to search the other part of the tree? |
184 | Coord test; | |
185 | if (useLongitude) | |
186 | test = Coord.makeHighPrecCoord(p.getLocation().getHighPrecLat(), tree.point.getLocation().getHighPrecLon()); | |
187 | else | |
188 | test = Coord.makeHighPrecCoord(tree.point.getLocation().getHighPrecLat(), p.getLocation().getHighPrecLon()); | |
189 | if (test.distanceInDegreesSquared(p.getLocation()) < minDist){ | |
190 | if (continueWithLeft) | |
191 | nextPoint = findNextPoint(p, tree.left, !useLongitude); | |
192 | else | |
193 | nextPoint = findNextPoint(p, tree.right, !useLongitude); | |
167 | int testLat = useLongitude ? p.getHighPrecLat() : tree.point.getLocation().getHighPrecLat(); | |
168 | int testLon = useLongitude ? tree.point.getLocation().getHighPrecLon() : p.getHighPrecLon(); | |
169 | Coord test = Coord.makeHighPrecCoord(testLat, testLon); | |
170 | if (test.distanceInDegreesSquared(p) < minDist) { | |
171 | nextPoint = findNextPoint(p, smaller ? tree.right : tree.left, !useLongitude); | |
194 | 172 | } |
195 | 173 | return nextPoint; |
196 | 174 | } |
175 | ||
176 | private void processNode(KdNode node, Coord p) { | |
177 | double dist = node.point.getLocation().distanceInDegreesSquared(p); | |
178 | if (dist <= maxDist && set != null) { | |
179 | // node is within wanted range | |
180 | set.add(node.point); | |
181 | } | |
182 | if (dist < minDist) { | |
183 | nextPoint = node.point; | |
184 | minDist = dist < maxDist ? maxDist : dist; | |
185 | } | |
186 | } | |
197 | 187 | } |
12 | 12 | |
13 | 13 | package uk.me.parabola.util; |
14 | 14 | |
15 | import java.util.ArrayList; | |
16 | 15 | import java.util.Collections; |
17 | 16 | import java.util.HashMap; |
18 | 17 | import java.util.LinkedList; |
22 | 21 | public class MultiHashMap<K,V> extends HashMap<K,List<V>> { |
23 | 22 | |
24 | 23 | /** |
25 | * the empty list to be returned when there is key without values. | |
26 | */ | |
27 | private final List<V> emptyList = Collections.unmodifiableList(new ArrayList<V>(0)); | |
28 | ||
29 | /** | |
30 | 24 | * Returns the list of values associated with the given key. |
31 | 25 | * |
32 | 26 | * @param key the key to get the values for. |
33 | 27 | * @return a list of values for the given keys or the empty list of no such |
34 | 28 | * value exist. |
35 | 29 | */ |
30 | @Override | |
36 | 31 | public List<V> get(Object key) { |
37 | 32 | List<V> result = super.get(key); |
38 | return result == null ? emptyList : result; | |
33 | return result == null ? Collections.emptyList() : result; | |
39 | 34 | } |
40 | 35 | |
41 | ||
36 | /** | |
37 | * Add mapping for the given key and value. | |
38 | * If the key already exists, the value is added to the end of the existing list. | |
39 | * | |
40 | * @param key the key | |
41 | * @param value the value | |
42 | * @return the value | |
43 | */ | |
42 | 44 | public V add(K key, V value ) { |
43 | List<V> values = super.get(key); | |
44 | if (values == null ) { | |
45 | values = new LinkedList<V>(); | |
46 | super.put( key, values ); | |
47 | } | |
48 | ||
49 | boolean results = values.add(value); | |
50 | ||
51 | return ( results ? value : null ); | |
45 | super.computeIfAbsent(key, k -> new LinkedList<>()).add(value); | |
46 | return value; | |
52 | 47 | } |
53 | 48 | |
54 | 49 | public V removeMapping(K key, V value) { |
55 | List<V> values = super.get(key); | |
56 | if (values == null ) | |
50 | List<V> values = super.get(key); | |
51 | if (values == null) | |
57 | 52 | return null; |
58 | 53 | |
59 | values.remove(value); | |
60 | ||
54 | values.remove(value); | |
55 | ||
61 | 56 | if (values.isEmpty()) |
62 | 57 | super.remove(key); |
63 | 58 |
0 | /* | |
1 | * Copyright (C) 2015 Gerd Petermann | |
2 | * | |
3 | * This program is free software; you can redistribute it and/or modify | |
4 | * it under the terms of the GNU General Public License version 3 or | |
5 | * version 2 as published by the Free Software Foundation. | |
6 | * | |
7 | * This program is distributed in the hope that it will be useful, but | |
8 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
10 | * General Public License for more details. | |
11 | */ | |
12 | package uk.me.parabola.util; | |
13 | ||
14 | import java.util.Collections; | |
15 | import java.util.HashMap; | |
16 | import java.util.LinkedHashSet; | |
17 | import java.util.Set; | |
18 | ||
19 | ||
20 | public class MultiHashSet<K,V> extends HashMap<K,Set<V>> { | |
21 | ||
22 | /** | |
23 | * the empty set to be returned when there is key without values. | |
24 | */ | |
25 | private final Set<V> emptyList = Collections.emptySet(); | |
26 | ||
27 | /** | |
28 | * Returns the list of values associated with the given key. | |
29 | * | |
30 | * @param key the key to get the values for. | |
31 | * @return a list of values for the given keys or the empty list of no such | |
32 | * value exist. | |
33 | */ | |
34 | public Set<V> get(Object key) { | |
35 | Set<V> result = super.get(key); | |
36 | return result == null ? emptyList : result; | |
37 | } | |
38 | ||
39 | ||
40 | public boolean add(K key, V value ) { | |
41 | Set<V> values = super.get(key); | |
42 | if (values == null ) { | |
43 | values = new LinkedHashSet<V>(); | |
44 | super.put( key, values ); | |
45 | } | |
46 | return values.add(value); | |
47 | } | |
48 | ||
49 | public boolean removeMapping(K key, V value) { | |
50 | Set<V> values = super.get(key); | |
51 | if (values == null ) | |
52 | return false; | |
53 | ||
54 | boolean existed = values.remove(value); | |
55 | ||
56 | if (values.isEmpty()) | |
57 | super.remove(key); | |
58 | ||
59 | return existed; | |
60 | } | |
61 | } | |
62 |
173 | 173 | SortKey<String> key = sort.createSortKey(s, s); |
174 | 174 | keys.add(key); |
175 | 175 | } |
176 | Collections.sort(keys); | |
176 | keys.sort(null); | |
177 | 177 | |
178 | 178 | long end = System.currentTimeMillis(); |
179 | 179 | |
189 | 189 | private List<String> sortWithCollator(List<String> list) { |
190 | 190 | long start = System.currentTimeMillis(); |
191 | 191 | List<String> ret = new ArrayList<>(list); |
192 | Collections.sort(ret, sort.getCollator()); | |
192 | ret.sort(sort.getCollator()); | |
193 | 193 | System.out.println("time coll: " + (System.currentTimeMillis() - start) + "ms"); |
194 | 194 | return ret; |
195 | 195 | } |
209 | 209 | CollationKey key = jcol.getCollationKey(s); |
210 | 210 | keys.add(key); |
211 | 211 | } |
212 | Collections.sort(keys); | |
212 | keys.sort(null); | |
213 | 213 | |
214 | 214 | long end = System.currentTimeMillis(); |
215 | 215 | |
235 | 235 | return null; |
236 | 236 | } |
237 | 237 | |
238 | Collections.sort(out, jcol); | |
238 | out.sort(jcol); | |
239 | 239 | |
240 | 240 | System.out.println("time J collator: " + (System.currentTimeMillis() - start) + "ms"); |
241 | 241 | return out; |
1205 | 1205 | el.addPoint(new Coord(2000,2000)); |
1206 | 1206 | el.addPoint(new Coord(2000,1000)); |
1207 | 1207 | if (closed) |
1208 | el.addPoint(el.getPoints().get(0)); | |
1208 | el.addPoint(el.getFirstPoint()); | |
1209 | 1209 | el.setComplete(complete); |
1210 | 1210 | el.setClosedInOSM(true); |
1211 | 1211 | return el; |
268 | 268 | return 0; |
269 | 269 | } |
270 | 270 | |
271 | public void addThroughRoute(int junctionNodeId, long roadIdA, long roadIdB) { } | |
272 | 271 | }; |
273 | 272 | |
274 | 273 | return new StyledConverter(style, coll, new EnhancedProperties()); |
15 | 15 | */ |
16 | 16 | package uk.me.parabola.mkgmap.reader.osm; |
17 | 17 | |
18 | import static org.junit.Assert.assertArrayEquals; | |
19 | import static org.junit.Assert.assertEquals; | |
20 | ||
18 | 21 | import java.util.ArrayList; |
19 | import java.util.Collections; | |
20 | 22 | import java.util.List; |
21 | 23 | import java.util.Map; |
22 | 24 | |
23 | 25 | import org.junit.Test; |
24 | ||
25 | import static org.junit.Assert.*; | |
26 | 26 | |
27 | 27 | |
28 | 28 | public class ElementTest { |
42 | 42 | values.add(ent.getValue()); |
43 | 43 | } |
44 | 44 | |
45 | Collections.sort(keys); | |
46 | Collections.sort(values); | |
45 | keys.sort(null); | |
46 | values.sort(null); | |
47 | 47 | |
48 | 48 | assertArrayEquals("list of keys", |
49 | 49 | new String[] {"a", "b", "c"}, |
12 | 12 | package uk.me.parabola.util; |
13 | 13 | |
14 | 14 | import static org.junit.Assert.assertFalse; |
15 | ||
15 | 16 | import org.junit.Test; |
16 | 17 | |
17 | 18 | import uk.me.parabola.imgfmt.app.Coord; |
18 | 19 | import uk.me.parabola.mkgmap.general.MapPoint; |
19 | import uk.me.parabola.util.KdTree; | |
20 | 20 | |
21 | 21 | public class KdTreeTest { |
22 | 22 | |
23 | 23 | @Test |
24 | public void TestFindNextPoint(){ | |
24 | public void findNextPointTest(){ | |
25 | 25 | KdTree<MapPoint> t = new KdTree<>( ); |
26 | 26 | |
27 | 27 | int [][]test = {{70,20}, {50,40}, {90,60}, {20,30}, {40,70}, {80,10}, {-10,20}, {-30,-40} } ; |
48 | 48 | } |
49 | 49 | } |
50 | 50 | toFind.setLocation(co); |
51 | MapPoint next = (MapPoint) t.findNextPoint(toFind); | |
51 | MapPoint next = t.findNextPoint(toFind); | |
52 | 52 | double dist = next.getLocation().distanceInDegreesSquared(co); |
53 | 53 | double delta = Math.abs(dist - minDist); |
54 | 54 | // if this test fails because |