use of uk.me.parabola.imgfmt.app.trergn.Zoom in project mkgmap by openstreetmap.
the class AbstractTestMap method makeMap.
protected void makeMap(String[] args) {
// Default to nowhere in particular.
double lat = 51.724;
double lng = 0.2487;
// Arguments allow you to place the map where ever you wish.
if (args.length > 1) {
lat = Double.valueOf(args[0]);
lng = Double.valueOf(args[1]);
}
log.debug("this is a test make map program. Start", lat, '/', lng);
FileSystemParam params = new FileSystemParam();
params.setBlockSize(512);
params.setMapDescription("OSM street map");
Map map;
try {
map = Map.createMap("32860003", ".", params, "32860003", SrtTextReader.sortForCodepage(1252));
} catch (FileExistsException e) {
throw new ExitException("File exists already", e);
} catch (FileNotWritableException e) {
throw new ExitException("Could not create or write file", e);
}
map.addInfo("Program released under the GPL");
map.addInfo("This map data is made available under the Open Database License:");
// There has to be (at least) two copyright messages or else the map
// does not show up. The second one will be displayed at startup,
// although the conditions where that happens are not known.
map.addCopyright("program licenced under GPL v2");
// This one gets shown when you switch on, so put the actual
// map copyright here. This is made up data, so no copyright applies.
map.addCopyright("No copyright");
Area area = new Area(lat, lng, lat + 1, lng + 1);
map.setBounds(area);
// There must always be an empty zoom level at the least detailed level.
log.info("area " + area);
log.info(" or " + lat + '/' + lng);
Zoom z1 = map.createZoom(1, 24);
Subdivision topdiv = map.topLevelSubdivision(area, z1);
// Create a most detailed view
Zoom z = map.createZoom(0, 24);
Subdivision div = map.createSubdivision(topdiv, area, z);
div.startDivision();
drawTestMap(map, div, lat, lng);
map.close();
}
use of uk.me.parabola.imgfmt.app.trergn.Zoom in project mkgmap by openstreetmap.
the class OverviewBuilder method readPoints.
/**
* Read the points from the .img file and add them to the overview map.
* We read from the least detailed level (apart from the empty one).
*
* @param mapReader Map reader on the detailed .img file.
*/
private void readPoints(MapReader mapReader) {
Area bounds = overviewSource.getBounds();
Zoom[] levels = mapReader.getLevels();
for (int l = 1; l < levels.length; l++) {
int min = levels[l].getLevel();
int res = levels[l].getResolution();
List<Point> pointList = mapReader.pointsForLevel(min, MapReader.WITH_EXT_TYPE_DATA);
for (Point point : pointList) {
if (log.isDebugEnabled())
log.debug("got point", point);
if (bounds.contains(point.getLocation()) == false) {
if (log.isDebugEnabled())
log.debug(point, "dropped, is outside of tile boundary");
continue;
}
MapPoint mp = new MapPoint();
mp.setType(point.getType());
if (point.getLabel() != null) {
mp.setName(point.getLabel().getText());
}
mp.setMaxResolution(res);
mp.setMinResolution(res);
mp.setLocation(point.getLocation());
overviewSource.addPoint(mp);
}
}
}
use of uk.me.parabola.imgfmt.app.trergn.Zoom in project mkgmap by openstreetmap.
the class OverviewBuilder method readShapes.
/**
* Read the polygons from the .img file and add them to the overview map.
* We read from the least detailed level (apart from the empty one).
*
* @param mapReader Map reader on the detailed .img file.
*/
private void readShapes(MapReader mapReader) {
Zoom[] levels = mapReader.getLevels();
for (int l = 1; l < levels.length; l++) {
int min = levels[l].getLevel();
int res = levels[l].getResolution();
List<Polygon> list = mapReader.shapesForLevel(min, MapReader.WITH_EXT_TYPE_DATA);
for (Polygon shape : list) {
if (log.isDebugEnabled())
log.debug("got polygon", shape);
if (shape.getType() == 0x4b) {
hasBackground = true;
}
MapShape ms = new MapShape();
List<Coord> points = shape.getPoints();
if (log.isDebugEnabled())
log.debug("polygon point list", points);
if (points.size() < 3)
continue;
ms.setType(shape.getType());
if (shape.getLabel() != null)
ms.setName(shape.getLabel().getText());
ms.setMaxResolution(res);
ms.setMinResolution(res);
ms.setPoints(points);
overviewSource.addShape(ms);
}
}
}
use of uk.me.parabola.imgfmt.app.trergn.Zoom in project mkgmap by openstreetmap.
the class MapBuilder method makeMapAreas.
/**
* Drive the map generation by stepping through the levels, generating the
* subdivisions for the level and filling in the map elements that should
* go into the area.
*
* This is fairly complex: you need to divide into subdivisions depending on
* their size and the number of elements that will be contained.
*
* @param map The map.
* @param src The data for the map.
*/
private void makeMapAreas(Map map, LoadableMapDataSource src) {
// The top level has to cover the whole map without subdividing, so
// do a special check to make sure.
LevelInfo[] levels = null;
if (src instanceof OverviewMapDataSource) {
mergeLines = true;
prepShapesForMerge(src.getShapes());
mergeShapes = true;
levels = src.mapLevels();
} else {
if (OverviewBuilder.isOverviewImg(map.getFilename())) {
levels = src.overviewMapLevels();
} else {
levels = src.mapLevels();
}
}
if (levels == null) {
throw new ExitException("no info about levels available.");
}
LevelInfo levelInfo = levels[0];
// If there is already a top level zoom, then we shouldn't add our own
Subdivision topdiv;
if (levelInfo.isTop()) {
// There is already a top level definition. So use the values from it and
// then remove it from the levels definition.
levels = Arrays.copyOfRange(levels, 1, levels.length);
Zoom zoom = map.createZoom(levelInfo.getLevel(), levelInfo.getBits());
topdiv = makeTopArea(src, map, zoom);
} else {
// We have to automatically create the definition for the top zoom level.
int maxBits = getMaxBits(src);
// decrease it so that it is less.
if (levelInfo.getBits() <= maxBits)
maxBits = levelInfo.getBits() - 1;
// Create the empty top level
Zoom zoom = map.createZoom(levelInfo.getLevel() + 1, maxBits);
topdiv = makeTopArea(src, map, zoom);
}
// We start with one map data source.
List<SourceSubdiv> srcList = Collections.singletonList(new SourceSubdiv(src, topdiv));
// Now the levels filled with features.
for (LevelInfo linfo : levels) {
List<SourceSubdiv> nextList = new ArrayList<>();
Zoom zoom = map.createZoom(linfo.getLevel(), linfo.getBits());
for (SourceSubdiv srcDivPair : srcList) {
MapSplitter splitter = new MapSplitter(srcDivPair.getSource(), zoom);
MapArea[] areas = splitter.split(orderByDecreasingArea);
log.info("Map region", srcDivPair.getSource().getBounds(), "split into", areas.length, "areas at resolution", zoom.getResolution());
for (MapArea area : areas) {
Subdivision parent = srcDivPair.getSubdiv();
Subdivision div = makeSubdivision(map, parent, area, zoom);
if (log.isDebugEnabled())
log.debug("ADD parent-subdiv", parent, srcDivPair.getSource(), ", z=", zoom, " new=", div);
nextList.add(new SourceSubdiv(area, div));
}
if (nextList.size() > 0) {
Subdivision lastdiv = nextList.get(nextList.size() - 1).getSubdiv();
lastdiv.setLast(true);
}
}
srcList = nextList;
}
}
use of uk.me.parabola.imgfmt.app.trergn.Zoom in project mkgmap by openstreetmap.
the class OverviewBuilder method readFileIntoOverview.
/**
* Add an individual .img file to the overview map.
*
* @param finfo Information about an individual map.
*/
private void readFileIntoOverview(FileInfo finfo) throws FileNotFoundException {
addMapCoverageArea(finfo);
MapReader mapReader = null;
String filename = finfo.getFilename();
if (codepage == null) {
codepage = finfo.getCodePage();
}
if (codepage != finfo.getCodePage()) {
System.err.println("WARNING: input file " + filename + " has different code page " + finfo.getCodePage());
}
try {
mapReader = new MapReader(filename);
if (encodingType == null) {
encodingType = mapReader.getEncodingType();
}
if (encodingType != mapReader.getEncodingType()) {
System.err.println("WARNING: input file " + filename + " has different charset type " + encodingType);
}
String[] msgs = mapReader.getCopyrights();
boolean found = false;
for (String[] block : copyrightMsgs) {
if (Arrays.deepEquals(block, msgs)) {
found = true;
break;
}
}
if (!found)
copyrightMsgs.add(msgs);
msgs = finfo.getLicenseInfo();
found = false;
for (String[] block : licenseInfos) {
if (Arrays.deepEquals(block, msgs)) {
found = true;
break;
}
}
if (!found)
licenseInfos.add(msgs);
Zoom[] levels = mapReader.getLevels();
if (wantedLevels == null) {
LevelInfo[] mapLevels;
if (isOverviewImg(filename)) {
mapLevels = new LevelInfo[levels.length - 1];
for (int i = 1; i < levels.length; i++) {
mapLevels[i - 1] = new LevelInfo(levels[i].getLevel(), levels[i].getResolution());
}
} else {
mapLevels = new LevelInfo[1];
mapLevels[0] = new LevelInfo(levels[1].getLevel(), levels[1].getResolution());
}
wantedLevels = mapLevels;
}
if (isOverviewImg(filename)) {
readPoints(mapReader);
readLines(mapReader);
readShapes(mapReader);
}
} catch (FileNotFoundException e) {
throw new ExitException("Could not open " + filename + " when creating overview file");
} finally {
Utils.closeFile(mapReader);
}
}
Aggregations