Am 18.01.2010 00:13, schrieb Mark Burton:
Hi Ronny,
this patch (against 1485) adds a new option for generate-sea:
"extend-sea-sectors"
If this option is set, coastlines not reaching the borders of a map will
be extended with a point at the nearest border.
This prevents strange things happening at the borders of geofabrik extracts.
See attached pictures of turkey created with options "polygon"
(just_polygon.png), "polygon,no-sea-sectors" (noseasectors.png) and
"polygon,extend-sea-sectors" (with_patch.png).
Would be nice if someone could test and merge it.
That looks a useful addition but as you haven't put any comments in
getNextEdgeHit() it's not immediately obvious what it's doing.
You do have one comment: // create additional points at next border
Perhaps I'm just stupid, but it doesn't really explain what happens
next.
The original generate sea code was not well commented but that doesn't
mean that additions to it have to similar.
Mark
OK. I added some comments. Hope this explains what is done.
Ronny
### Eclipse Workspace Patch 1.0
#P mkgmap
Index: src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
===================================================================
--- src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
(revision 1485)
+++ src/uk/me/parabola/mkgmap/reader/osm/xml/Osm5XmlHandler.java
(working copy)
@@ -118,6 +118,7 @@
private final boolean generateSea;
private boolean generateSeaUsingMP = true;
private boolean allowSeaSectors = true;
+ private boolean extendSeaSectors = false;
private String[] landTag = { "natural", "land" };
private final Double minimumArcLength;
private final String frigRoundabouts;
@@ -146,6 +147,10 @@
generateSeaUsingMP = true;
else if("no-sea-sectors".equals(o))
allowSeaSectors = false;
+ else if("extend-sea-sectors".equals(o)) {
+ allowSeaSectors = false;
+ extendSeaSectors = true;
+ }
else if(o.startsWith("land-tag="))
landTag = o.substring(9).split("=");
else {
@@ -1259,6 +1264,20 @@
seaRelation.addElement("outer",
sea);
generateSeaBackground = false;
}
+ else if (extendSeaSectors) {
+ // create additional points at next
border to prevent triangles from point 2
+ if (null == hStart) {
+ hStart =
getNextEdgeHit(seaBounds, pStart);
+ w.getPoints().add(0,
hStart.getPoint(seaBounds));
+ }
+ if (null == hEnd) {
+ hEnd =
getNextEdgeHit(seaBounds, pEnd);
+
w.getPoints().add(hEnd.getPoint(seaBounds));
+ }
+ log.debug("hits (second try): ",
hStart, hEnd);
+ hitMap.put(hStart, w);
+ hitMap.put(hEnd, null);
+ }
else {
// show the coastline even though we
can't produce
// a polygon for the land
@@ -1461,6 +1480,51 @@
return null;
}
+ /*
+ * Find the nearest edge for supplied Coord p.
+ */
+ private EdgeHit getNextEdgeHit(Area a, Coord p)
+ {
+ int lat = p.getLatitude();
+ int lon = p.getLongitude();
+ int minLat = a.getMinLat();
+ int maxLat = a.getMaxLat();
+ int minLong = a.getMinLong();
+ int maxLong = a.getMaxLong();
+
+ log.info(String.format("getNextEdgeHit: (%d %d) (%d %d %d %d)",
lat, lon, minLat, minLong, maxLat, maxLong));
+ // shortest distance to border (init with distance to southern
border)
+ int min = lat - minLat;
+ // number of edge as used in getEdgeHit.
+ // 0 = southern
+ // 1 = eastern
+ // 2 = northern
+ // 3 = western edge of Area a
+ int i = 0;
+ // normalized position at border (0..1)
+ double l = ((double)(lon - minLong))/(maxLong-minLong);
+ // now compare distance to eastern border with already known
distance
+ if (maxLong - lon < min) {
+ // update data if distance is shorter
+ min = maxLong - lon;
+ i = 1;
+ l = ((double)(lat - minLat))/(maxLat-minLat);
+ }
+ // same for northern border
+ if (maxLat - lat < min) {
+ min = maxLat - lat;
+ i = 2;
+ l = ((double)(maxLong - lon))/(maxLong-minLong);
+ }
+ // same for western border
+ if (lon - minLong < min) {
+ i = 3;
+ l = ((double)(maxLat - lat))/(maxLat-minLat);
+ }
+ // now created the EdgeHit for found values
+ return new EdgeHit(i, l);
+ }
+
private void concatenateWays(List<Way> ways) {
Map<Coord, Way> beginMap = new HashMap<Coord, Way>();
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev