[mkgmap-dev] Proposed change to splitter to make tile names unique
From Randolph J. Herber army.bronze.star at gmail.com on Sun May 20 17:44:36 BST 2018
Dear Sirs: I propose adding the following to uk.me.parabola.splitter.AreaList.java: *** AreaList-old.java 2019-05-20 11:28:45.739455200 -0500 --- AreaList.java 2018-05-11 20:01:47.861375200 -0500 *************** *** 280,286 **** cityFinder = new DefaultCityFinder(cities); } for (Area area : getAreas()) { ! area.setName(description); if (cityFinder == null) continue; --- 280,286 ---- cityFinder = new DefaultCityFinder(cities); } for (Area area : getAreas()) { ! area.setName(description + "-" + openLocationCode(area)); if (cityFinder == null) continue; *************** *** 350,354 **** --- 350,401 ---- } } + private static final String codes = "23456789CFGHJMPQRVWX"; + private static String openLocationCode(Area area) { + return openLocationCode( + Utils.toDegrees(area.getMinLat()), + Utils.toDegrees(area.getMinLong()), + Utils.toDegrees(area.getMaxLat()), + Utils.toDegrees(area.getMaxLong())); + } + + private static String openLocationCode( + double south,double west,double north,double east) { + double centerLatitude = 0.5 *(south + north)+90.; + double centerLongitude = 0.5 * (west + east)+180.; + double boxHeight = north - south; + double boxWidth = east - west; + double height = 400.; + double width = 400.; + String code = ""; + boolean done = false; + while(code.length() < 8 & !done) { + int p; + height /= 20.; + width /= 20.; + p = (int)Math.floor(centerLatitude/height); + code += codes.charAt(p); + centerLatitude -= p * height; + p = (int)Math.floor(centerLongitude/width); + code += codes.charAt(p); + centerLongitude -= p * width; + done = width <= boxWidth && height <= boxHeight; + } + if(!done) { + code += "+"; + while(!done) { + int la, lo; + height /= 5.; + width /= 4.; + la = (int)Math.floor(centerLatitude/height); + centerLatitude -= la * height; + lo = (int)Math.floor(centerLongitude/width); + centerLongitude -= lo * width; + code += codes.charAt(5*la+lo); + done = width <= boxWidth && height <= boxHeight; + } + } + return code; + } } The purpose is to give each tile an unique name by appending the Open Location Code of the largest region (shortest code) that fits within the tile. I have been using this code myself. https://en.wikipedia.org/wiki/Open_Location_Code Randolph J. Herber -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://www.mkgmap.org.uk/pipermail/mkgmap-dev/attachments/20180520/35251ab6/attachment.html>
- Previous message: [mkgmap-dev] Erroneous error message
- Next message: [mkgmap-dev] I would like a maxways parameter and associated code to limit the number of ways in a tile
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the mkgmap-dev mailing list