use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.
the class TypCompiler method compile.
/**
* Read and compile a TYP file, returning the compiled form.
*
* @param filename The input filename.
* @param charset The character set to use to read this file. We should have already determined
* that this character set is valid and can be used to read the file.
* @param sort The sort information from command line options, used for the output code page
* only. If null, then the code page set by CodePage in the typ.txt file will be used.
*
* @return The compiled form as a data structure.
* @throws FileNotFoundException If the file doesn't exist.
* @throws SyntaxException All user correctable problems in the input file.
*/
private TypData compile(String filename, String charset, Sort sort) throws FileNotFoundException, SyntaxException {
TypTextReader tr = new TypTextReader();
TypData data = tr.getData();
data.setSort(sort);
try {
Reader r = new BufferedReader(new InputStreamReader(new FileInputStream(filename), charset));
try {
tr.read(filename, r);
} finally {
Utils.closeFile(r);
}
} catch (UnsupportedEncodingException e) {
// Not likely to happen as we should have already used this character set!
throw new MapFailedException("Unsupported character set", e);
}
return tr.getData();
}
use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.
the class LBLFile method newLabel.
/**
* Add a new label with the given text. Labels are shared, so that identical
* text is always represented by the same label.
*
* @param text The text of the label, it will be in uppercase.
* @return A reference to the created label.
*/
public Label newLabel(String text) {
EncodedText encodedText = textEncoder.encodeText(text);
Label l = labelCache.get(encodedText);
if (l == null) {
l = new Label(encodedText.getChars());
labelCache.put(encodedText, l);
l.setOffset(getNextLabelOffset());
if (encodedText.getLength() > 0)
getWriter().put(encodedText.getCtext(), 0, encodedText.getLength());
alignForNext();
if (l.getOffset() > 0x3fffff)
throw new MapFailedException("Overflow of LBL section");
}
return l;
}
use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.
the class Area method split.
/**
* Split this area up into a number of smaller areas.
*
* @param xsplit The number of pieces to split this area into in the x
* direction.
* @param ysplit The number of pieces to split this area into in the y
* direction.
* @param resolutionShift round to this power of 2.
* @return An array containing xsplit*ysplit areas or null if can't split in half.
* @throws MapFailedException if more complex split operation couldn't be honoured.
*/
public Area[] split(int xsplit, int ysplit, int resolutionShift) {
Area[] areas = new Area[xsplit * ysplit];
int xstart;
int xend;
int ystart;
int yend;
int nAreas = 0;
xstart = minLong;
for (int x = 0; x < xsplit; x++) {
if (x == xsplit - 1)
xend = maxLong;
else
xend = roundPof2(xstart + (maxLong - xstart) / (xsplit - x), resolutionShift);
ystart = minLat;
for (int y = 0; y < ysplit; y++) {
if (y == ysplit - 1)
yend = maxLat;
else
yend = roundPof2(ystart + (maxLat - ystart) / (ysplit - y), resolutionShift);
if (xstart < xend && ystart < yend) {
Area a = new Area(ystart, xstart, yend, xend);
// log.debug(x, y, a);
log.debug("Area.split", minLat, minLong, maxLat, maxLong, "res", resolutionShift, "to", ystart, xstart, yend, xend);
areas[nAreas++] = a;
} else
log.warn("Area.split", minLat, minLong, maxLat, maxLong, "res", resolutionShift, "can't", xsplit, ysplit);
ystart = yend;
}
xstart = xend;
}
if (// no problem
nAreas == areas.length)
return areas;
else // beware - MapSplitter.splitMaxSize requests split of 1/1 if the original area wasn't too big
if (// failed to split in half
nAreas == 1)
return null;
else if (areas.length == 1 && areas[0] == null)
return null;
else
throw new MapFailedException("Area split shift align problems");
}
use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.
the class BufferedImgFileWriter method ensureSize.
/**
* Make sure there is enough room for the data we are about to write.
*
* @param length The amount of data.
*/
private void ensureSize(int length) {
int needed = buf.position() + length;
if (needed > (bufferSize - GUARD_SIZE)) {
while (needed > (bufferSize - GUARD_SIZE)) bufferSize += GROW_SIZE;
if (bufferSize > maxAllowedSize) {
// up with something that is strictly true in all situations.
throw new MapFailedException("There is not enough room in a single garmin map for all the input data." + " The .osm file should be split into smaller pieces first.");
}
ByteBuffer newb = ByteBuffer.allocate(bufferSize);
newb.order(ByteOrder.LITTLE_ENDIAN);
buf.flip();
newb.put(buf);
buf = newb;
}
}
use of uk.me.parabola.imgfmt.MapFailedException in project mkgmap by openstreetmap.
the class FileBackedImgFileWriter method putInt.
/**
* Write out 4 byte value.
*
* @param val The value to write.
*/
public void putInt(int val) {
try {
file.write(val);
file.write(val >> 8);
file.write(val >> 16);
file.write(val >> 24);
} catch (IOException e) {
throw new MapFailedException("could not write int to mdr tmp file");
}
}
Aggregations