use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class SeaPolygonRelation method removeFloodedAreas.
private void removeFloodedAreas() {
fillQuadTrees();
// create a copy of all resulting ways - the tile way map contains only
// polygons from
// the sea generation
ArrayList<Way> polygons = new ArrayList<Way>(getMpPolygons().values());
log.info("Starting flood blocker. Polygons to check:", getMpPolygons().size());
String baseName = GpxCreator.getGpxBaseName();
if (debug) {
GpxCreator.createAreaGpx(baseName + "bbox", getTileBounds());
}
// the other type
for (Way p : polygons) {
boolean sea = "sea".equals(p.getTag("natural"));
QuadTree goodCoords = (sea ? seaCoords : landCoords);
QuadTree badCoords = (sea ? landCoords : seaCoords);
String polyType = (sea ? "sea" : "land");
String otherType = (sea ? "land" : "sea");
List<Coord> minusCoords = badCoords.get(p.getPoints(), getFloodBlockerGap());
List<Coord> positiveCoords = goodCoords.get(p.getPoints());
log.info(polyType, "polygon", p.getId(), "contains", minusCoords.size(), otherType, "coords and", positiveCoords.size(), polyType, "coords.");
if (minusCoords.size() > 0) {
double area = MultiPolygonRelation.calcAreaSize(p.getPoints());
double ratio = ((minusCoords.size() - positiveCoords.size()) * 100000.0d / area);
String areaFMT = format.format(area);
String ratioFMT = format.format(ratio);
log.info("Flood blocker for", polyType, "polygon", p.getId());
log.info("area", areaFMT);
log.info(polyType, positiveCoords.size());
log.info(otherType, minusCoords.size());
log.info("ratio", ratioFMT);
if (debug) {
GpxCreator.createGpx(baseName + p.getId() + "_" + polyType + "_" + minusCoords.size() + "_" + positiveCoords.size() + "_" + ratioFMT, p.getPoints());
GpxCreator.createGpx(baseName + p.getId() + "_con_" + minusCoords.size() + "_" + positiveCoords.size() + "_" + ratioFMT, null, minusCoords);
if (positiveCoords.isEmpty() == false) {
GpxCreator.createGpx(baseName + p.getId() + "_pro_" + minusCoords.size() + "_" + positiveCoords.size() + "_" + ratioFMT, null, positiveCoords);
}
}
if (minusCoords.size() - positiveCoords.size() >= getFloodBlockerThreshold() && ratio > getFloodBlockerRatio()) {
log.warn("Polygon", p.getId(), "type", polyType, "seems to be wrong. Changing it to", otherType);
if (sea) {
p.deleteTag("natural");
p.addTag(landTag[0], landTag[1]);
} else {
p.deleteTag(landTag[0]);
p.addTag("natural", "sea");
}
// getMpPolygons().remove(p.getId());
} else {
log.info("Polygon", p.getId(), "is not blocked");
}
}
}
log.info("Flood blocker finished. Resulting polygons:", getMpPolygons().size());
landCoords.clear();
seaCoords.clear();
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class AllElements method drawPoints.
private void drawPoints(MapCollector mapper, double slat, double slon, boolean hasBackground) {
double lat = slat + 0.004;
double lon = slon + 0.002;
for (int maintype = 0; maintype <= MAX_POINT_TYPE; maintype++) {
// for (int subtype = 0; subtype <= MAX_POINT_SUB_TYPE; subtype++) {
for (int subtype = -1; subtype <= MAX_POINT_SUB_TYPE; subtype++) {
// if maintype is zero, the subtype will be treated as the type
// use subtype -1 to indicate no subtype and draw, say
// point 0x23 under 0x2300 to check they are the same
// The zero column is just for just to see 0x00
// = (maintype << 8) + subtype;
int type;
if (subtype < 0)
type = maintype;
else
type = (maintype << 8) + subtype;
MapPoint point = new MapPoint();
double baseLat = lat + subtype * ELEMENT_SPACING;
double baseLong = lon + maintype * ELEMENT_SPACING;
point.setMinResolution(10);
if (subtype < 0 ? hasBackground : !hasBackground)
point.setName(GType.formatType(type));
point.setLocation(new Coord(baseLat, baseLong));
point.setType(type);
mapper.addPoint(point);
if (configProps.containsKey("verbose"))
System.out.println("Generated POI " + GType.formatType(type) + " at " + point.getLocation().toDegreeString());
// XXX shouldn't be needed.
mapper.addToBounds(point.getLocation());
if (maintype == 0)
break;
}
}
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class AllElements method drawBackground.
private void drawBackground(MapCollector mapper, double startLat, double startLong, int nUp, int nAcross) {
MapShape shape = new MapShape();
// Wetlands // 0x4d; // glacier-white
int type = 0x51;
shape.setMinResolution(10);
shape.setName("background");
List<Coord> coords = new ArrayList<Coord>();
Coord co = new Coord(startLat, startLong);
coords.add(co);
mapper.addToBounds(co);
co = new Coord(startLat + (nUp * ELEMENT_SPACING), startLong);
coords.add(co);
mapper.addToBounds(co);
co = new Coord(startLat + (nUp * ELEMENT_SPACING), startLong + (nAcross * ELEMENT_SPACING));
coords.add(co);
mapper.addToBounds(co);
co = new Coord(startLat, startLong + (nAcross * ELEMENT_SPACING));
coords.add(co);
mapper.addToBounds(co);
coords.add(coords.get(0));
shape.setType(type);
shape.setPoints(coords);
mapper.addShape(shape);
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class AllElements method drawLines.
private void drawLines(MapCollector mapper, double slat, double slon, boolean hasBackground) {
double lat = slat + 0.004;
double lon = slon + 0.002;
int type = 0;
for (int x = 0; x < MAX_LINE_TYPE_X; x++) {
for (int y = 0; y < MAX_LINE_TYPE_Y; y++) {
MapLine line = new MapLine();
line.setMinResolution(10);
if (!hasBackground)
line.setName(GType.formatType(type));
double baseLat = lat + y * ELEMENT_SPACING;
double baseLong = lon + x * ELEMENT_SPACING;
List<Coord> coords = new ArrayList<Coord>();
Coord co = new Coord(baseLat, baseLong);
coords.add(co);
mapper.addToBounds(co);
if (configProps.containsKey("verbose"))
System.out.println("Generated line " + GType.formatType(type) + " at " + co.toDegreeString());
co = new Coord(baseLat + ELEMENT_SIZE, baseLong + ELEMENT_SIZE);
coords.add(co);
mapper.addToBounds(co);
co = new Coord(baseLat + ELEMENT_SIZE, baseLong + ELEMENT_SIZE + ELEMENT_SIZE / 2);
coords.add(co);
mapper.addToBounds(co);
line.setType(type);
line.setPoints(coords);
mapper.addLine(line);
type++;
}
}
}
use of uk.me.parabola.imgfmt.app.Coord in project mkgmap by openstreetmap.
the class AllElements method drawPolygons.
private void drawPolygons(MapCollector mapper, double slat, double slon, boolean hasBackground) {
double lat = slat + 0.004;
double lon = slon + 0.002;
int type = 0;
for (int x = 0; x < MAX_SHAPE_TYPE_X; x++) {
for (int y = 0; y < MAX_SHAPE_TYPE_Y; y++) {
// Polygon pg = div.createPolygon("0x" + Integer.toHexString(type));
MapShape shape = new MapShape();
shape.setMinResolution(10);
if (hasBackground)
shape.setName(GType.formatType(type));
double baseLat = lat + y * ELEMENT_SPACING;
double baseLong = lon + x * ELEMENT_SPACING;
List<Coord> coords = new ArrayList<Coord>();
Coord co = new Coord(baseLat, baseLong);
// pg.addCoord(co);
coords.add(co);
mapper.addToBounds(co);
if (configProps.containsKey("verbose"))
System.out.println("Generated polygon " + GType.formatType(type) + " at " + co.toDegreeString());
co = new Coord(baseLat + ELEMENT_SIZE, baseLong);
coords.add(co);
mapper.addToBounds(co);
co = new Coord(baseLat + ELEMENT_SIZE, baseLong + ELEMENT_SIZE);
coords.add(co);
mapper.addToBounds(co);
co = new Coord(baseLat, baseLong + ELEMENT_SIZE);
coords.add(co);
mapper.addToBounds(co);
coords.add(coords.get(0));
shape.setType(type);
shape.setPoints(coords);
mapper.addShape(shape);
type++;
}
}
}
Aggregations