-
-
Save Marc-marc-marc/eeb3f1ec799143d63dc6e7e6ac2f7d15 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package se.kodapan.osm.prerender; | |
import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream; | |
import se.kodapan.osm.domain.Node; | |
import se.kodapan.osm.domain.Relation; | |
import se.kodapan.osm.domain.Way; | |
import se.kodapan.osm.parser.xml.streaming.StreamingOsmXmlParser; | |
import se.kodapan.osm.parser.xml.streaming.StreamingOsmXmlParserListener; | |
import se.kodapan.osm.util.slippymap.Tile; | |
import se.kodapan.osm.util.slippymap.TileVisitor; | |
import se.kodapan.osm.util.slippymap.XYZ; | |
import java.io.*; | |
import java.util.*; | |
public class PreRenderTilesGatherer { | |
public static void main(String[] args) throws Exception { | |
extractPlaces(new File("data/extracted-places.osm.xml")); | |
} | |
public static void extractPlaces(File osmFile) throws Exception { | |
File outputFile = new File(osmFile.getParent(), osmFile.getName() + ".places-tiles.txt"); | |
XYZ slippymap = new XYZ(); | |
Set<Tile> tiles = new LinkedHashSet<>(500000); | |
StreamingOsmXmlParser parser = StreamingOsmXmlParser.newInstance(); | |
try { | |
parser.read(new InputStreamReader(new FileInputStream(osmFile), "UTF8"), new StreamingOsmXmlParserListener() { | |
@Override | |
public void processParsedNode(Node node) { | |
if (node.getTag("place") != null) { | |
for (int z = 1; z < 18; z++) { | |
Tile tile = slippymap.tileFactory(node.getLongitude(), node.getLatitude(), z); | |
tiles.add(tile); | |
} | |
} | |
} | |
@Override | |
public void processParsedWay(Way way) { | |
throw new RuntimeException("Breaking out"); // todo bbox, but the nodes here are only refs | |
} | |
@Override | |
public void processParsedRelation(Relation relation) { | |
throw new RuntimeException("Breaking out"); // todo bbox, but the items here are only refs | |
} | |
}); | |
} catch (Exception e) { | |
e.printStackTrace(); | |
} | |
System.out.println("Writing"); | |
Writer out = new OutputStreamWriter(new FileOutputStream(outputFile), "UTF8"); | |
for(Tile tile : tiles) { | |
out.write(String.valueOf(tile.getX())); | |
out.write("\t"); | |
out.write(String.valueOf(tile.getY())); | |
out.write("\t"); | |
out.write(String.valueOf(tile.getZ())); | |
out.write("\n"); | |
} | |
out.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment