Search in sources :

Example 1 with StyleImpl

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;
}
Also used : EnhancedProperties(uk.me.parabola.util.EnhancedProperties) StyleImpl(uk.me.parabola.mkgmap.osmstyle.StyleImpl) SyntaxException(uk.me.parabola.mkgmap.scan.SyntaxException) FileNotFoundException(java.io.FileNotFoundException) Style(uk.me.parabola.mkgmap.reader.osm.Style) File(java.io.File)

Example 2 with StyleImpl

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;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) ZipEntry(java.util.zip.ZipEntry) FileNotFoundException(java.io.FileNotFoundException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) ZipFile(java.util.zip.ZipFile) StyleImpl(uk.me.parabola.mkgmap.osmstyle.StyleImpl) ZipFile(java.util.zip.ZipFile) File(java.io.File) ExitException(uk.me.parabola.imgfmt.ExitException)

Aggregations

File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 StyleImpl (uk.me.parabola.mkgmap.osmstyle.StyleImpl)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 ZipEntry (java.util.zip.ZipEntry)1 ZipFile (java.util.zip.ZipFile)1 ExitException (uk.me.parabola.imgfmt.ExitException)1 Style (uk.me.parabola.mkgmap.reader.osm.Style)1 SyntaxException (uk.me.parabola.mkgmap.scan.SyntaxException)1 EnhancedProperties (uk.me.parabola.util.EnhancedProperties)1