use of net.osmand.osm.io.OsmBaseStorage 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.OsmBaseStorage in project OsmAnd-tools by osmandapp.
the class OceanTilesCreator method createTilesFile.
public static void createTilesFile(String coastlinesInput, String result) throws IOException, XmlPullParserException {
if (result == null) {
result = "oceantiles_12.dat";
}
File readFile = new File(coastlinesInput);
InputStream stream = new BufferedInputStream(new FileInputStream(readFile), 8192 * 4);
InputStream streamFile = stream;
long st = System.currentTimeMillis();
if (readFile.getName().endsWith(".bz2")) {
// $NON-NLS-1$
if (stream.read() != 'B' || stream.read() != 'Z') {
// throw new RuntimeException("The source stream must start with the characters BZ if it is to be read as a BZip2 stream."); //$NON-NLS-1$
} else {
stream = new CBZip2InputStream(stream);
}
}
OsmBaseStorage bs = new OsmBaseStorage();
bs.parseOSM(stream, IProgress.EMPTY_PROGRESS);
int c = 0;
int ns = 0;
TLongObjectHashMap<OceanTileInfo> map = new TLongObjectHashMap<OceanTileInfo>();
for (Entity e : bs.getRegisteredEntities().values()) {
if (e instanceof Way) {
Way w = (Way) e;
List<Node> nodes = w.getNodes();
for (int i = 1; i < nodes.size(); i++) {
double tx = MapUtils.getTileNumberX(TILE_ZOOMLEVEL, nodes.get(i).getLongitude());
double ty = MapUtils.getTileNumberY(TILE_ZOOMLEVEL, nodes.get(i).getLatitude());
double px = MapUtils.getTileNumberX(TILE_ZOOMLEVEL, nodes.get(i - 1).getLongitude());
double py = MapUtils.getTileNumberY(TILE_ZOOMLEVEL, nodes.get(i - 1).getLatitude());
for (int x = (int) Math.min(tx, px); x <= Math.max(tx, px); x++) {
for (int y = (int) Math.min(ty, py); y <= Math.max(ty, py); y++) {
// check if intersects (x-1,y+0.5) & (x,y+0.5)
long key = ((long) x << TILE_ZOOMLEVEL) + (long) y;
if (intersect2Segments(tx, ty, px, py, x, y + 0.5d, x + 1, y + 0.5d)) {
getOrCreate(map, key).linesIntersectMedian++;
getOrCreate(map, key).type = OceanTileInfo.MIXED;
} else if (intersect2Segments(tx, ty, px, py, x, y, x + 1, y)) {
getOrCreate(map, key).type = OceanTileInfo.MIXED;
} else if (intersect2Segments(tx, ty, px, py, x, y + 1, x + 1, y + 1)) {
getOrCreate(map, key).type = OceanTileInfo.MIXED;
} else if (intersect2Segments(tx, ty, px, py, x, y, x, y + 1)) {
getOrCreate(map, key).type = OceanTileInfo.MIXED;
} else if (intersect2Segments(tx, ty, px, py, x + 1, y, x + 1, y + 1)) {
getOrCreate(map, key).type = OceanTileInfo.MIXED;
}
}
}
}
c++;
ns += w.getNodeIds().size();
}
}
writeResult(map, result);
System.out.println(c + " " + ns + " coastlines " + map.size());
}
use of net.osmand.osm.io.OsmBaseStorage 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.OsmBaseStorage 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.OsmBaseStorage in project OsmAnd-tools by osmandapp.
the class MultipolygonFileTest method testDifferentOrientationMultipolygon.
@Test
public void testDifferentOrientationMultipolygon() throws IOException, XmlPullParserException {
String file = "multipolygon.osm";
OsmBaseStorage st = parse(file);
Multipolygon polygon = buildPolygon(st, 1184817L);
assertTrue(polygon.areRingsComplete());
assertEquals(1, polygon.getOuterRings().size());
Ring rng = polygon.getOuterRings().get(0);
assertTrue(rng.containsPoint(53.17573, 8.26));
assertTrue(rng.containsPoint(53.18901289819956, 8.296700487828224));
assertFalse(rng.containsPoint(53.1863199155393, 8.309607569738336));
assertFalse(rng.containsPoint(53.13992097340422, 8.280586804995954));
}
Aggregations