use of net.osmand.osm.io.OsmStorageWriter in project OsmAnd-tools by osmandapp.
the class FixAdminLevel0 method process.
private static void process(File read, File write) throws IOException, XMLStreamException, XmlPullParserException {
OsmBaseStorage storage = new OsmBaseStorage();
storage.parseOSM(new FileInputStream(read), new ConsoleProgressImplementation());
Map<EntityId, Entity> entities = new HashMap<EntityId, Entity>(storage.getRegisteredEntities());
long id = -1;
for (EntityId e : entities.keySet()) {
Entity es = storage.getRegisteredEntities().get(e);
if (e.getId() < id) {
id = e.getId() - 1;
}
if (e.getType() == EntityType.WAY) {
processWay((Way) es);
}
}
for (String country : countryNames.keySet()) {
List<Way> list = countryNames.get(country);
for (Way w : list) {
LatLon latLon = OsmMapUtils.getMathWeightCenterForNodes(w.getNodes());
// LatLon latLon = w.getLatLon();
Node node = new Node(latLon.getLatitude(), latLon.getLongitude(), id--);
node.putTag("name", country);
node.putTag("place", "country");
storage.getRegisteredEntities().put(EntityId.valueOf(node), node);
}
}
OsmStorageWriter writer = new OsmStorageWriter();
writer.saveStorage(new FileOutputStream(write), storage, null, true);
}
use of net.osmand.osm.io.OsmStorageWriter in project OsmAnd-tools by osmandapp.
the class OceanTilesCreator method createJOSMFile.
public static void createJOSMFile(String[] args) throws XMLStreamException, IOException {
String fileLocation = args.length == 0 ? "oceanTiles.osm" : args[0];
int z = TILE_ZOOMLEVEL;
BasemapProcessor bmp = new BasemapProcessor();
bmp.constructBitSetInfo(args.length > 1 ? args[1] : null);
OsmBaseStorage st = new OsmBaseStorage();
Set<Entity.EntityId> s = new LinkedHashSet();
TLongHashSet nodeIds = new TLongHashSet();
int minzoom = 4;
BasemapProcessor.SimplisticQuadTree quadTree = bmp.constructTilesQuadTree(z);
for (int zm = minzoom; zm <= z; zm++) {
int pz = 1 << zm;
for (int x = 0; x < pz; x++) {
for (int y = 0; y < pz; y++) {
// if((quadTree.getOrCreateSubTree(i, j, z).seaCharacteristic < 0.9 && !bmp.isWaterTile(i, j, z))||
// bmp.isLandTile(i, j, z) ) {
boolean parentWater = bmp.isWaterTile(x >> 1, y >> 1, zm - 1);
boolean parentLand = bmp.isLandTile(x >> 1, y >> 1, zm - 1);
if (zm > minzoom && (parentLand || parentWater)) {
continue;
}
boolean landTile = bmp.isLandTile(x, y, zm);
boolean waterTile = bmp.isWaterTile(x, y, zm);
if (waterTile || landTile) {
Way w = new Way(-getNodeId(x, y, zm));
addNode(w, nodeIds, x, y, zm);
addNode(w, nodeIds, x, y + 1, zm);
addNode(w, nodeIds, x + 1, y + 1, zm);
addNode(w, nodeIds, x + 1, y, zm);
addNode(w, nodeIds, x, y, zm);
if (waterTile) {
w.putTag("natural", "water");
} else if (landTile) {
w.putTag("landuse", "grass");
}
w.putTag("name", x + " " + y + " " + zm + " " + (waterTile ? 1 : 0));
s.addAll(w.getEntityIds());
s.add(Entity.EntityId.valueOf(w));
st.registerEntity(w, null);
}
}
}
}
for (long l : nodeIds.toArray()) {
st.registerEntity(getNode(l), null);
}
new OsmStorageWriter().saveStorage(new FileOutputStream(fileLocation), st, s, true);
}
use of net.osmand.osm.io.OsmStorageWriter in project OsmAnd-tools by osmandapp.
the class AugmentedDiffsInspector method writeFile.
private File writeFile(File targetDir, String prefix, Map<EntityId, Entity> octx, Set<EntityId> oset, Map<EntityId, Entity> nctx, Set<EntityId> nset, long lastModified) throws XMLStreamException, IOException, FileNotFoundException {
List<Node> nodes = new ArrayList<Node>();
List<Way> ways = new ArrayList<Way>();
List<Relation> relations = new ArrayList<Relation>();
groupObjects(octx, oset, nodes, ways, relations);
groupObjects(nctx, nset, nodes, ways, relations);
File f = new File(targetDir, prefix + ".osm.gz");
FileOutputStream fous = new FileOutputStream(f);
GZIPOutputStream gz = new GZIPOutputStream(fous);
new OsmStorageWriter().writeOSM(gz, new HashMap<Entity.EntityId, EntityInfo>(), nodes, ways, relations, true);
gz.close();
fous.close();
f.setLastModified(lastModified);
return f;
}
use of net.osmand.osm.io.OsmStorageWriter in project OsmAnd-tools by osmandapp.
the class GenerateRegionTags method process.
private static void process(File inputFile, File targetFile, OsmandRegions or) throws IOException, XmlPullParserException, XMLStreamException {
InputStream fis = new FileInputStream(inputFile);
if (inputFile.getName().endsWith(".gz")) {
fis = new GZIPInputStream(fis);
} else if (inputFile.getName().endsWith(".bz2")) {
if (fis.read() != 'B' || fis.read() != 'Z') {
throw new RuntimeException(// $NON-NLS-1$
"The source stream must start with the characters BZ if it is to be read as a BZip2 stream.");
}
fis = new CBZip2InputStream(fis);
}
OsmBaseStorage bs = new OsmBaseStorage();
bs.parseOSM(fis, new ConsoleProgressImplementation());
LOG.info("File was read");
iterateOverEntities(bs.getRegisteredEntities(), or);
OsmStorageWriter w = new OsmStorageWriter();
OutputStream output = new FileOutputStream(targetFile);
if (targetFile.getName().endsWith(".gz")) {
output = new GZIPOutputStream(output);
} else if (targetFile.getName().endsWith(".bz2")) {
output.write("BZ".getBytes());
output = new CBZip2OutputStream(output);
}
LOG.info("Entities processed. About to save the file.");
w.saveStorage(output, bs, null, true);
output.close();
fis.close();
}
use of net.osmand.osm.io.OsmStorageWriter in project OsmAnd-tools by osmandapp.
the class FixBasemapRoads method process.
private void process(File read, File write, List<File> relationFiles) throws IOException, XMLStreamException, XmlPullParserException, SQLException {
MapRenderingTypesEncoder renderingTypes = new MapRenderingTypesEncoder("basemap");
OsmandRegions or = prepareRegions();
TagsTransformer transformer = new TagsTransformer();
for (File relFile : relationFiles) {
LOG.info("Parse relations file " + relFile.getName());
OsmBaseStorage storage = parseOsmFile(relFile);
int total = 0;
for (EntityId e : storage.getRegisteredEntities().keySet()) {
if (e.getType() == EntityType.RELATION) {
total++;
if (total % 1000 == 0) {
LOG.info("Processed " + total + " relations");
}
Relation es = (Relation) storage.getRegisteredEntities().get(e);
transformer.handleRelationPropogatedTags(es, renderingTypes, null, EntityConvertApplyType.MAP);
}
}
}
LOG.info("Parse main file " + read.getName());
OsmBaseStorage storage = parseOsmFile(read);
Map<EntityId, Entity> entities = new HashMap<EntityId, Entity>(storage.getRegisteredEntities());
int total = 0;
for (EntityId e : entities.keySet()) {
if (e.getType() == EntityType.WAY) {
Way es = (Way) storage.getRegisteredEntities().get(e);
total++;
if (total % 1000 == 0) {
LOG.info("Processed " + total + " ways");
}
addRegionTag(or, es);
transformer.addPropogatedTags(es);
Map<String, String> ntags = renderingTypes.transformTags(es.getModifiableTags(), EntityType.WAY, EntityConvertApplyType.MAP);
if (es.getModifiableTags() != ntags) {
es.getModifiableTags().putAll(ntags);
}
processWay(es);
}
}
List<EntityId> toWrite = new ArrayList<EntityId>();
processRegion(toWrite);
OsmStorageWriter writer = new OsmStorageWriter();
LOG.info("Writing file... ");
writer.saveStorage(new FileOutputStream(write), storage, toWrite, true);
LOG.info("DONE");
}
Aggregations