use of uk.me.parabola.mkgmap.osmstyle.StyleImpl in project mkgmap by openstreetmap.
the class Main method readOneStyle.
/**
* Try to read a style from styleFile directory
* @param name name of the style
* @param performChecks perform checks?
* @return the style or null in case of errors
*/
private Style readOneStyle(String name, boolean performChecks) {
searchedStyleName = name;
Style style = null;
try {
style = new StyleImpl(styleFile, name, new EnhancedProperties(), performChecks);
} catch (SyntaxException e) {
System.err.println("Error in style: " + e.getMessage());
} catch (FileNotFoundException e) {
log.debug("could not find style", name);
try {
searchedStyleName = new File(styleFile).getName();
style = new StyleImpl(styleFile, null, new EnhancedProperties(), performChecks);
} catch (SyntaxException e1) {
System.err.println("Error in style: " + e1.getMessage());
} catch (FileNotFoundException e1) {
log.debug("could not find style", styleFile);
}
}
return style;
}
use of uk.me.parabola.mkgmap.osmstyle.StyleImpl in project mkgmap by openstreetmap.
the class SeaGenerator method init.
/**
* Sort out options from the command line.
* Returns true only if the option to generate the sea is active, so that
* the whole thing is omitted if not used.
*/
public boolean init(ElementSaver saver, EnhancedProperties props) {
this.saver = saver;
String precompSea = props.getProperty("precomp-sea", null);
if (precompSea != null) {
precompSeaDir = new File(precompSea);
if (precompSeaDir.exists()) {
if (precompIndex.get() == null) {
PrecompData precompData = null;
String internalPath = null;
InputStream indexStream = null;
String indexFileName = "index.txt.gz";
ZipFile zipFile = null;
try {
if (precompSeaDir.isDirectory()) {
File indexFile = new File(precompSeaDir, indexFileName);
if (indexFile.exists() == false) {
// check if the unzipped index file exists
indexFileName = "index.txt";
indexFile = new File(precompSeaDir, indexFileName);
}
if (indexFile.exists()) {
indexStream = new FileInputStream(indexFile);
}
} else if (precompSea.endsWith(".zip")) {
zipFile = new ZipFile(precompSeaDir);
internalPath = "sea/";
ZipEntry entry = zipFile.getEntry(internalPath + indexFileName);
if (entry == null) {
indexFileName = "index.txt";
entry = zipFile.getEntry(internalPath + indexFileName);
}
if (entry == null) {
internalPath = "";
indexFileName = "index.txt.gz";
entry = zipFile.getEntry(internalPath + indexFileName);
}
if (entry != null) {
indexStream = zipFile.getInputStream(entry);
} else
log.error("Don't know how to read " + precompSeaDir);
} else {
log.error("Don't know how to read " + precompSeaDir);
}
if (indexStream != null) {
if (indexFileName.endsWith(".gz")) {
indexStream = new GZIPInputStream(indexStream);
}
precompData = loadIndex(indexStream);
if (precompData != null) {
if (zipFile != null) {
precompData.precompZipFileInternalPath = internalPath;
precompData.zipFile = zipFile;
}
precompIndex.set(precompData);
}
indexStream.close();
}
} catch (IOException exp) {
log.error("Cannot read index file", indexFileName, "in", precompSea, exp);
// exp.printStackTrace();
throw new ExitException("Failed to read required index file in " + precompSeaDir);
}
precompIndex.set(precompData);
}
} else {
log.error("Directory or zip file with precompiled sea does not exist: " + precompSea);
System.err.println("Directory or zip file with precompiled sea does not exist: " + precompSea);
precompSeaDir = null;
}
}
String gs = props.getProperty("generate-sea", null);
boolean generateSea = gs != null || precompSea != null;
if (gs != null) {
for (String o : gs.split(",")) {
if ("no-mp".equals(o) || "polygon".equals(o) || "polygons".equals(o))
generateSeaUsingMP = false;
else if ("multipolygon".equals(o))
generateSeaUsingMP = true;
else if (o.startsWith("land-tag="))
landTag = o.substring(9).split("=");
else if (precompSea == null) {
// the other options are valid only if not using precompiled sea data
if (o.startsWith("close-gaps="))
maxCoastlineGap = (int) Double.parseDouble(o.substring(11));
else if ("no-sea-sectors".equals(o))
allowSeaSectors = false;
else if ("extend-sea-sectors".equals(o)) {
allowSeaSectors = false;
extendSeaSectors = true;
} else if ("floodblocker".equals(o))
floodblocker = true;
else if (o.startsWith("fbgap="))
fbGap = (int) Double.parseDouble(o.substring("fbgap=".length()));
else if (o.startsWith("fbratio="))
fbRatio = Double.parseDouble(o.substring("fbratio=".length()));
else if (o.startsWith("fbthres="))
fbThreshold = (int) Double.parseDouble(o.substring("fbthres=".length()));
else if ("fbdebug".equals(o))
fbDebug = true;
else {
printOptionHelpMsg(precompSea != null, o);
}
} else if (o.isEmpty())
continue;
else {
printOptionHelpMsg(precompSea != null, o);
}
}
// if precompSea is not set
if (precompSea == null) {
if (floodblocker) {
try {
fbRules = new StyleImpl(null, "floodblocker");
} catch (FileNotFoundException e) {
log.error("Cannot load file floodblocker rules. Continue floodblocking disabled.");
floodblocker = false;
}
}
String coastlineFileOpt = props.getProperty("coastlinefile", null);
if (coastlineFileOpt != null) {
coastlineFilenames = coastlineFileOpt.split(",");
CoastlineFileLoader.getCoastlineLoader().setCoastlineFiles(coastlineFilenames);
CoastlineFileLoader.getCoastlineLoader().loadCoastlines();
log.info("Coastlines loaded");
} else {
coastlineFilenames = null;
}
}
}
return generateSea;
}
Aggregations