From 06ec6db0706c03764f931c9d59828c1ce02a4b39 Mon Sep 17 00:00:00 2001 From: Victor Shcherb Date: Sat, 31 Mar 2012 16:57:38 +0200 Subject: [PATCH] Process coastlines --- .../data/preparation/CoastlineProcessor.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/DataExtractionOSM/src/net/osmand/data/preparation/CoastlineProcessor.java b/DataExtractionOSM/src/net/osmand/data/preparation/CoastlineProcessor.java index 88b92c1a3e..091101fa91 100644 --- a/DataExtractionOSM/src/net/osmand/data/preparation/CoastlineProcessor.java +++ b/DataExtractionOSM/src/net/osmand/data/preparation/CoastlineProcessor.java @@ -185,43 +185,53 @@ public class CoastlineProcessor { int nextLonMaximum = ind + 1; double lonEnd = first.getLongitude(); double latPeek = first.getLatitude(); - double latLocPeek = first.getLatitude(); + int latPeekInd = ind; + int latLocPeekInd = ind; for (int j = ind + 1; j < chain.size(); j++) { if (directionToRight) { if (chain.get(j).getLatitude() <= latPeek) { latPeek = chain.get(j).getLatitude(); + latPeekInd = j; } if (chain.get(j).getLongitude() >= lonEnd) { nextLonMaximum = j; lonEnd = chain.get(j).getLongitude(); - latLocPeek = latPeek; + latLocPeekInd = latPeekInd; } else if (chain.get(j).getLongitude() < first.getLongitude()) { break; } } else { if (chain.get(j).getLatitude() >= latPeek) { latPeek = chain.get(j).getLatitude(); + latPeekInd = j; } if (chain.get(j).getLongitude() <= lonEnd) { nextLonMaximum = j; lonEnd = chain.get(j).getLongitude(); - latLocPeek = latPeek; + latLocPeekInd = latPeekInd; } else if (chain.get(j).getLongitude() > first.getLongitude()) { break; } } } - for (int i = ind; i <= nextLonMaximum; i++) { + if(latLocPeekInd > ind) { + for (int i = ind; i <= latLocPeekInd; i++) { + subChain.add(chain.get(i)); + } + Node ned = new Node(chain.get(latLocPeekInd).getLatitude(), first.getLongitude(), nodeId++); + subChain.add(ned); + subChain.add(first); + chains.add(subChain); + subChain= new ArrayList(); + } + + for (int i = latLocPeekInd; i <= nextLonMaximum; i++) { subChain.add(chain.get(i)); } - Node ned = new Node(latLocPeek, lonEnd, nodeId++); + Node ned = new Node(chain.get(latLocPeekInd).getLatitude(), lonEnd, nodeId++); subChain.add(ned); - if (latLocPeek != first.getLatitude()) { - ned = new Node(latLocPeek, first.getLongitude(), nodeId++); - subChain.add(ned); - } ind = nextLonMaximum; - subChain.add(first); + subChain.add(chain.get(latLocPeekInd)); chains.add(subChain); }