use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.
the class MapMaker method makeMap.
public String makeMap(CommandArgs args, String filename) {
try {
LoadableMapDataSource src = loadFromFile(args, filename);
sort = args.getSort();
if (createOverviewFiles) {
if (src.overviewMapLevels() != null) {
makeMap(args, src, OverviewBuilder.OVERVIEW_PREFIX);
} else {
String fname = OverviewBuilder.getOverviewImgName(args.getMapname());
File f = new File(fname);
if (f.exists()) {
if (f.isFile())
f.delete();
else {
// TODO: error message ?
}
}
}
}
return makeMap(args, src, "");
} catch (FormatException e) {
System.err.println("Bad file format: " + filename);
System.err.println(e.getMessage());
return filename;
} catch (FileNotFoundException e) {
System.err.println("Could not open file: " + filename);
return filename;
}
}
use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.
the class StyleTester method runTest.
private static void runTest(String stylefile, String mapfile) {
PrintingMapCollector collector = new PrintingMapCollector();
OsmConverter normal;
try {
normal = new StyleTester(stylefile, collector, reference);
} catch (FileNotFoundException e) {
System.err.println("Could not open style file " + stylefile);
return;
}
try {
InputStream is = Utils.openFile(mapfile);
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setXIncludeAware(true);
parserFactory.setNamespaceAware(true);
SAXParser parser = parserFactory.newSAXParser();
try {
EnhancedProperties props = new EnhancedProperties();
props.put("preserve-element-order", "1");
ElementSaver saver = new ElementSaver(props);
OsmXmlHandler handler = new OsmXmlHandler();
SaxHandler saxHandler = handler.new SaxHandler();
handler.setElementSaver(saver);
parser.parse(is, saxHandler);
saver.finishLoading();
saver.convert(normal);
System.err.println("Conversion time " + (System.currentTimeMillis() - collector.getStart()) + "ms");
} catch (IOException e) {
throw new FormatException("Error reading file", e);
}
} catch (SAXException e) {
throw new FormatException("Error parsing file", e);
} catch (ParserConfigurationException e) {
throw new FormatException("Internal error configuring xml parser", e);
} catch (FileNotFoundException e) {
System.err.println("Cannot open file " + mapfile);
}
}
use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.
the class BoundaryUtil method loadQuadTreeFromStream.
/**
* Create and fill a BoundaryQuadTree. Read the header of the stream to detect
* the proper reading routine for the different supported formats.
* @param stream an already opened InputStream
* @param fname the file name of the corresponding *.bnd file
* @param searchBbox a bounding box or null. If not null, area info outside of this
* bounding box is ignored.
* @param props properties to be used or null
* @return on success it returns a new BoundaryQuadTree, else null
* @throws IOException
*/
private static BoundaryQuadTree loadQuadTreeFromStream(InputStream stream, String fname, uk.me.parabola.imgfmt.app.Area searchBbox, EnhancedProperties props) throws IOException {
BoundaryQuadTree bqt = null;
uk.me.parabola.imgfmt.app.Area qtBbox = getBbox(fname);
try (DataInputStream inpStream = new DataInputStream(new BufferedInputStream(stream, 1024 * 1024))) {
try {
// 1st read the mkgmap release the boundary file is created by
String mkgmapRel = "?";
String firstId = inpStream.readUTF();
if ("BND".equals(firstId) == false) {
throw new FormatException("Unsupported boundary data type " + firstId);
}
int format = UNKNOWN_DATA_FORMAT;
long createTime = inpStream.readLong();
int headerLength = inpStream.readInt();
byte[] header = new byte[headerLength];
int bytesRead = 0;
while (bytesRead < headerLength) {
int nBytes = inpStream.read(header, bytesRead, headerLength - bytesRead);
if (nBytes < 0) {
throw new IOException("Cannot read header with size " + headerLength);
}
bytesRead += nBytes;
}
ByteArrayInputStream rawHeaderStream = new ByteArrayInputStream(header);
DataInputStream headerStream = new DataInputStream(rawHeaderStream);
String dataFormat = (rawHeaderStream.available() > 0 ? headerStream.readUTF() : "RAW");
int recordVersion = (rawHeaderStream.available() > 0 ? headerStream.readInt() : RAW_DATA_FORMAT_V1);
mkgmapRel = (rawHeaderStream.available() > 0 ? headerStream.readUTF() : "unknown");
if ("RAW".equals(dataFormat) && recordVersion == 1)
format = RAW_DATA_FORMAT_V1;
else if ("QUADTREE".equals(dataFormat) && recordVersion == 1)
format = QUADTREE_DATA_FORMAT_V1;
if (log.isDebugEnabled()) {
log.debug("File created by mkgmap release", mkgmapRel, "at", new Date(createTime));
}
switch(format) {
case QUADTREE_DATA_FORMAT_V1:
bqt = new BoundaryQuadTree(inpStream, qtBbox, searchBbox, props);
break;
case RAW_DATA_FORMAT_V1:
List<Boundary> boundaryList = readStreamRawFormat(inpStream, fname, searchBbox);
if (boundaryList == null || boundaryList.isEmpty())
return null;
boundaryList = mergePostalCodes(boundaryList);
bqt = new BoundaryQuadTree(qtBbox, boundaryList, props);
break;
default:
throw new FormatException("Unsupported boundary file format: " + format);
}
} catch (EOFException exp) {
// it's always thrown at the end of the file
// log.error("Got EOF at the end of the file");
} catch (FormatException exp) {
log.error("Failed to read boundary file " + fname + " " + exp.getMessage());
}
}
return bqt;
}
use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.
the class PolishMapDataSource method load.
@Override
public void load(String name, boolean addBackground) throws FileNotFoundException, FormatException {
Reader reader;
try {
reader = new InputStreamReader(Utils.openFile(name), READING_CHARSET);
} catch (UnsupportedEncodingException e) {
// Java is required to support iso-8859-1 so this is unlikely
throw new FormatException("Unrecognised charset " + READING_CHARSET);
}
// If no code page is given then we read labels in utf-8
dec = Charset.forName("utf-8").newDecoder();
dec.onUnmappableCharacter(CodingErrorAction.REPLACE);
BufferedReader in = new BufferedReader(reader);
try {
String line;
while ((line = in.readLine()) != null) {
++lineNo;
line = line.trim();
if (line.isEmpty() || line.charAt(0) == ';')
continue;
if (line.toUpperCase().startsWith("[END"))
endSection();
else if (line.charAt(0) == '[')
sectionStart(line);
else
processLine(line);
}
// Add all restrictions to the map after reading the full map.
// The reason being, the restrictions section appear in the beginning of the map.
// All the nodes will only be read later on.
// Required to pass the road helper instance as it contains all node data.
restrictionHelper.processAndAddRestrictions(roadHelper, mapper);
} catch (IOException e) {
throw new FormatException("Reading file failed", e);
}
if (addBackground && !havePolygon4B)
addBackground();
coordMap = null;
}
use of uk.me.parabola.imgfmt.FormatException in project mkgmap by openstreetmap.
the class Rgb method write.
public void write(ImgFileWriter writer, byte type) {
if (type != 0x10)
throw new FormatException("Invalid color deep");
writer.put((byte) b);
writer.put((byte) g);
writer.put((byte) r);
}
Aggregations