} else {
GraphDatabaseService db = new GraphDatabaseFactory().newEmbeddedDatabase((new File(args[0])).getAbsolutePath());
SpatialDatabaseService spatial = new SpatialDatabaseService(db);
OSMLayer layer = (OSMLayer) spatial.getLayer(args[2]);
if (layer != null) {
ShapefileExporter exporter = new ShapefileExporter(db);
exporter.setExportDir(args[1]+File.separator+layer.getName());
for (int i = 3; i < args.length; i++) {
String[] fields = args[i].split("[\\.\\-]");
HashMap<String, String> tags = new HashMap<String, String>();
String key = fields[0];
String name = key;
if (fields.length > 1) {
String value = fields.length > 1 ? fields[1] : null;
name = key + "-" + value;
tags.put(key, value);
}
try {
if (layer.getLayerNames().contains(name)) {
System.out.println("Exporting previously existing layer: "+name);
exporter.exportLayer(name);
} else {
System.out.println("Creating and exporting new layer: "+name);
layer.addDynamicLayerOnWayTags(name, Constants.GTYPE_LINESTRING, tags);
exporter.exportLayer(name);
}
} catch (Exception e) {
System.err.println("Failed to export dynamic layer " + name + ": " + e);
e.printStackTrace(System.err);
}