From a61c9d9071c35c278840f73b9eb5aa01a6677506 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sun, 1 Apr 2012 18:38:10 +0200 Subject: [PATCH] Add coastline processing --- .../osmand/binary/BinaryMapIndexReader.java | 4 +-- .../osmand/data/preparation/IndexCreator.java | 4 +-- .../data/preparation/OsmDbAccessor.java | 9 ++--- .../src/net/osmand/render/default.render.xml | 6 ++-- OsmAnd/res/values/strings.xml | 2 +- .../plus/render/MapRenderRepositories.java | 35 +++++++++++-------- 6 files changed, 33 insertions(+), 27 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java index e629593a3c..4618695448 100644 --- a/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java +++ b/DataExtractionOSM/src/net/osmand/binary/BinaryMapIndexReader.java @@ -534,10 +534,10 @@ public class BinaryMapIndexReader { switch (tag) { case 0: // encoding rules are required! - index.finishInitializingTags(); if(index.encodingRules.isEmpty()){ throw new IllegalStateException("Encoding rules are not defined for the map index"); } + index.finishInitializingTags(); return; case OsmandOdb.OsmAndMapIndex.NAME_FIELD_NUMBER : index.setName(codedIS.readString()); @@ -1331,7 +1331,7 @@ public class BinaryMapIndexReader { } public void finishInitializingTags() { - coastlineBrokenEncodingType = encodingRules.size() * 2; + coastlineBrokenEncodingType = decodingRules.size() * 2 + 1; initMapEncodingRule(0, coastlineBrokenEncodingType, "natural", "coastline_broken"); } diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java index 98b19beb35..0b96f9f015 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/IndexCreator.java @@ -626,7 +626,7 @@ public class IndexCreator { long time = System.currentTimeMillis(); IndexCreator creator = new IndexCreator(new File("/home/victor/projects/OsmAnd/data/osm-gen/")); //$NON-NLS-1$ creator.setIndexMap(true); - creator.setIndexAddress(true); + creator.setIndexAddress(false); creator.setIndexPOI(false); creator.setIndexTransport(false); @@ -637,7 +637,7 @@ public class IndexCreator { creator.setZoomWaySmothness(2); MapRenderingTypes rt = MapRenderingTypes.getDefault();// new MapRenderingTypes("/home/victor/projects/OsmAnd/data/testdata/roads_rendering_types.xml"); MapZooms zooms = MapZooms.getDefault(); // MapZooms.parseZooms("15-"); -// creator.setNodesDBFile(new File("/home/victor/projects/OsmAnd/data/osm-gen/nodes.tmp.odb")); + creator.setNodesDBFile(new File("/home/victor/projects/OsmAnd/data/osm-gen/nodes.tmp.odb")); // creator.generateIndexes(new File("/home/victor/projects/OsmAnd/data/osm-maps/luxembourg.osm.pbf"), creator.generateIndexes(new File("/home/victor/projects/OsmAnd/data/osm-maps/cuba.osm.bz2"), new ConsoleProgressImplementation(1), null, zooms, rt, log); diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/OsmDbAccessor.java b/DataExtractionOSM/src/net/osmand/data/preparation/OsmDbAccessor.java index 44eb082d71..5ab80f802e 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/OsmDbAccessor.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/OsmDbAccessor.java @@ -150,7 +150,11 @@ public class OsmDbAccessor implements OsmDbAccessorContext { int ord = rs.getInt(2); if (ord > 0 || first) { first = false; - ((Way) e).addNode(new Node(rs.getDouble(5), rs.getDouble(6), rs.getLong(1))); + if(rs.getObject(5) != null) { + ((Way) e).addNode(new Node(rs.getDouble(5), rs.getDouble(6), rs.getLong(1))); + } else { + ((Way) e).addNode(rs.getLong(1)); + } } } rs.close(); @@ -200,9 +204,6 @@ public class OsmDbAccessor implements OsmDbAccessorContext { way.putTag(rs.getString(3), rs.getString(4)); } } - if (way.getNodes() == null) { - System.err.println("Strange, way with id:" + i.getId() + " has no nodes?"); - } rs.close(); } } else if (i.getType() == EntityType.RELATION) { diff --git a/DataExtractionOSM/src/net/osmand/render/default.render.xml b/DataExtractionOSM/src/net/osmand/render/default.render.xml index 4e0e2e8f6c..ed9f8e7d76 100644 --- a/DataExtractionOSM/src/net/osmand/render/default.render.xml +++ b/DataExtractionOSM/src/net/osmand/render/default.render.xml @@ -199,7 +199,7 @@ - + @@ -824,7 +824,7 @@ - + @@ -958,7 +958,7 @@ - + diff --git a/OsmAnd/res/values/strings.xml b/OsmAnd/res/values/strings.xml index 8fd7f4a70d..c86c63b51e 100644 --- a/OsmAnd/res/values/strings.xml +++ b/OsmAnd/res/values/strings.xml @@ -676,7 +676,7 @@ Turn slightly left and go Make U-turn and go Head - No, Thanks + Later Download regions Thank you for choosing OsmAnd. \nTo use the major features of this application, you will need some regional offline data, which you can download (use Settings, Offline Data). Afterwards, you will be able to search by address, look up POIs and find public transportation. Searching for signal… diff --git a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java index e406d70fc6..93b4ea423e 100644 --- a/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java +++ b/OsmAnd/src/net/osmand/plus/render/MapRenderRepositories.java @@ -627,7 +627,7 @@ public class MapRenderRepositories { private List processCoastlines(List coastLines, int leftX, int rightX, int bottomY, int topY, int zoom) { List completedRings = new ArrayList(); - List incompletedRings = new ArrayList(); + List uncompletedRings = new ArrayList(); List result = new ArrayList(coastLines.size()); MapIndex mapIndex = null; long dbId = 0; @@ -653,7 +653,7 @@ public class MapRenderRepositories { boolean inside = leftX <= x && x <= rightX && y >= topY && y <= bottomY; boolean lineEnded = calculateLineCoordinates(inside, x, y, pinside, px, py, leftX, rightX, bottomY, topY, coordinates); if (lineEnded) { - combineMultipolygonLine(completedRings, incompletedRings, coordinates); + combineMultipolygonLine(completedRings, uncompletedRings, coordinates); // create new line if it goes outside coordinates = new TLongArrayList(); } @@ -661,13 +661,13 @@ public class MapRenderRepositories { py = y; pinside = inside; } - combineMultipolygonLine(completedRings, incompletedRings, coordinates); + combineMultipolygonLine(completedRings, uncompletedRings, coordinates); } - if (completedRings.size() == 0 && incompletedRings.size() == 0) { + if (completedRings.size() == 0 && uncompletedRings.size() == 0) { return result; } - if (incompletedRings.size() > 0) { - unifyIncompletedRings(incompletedRings, completedRings, leftX, rightX, bottomY, topY, dbId, zoom); + if (uncompletedRings.size() > 0) { + unifyIncompletedRings(uncompletedRings, completedRings, leftX, rightX, bottomY, topY, dbId, zoom); } boolean clockwiseFound = false; int mask = 0xffffffff; @@ -687,8 +687,9 @@ public class MapRenderRepositories { result.add(o); } - for (int i = 0; i < incompletedRings.size(); i++) { - TLongList ring = incompletedRings.get(i); + // draw uncompleted for debug purpose + for (int i = 0; i < uncompletedRings.size(); i++) { + TLongList ring = uncompletedRings.get(i); int[] coordinates = new int[ring.size() * 2]; for (int j = 0; j < ring.size(); j++) { coordinates[j * 2] = (int) (ring.get(j) >> 32); @@ -702,6 +703,7 @@ public class MapRenderRepositories { // add complete water tile BinaryMapDataObject o = new BinaryMapDataObject(new int[] { leftX, topY, rightX, topY, rightX, bottomY, leftX, bottomY, leftX, topY }, new int[] { mapIndex.coastlineEncodingType }, null, dbId); + o.setMapIndex(mapIndex); log.info("!!! Isolated islands !!!"); //$NON-NLS-1$ result.add(o); @@ -744,11 +746,13 @@ public class MapRenderRepositories { } } - private void unifyIncompletedRings(List incompletedRings, List completedRings, int leftX, int rightX, int bottomY, int topY, long dbId, int zoom) { + private void unifyIncompletedRings(List toProcces, List completedRings, int leftX, int rightX, int bottomY, int topY, long dbId, int zoom) { int mask = 0xffffffff; + List uncompletedRings = new ArrayList(toProcces); + toProcces.clear(); Set nonvisitedRings = new LinkedHashSet(); - for (int j = 0; j < incompletedRings.size(); j++) { - TLongList i = incompletedRings.get(j); + for (int j = 0; j < uncompletedRings.size(); j++) { + TLongList i = uncompletedRings.get(j); int x = (int) (i.get(i.size() - 1) >> 32); int y = (int) (i.get(i.size() - 1) & mask); int sx = (int) (i.get(0) >> 32); @@ -775,12 +779,13 @@ public class MapRenderRepositories { System.err .println(MessageFormat.format(dbId + str, dx, dy, dsx, dsy, leftX + "", topY + "", rightX + "", bottomY + "")); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$//$NON-NLS-4$ } + toProcces.add(i); } else { nonvisitedRings.add(j); } } - for (int j = 0; j < incompletedRings.size(); j++) { - TLongList i = incompletedRings.get(j); + for (int j = 0; j < uncompletedRings.size(); j++) { + TLongList i = uncompletedRings.get(j); if (!nonvisitedRings.contains(j)) { continue; } @@ -808,7 +813,7 @@ public class MapRenderRepositories { // BEGIN find closest nonvisited start (including current) int mindiff = UNDEFINED_MIN_DIFF; for (Integer ni : nonvisitedRings) { - TLongList cni = incompletedRings.get(ni); + TLongList cni = uncompletedRings.get(ni); int csx = (int) (cni.get(0) >> 32); int csy = (int) (cni.get(0) & mask); if (h % 4 == 0) { @@ -877,7 +882,7 @@ public class MapRenderRepositories { nonvisitedRings.remove(j); break; } else { - i.addAll(incompletedRings.get(nextRingIndex)); + i.addAll(uncompletedRings.get(nextRingIndex)); nonvisitedRings.remove(nextRingIndex); // get last point and start again going clockwise x = (int) (i.get(i.size() - 1) >> 32);