Use douglas peuker algorithm to simplify ways

This commit is contained in:
Victor Shcherb 2012-05-28 20:36:59 +02:00
parent c119d1628b
commit 587d881a55
2 changed files with 43 additions and 38 deletions

View file

@ -372,17 +372,7 @@ public class BinaryMapIndexWriter {
writeRawVarint32(mapDataBuf, CodedOutputStream.encodeZigZag32(ty));
pcalcx = pcalcx + tx ;
pcalcy = pcalcy + ty ;
delta = 1;
// keep first/latest point untouched
// just try to skip some points very close to this point
while (i + delta < len - 1) {
int nx = Algoritms.parseIntFromBytes(coordinates, (i + delta) * 8);
int ny = Algoritms.parseIntFromBytes(coordinates, (i + delta) * 8 + 4);
if ((Math.abs(x - nx)) >> SHIFT_COORDINATES > 7 || (Math.abs(y - ny)) >> SHIFT_COORDINATES > 7) {
break;
}
delta++;
}
delta = skipSomeNodes(coordinates, len, i, x, y, false);
}
COORDINATES_SIZE += CodedOutputStream.computeRawVarint32Size(mapDataBuf.size())
+ CodedOutputStream.computeTagSize(MapData.COORDINATES_FIELD_NUMBER) + mapDataBuf.size();
@ -416,23 +406,7 @@ public class BinaryMapIndexWriter {
pcalcx = pcalcx + tx ;
pcalcy = pcalcy + ty ;
delta = 1;
// keep first/latest point untouched
// just try to skip some points very close to this point
while (i + delta < len - 1) {
int nx = Algoritms.parseIntFromBytes(innerPolygonTypes, (i + delta) * 8);
int ny = Algoritms.parseIntFromBytes(innerPolygonTypes, (i + delta) * 8 + 4);
if(nx == 0 && ny == 0) {
if(delta > 1) {
delta --;
}
break;
}
if ((Math.abs(x - nx)) >> SHIFT_COORDINATES > 7 || (Math.abs(y - ny)) >> SHIFT_COORDINATES > 7) {
break;
}
delta++;
}
delta = skipSomeNodes(coordinates, len, i, x, y ,false);
}
}
}
@ -472,6 +446,37 @@ public class BinaryMapIndexWriter {
ID_SIZE += CodedOutputStream.computeSInt64Size(OsmandOdb.MapData.ID_FIELD_NUMBER, diffId);
return data.build();
}
private static double orthogonalDistance(int x, int y, int x1, int y1, int x2, int y2) {
int A = (x - x1);
int B = (y - y1);
int C = (x2 - x1);
int D = (y2 - y1);
return Math.abs(A * D - C * B) / Math.sqrt(C * C + D * D);
}
private int skipSomeNodes(byte[] coordinates, int len, int i, int x, int y, boolean multi) {
int delta;
delta = 1;
// keep first/latest point untouched
// simplified douglas\peuker
// just try to skip some points very close to this point
while (i + delta < len - 1) {
int nx = Algoritms.parseIntFromBytes(coordinates, (i + delta) * 8);
int ny = Algoritms.parseIntFromBytes(coordinates, (i + delta) * 8 + 4);
int nnx = Algoritms.parseIntFromBytes(coordinates, (i + delta + 1) * 8);
int nny = Algoritms.parseIntFromBytes(coordinates, (i + delta + 1) * 8 + 4);
if(nnx == 0 && nny == 0) {
break;
}
double dist = orthogonalDistance(nx, ny, x, y, nnx, nny);
if (dist > 31 ) {
break;
}
delta++;
}
return delta;
}
public void startWriteAddressIndex(String name) throws IOException {
pushState(ADDRESS_INDEX_INIT, OSMAND_STRUCTURE_INIT);

View file

@ -489,14 +489,14 @@
<filter minzoom="17" tag="amenity" value="prison"/>
<groupFilter textSize="12" textColor="#734a08" textHaloRadius="1" textDy="7" textWrapWidth="20"/>
</group>
<filter minzoom="16" textSize="12" textColor="#000033" textDy="7" textWrapWidth="16" tag="amenity" value="kindergarten"/>
<filter minzoom="16" textSize="12" textColor="#000033" textDy="7" textWrapWidth="16" tag="amenity" value="school"/>
<filter minzoom="15" textSize="12" textColor="#000033" textDy="7" textWrapWidth="16" tag="amenity" value="college"/>
<filter minzoom="15" textSize="12" textColor="#000033" textDy="7" textWrapWidth="16" textBold="true" tag="amenity" value="university"/>
<filter minzoom="16" textSize="12" textColor="#000033" textHaloRadius="1" textDy="7" textWrapWidth="16" tag="amenity" value="kindergarten"/>
<filter minzoom="16" textSize="12" textColor="#000033" textHaloRadius="1" textDy="7" textWrapWidth="16" tag="amenity" value="school"/>
<filter minzoom="15" textSize="12" textColor="#000033" textHaloRadius="1" textDy="7" textWrapWidth="16" tag="amenity" value="college"/>
<filter minzoom="15" textSize="12" textColor="#000033" textHaloRadius="1" textDy="7" textWrapWidth="16" textBold="true" tag="amenity" value="university"/>
<filter minzoom="16" textSize="12" textColor="#000033" textHaloRadius="1" textDy="7" textWrapWidth="30" tag="amenity" value="place_of_worship"/>
<filter minzoom="17" textSize="12" textColor="#0066ff" textDy="7" textWrapWidth="34" tag="amenity" value="parking"/>
<filter minzoom="17" textSize="12" textColor="#0066ff" textDy="7" tag="amenity" value="fuel"/>
<filter minzoom="16" textSize="12" textColor="#0066ff" textDy="7" tag="amenity" value="bus_station"/>
<filter minzoom="17" textSize="12" textColor="#0066ff" textHaloRadius="1" textDy="7" textWrapWidth="34" tag="amenity" value="parking"/>
<filter minzoom="17" textSize="12" textColor="#0066ff" textHaloRadius="1" textDy="7" tag="amenity" value="fuel"/>
<filter minzoom="16" textSize="12" textColor="#0066ff" textHaloRadius="1" textDy="7" tag="amenity" value="bus_station"/>
<filter minzoom="16" textSize="12" textColor="#0066ff" textHaloRadius="1" textDy="7" tag="amenity" value="shelter"/>
<filter minzoom="17" textSize="12" textColor="#da0092" textHaloRadius="1" textDy="7" textWrapWidth="12" tag="amenity" value="pharmacy"/>
<filter minzoom="16" textSize="12" textColor="#da0092" textHaloRadius="1" textDy="7" textWrapWidth="24" tag="amenity" value="hospital"/>
@ -504,7 +504,7 @@
<filter minzoom="16" textSize="12" textColor="#da0092" textHaloRadius="1" textDy="7" textWrapWidth="24" tag="amenity" value="doctors"/>
<filter minzoom="16" textSize="12" textColor="#da0092" textHaloRadius="1" textDy="7" textWrapWidth="24" tag="amenity" value="dentist"/>
<filter minzoom="16" textSize="12" textColor="#993399" textHaloRadius="1" textDy="7" textWrapWidth="20" tag="amenity" value="marketplace"/>
<filter minzoom="13" textSize="12" textColor="#ffc0cb" textBold="true" textWrapWidth="10" tag="military" value="danger_area"/>
<filter minzoom="13" textSize="12" textColor="#ffc0cb" textHaloRadius="1" textBold="true" textWrapWidth="10" tag="military" value="danger_area"/>
<!-- Shops -->
<group>
@ -1122,7 +1122,7 @@
<filter tag="highway" value="service"/>
<filter tag="highway" value="living_street"/>
<filter tag="highway" value="pedestrian"/>
<groupFilter color="#ececec" color_2="#ececec" shadowRadius="1" cap="ROUND">
<groupFilter color="#fcfcfc" color_2="#fcfcfc" shadowRadius="1" cap="ROUND">
<!-- Bridges -->
<filter layer="1" color="#000000" shadowRadius="0" cap="BUTT" cap_2="SQUARE">
<filter hmRendered="true" minzoom="14" maxzoom="14" strokeWidth="5" strokeWidth_2="3"/>
@ -1138,7 +1138,7 @@
<filter minzoom="15" maxzoom="15" strokeWidth="4"/>
<filter minzoom="16" maxzoom="16" strokeWidth="5"/>
<filter minzoom="17" maxzoom="17" strokeWidth="8"/>
<filter minzoom="18" strokeWidth="12"/>
<filter minzoom="18" strokeWidth="11"/>
<groupFilter layer="-1" pathEffect="4_4" cap="BUTT"/>
</filter>
</groupFilter>