Search in sources :

Example 1 with OsmIterator

use of de.topobyte.osm4j.core.access.OsmIterator in project osm4j-pbf by topobyte.

the class Util method iterate.

public static void iterate(File file, boolean fetchMetadata) throws IOException {
    InputStream input = new FileInputStream(file);
    OsmIterator iterator = new PbfIterator(input, fetchMetadata);
    while (iterator.hasNext()) {
        iterator.next();
    }
    input.close();
}
Also used : FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OsmIterator(de.topobyte.osm4j.core.access.OsmIterator) PbfIterator(de.topobyte.osm4j.pbf.seq.PbfIterator) FileInputStream(java.io.FileInputStream)

Example 2 with OsmIterator

use of de.topobyte.osm4j.core.access.OsmIterator in project osm4j-core by topobyte.

the class ListDataSetLoader method read.

public static InMemoryListDataSet read(OsmIteratorInput iteratorInput, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
    OsmIterator iterator = iteratorInput.getIterator();
    InMemoryListDataSet data = read(iterator, keepNodeTags, keepWayTags, keepRelationTags);
    iteratorInput.close();
    return data;
}
Also used : OsmIterator(de.topobyte.osm4j.core.access.OsmIterator)

Example 3 with OsmIterator

use of de.topobyte.osm4j.core.access.OsmIterator in project osm4j-core by topobyte.

the class MapDataSetLoader method read.

public static InMemoryMapDataSet read(OsmIteratorInput iteratorInput, boolean keepNodeTags, boolean keepWayTags, boolean keepRelationTags) throws IOException {
    OsmIterator iterator = iteratorInput.getIterator();
    InMemoryMapDataSet data = read(iterator, keepNodeTags, keepWayTags, keepRelationTags);
    iteratorInput.close();
    return data;
}
Also used : OsmIterator(de.topobyte.osm4j.core.access.OsmIterator)

Example 4 with OsmIterator

use of de.topobyte.osm4j.core.access.OsmIterator in project osm4j-geometry by topobyte.

the class TestBuildLinework method main.

public static void main(String[] args) throws MalformedURLException, IOException, ParserConfigurationException, SAXException, EntityNotFoundException {
    if (args.length == 0) {
        System.out.println("Please specify an input file");
        usage();
    }
    if (args.length != 1) {
        System.out.println("Please specify only one input file");
        usage();
    }
    InputStream input = new FileInputStream(args[0]);
    OsmIterator iterator = new TboIterator(input, true, true);
    InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false, true);
    TLongObjectMap<OsmRelation> relations = data.getRelations();
    if (relations.isEmpty()) {
        logger.warn("No relation found");
        return;
    }
    LineworkBuilder lineworkBuilder = new LineworkBuilder();
    lineworkBuilder.setMissingEntitiesStrategy(MissingEntitiesStrategy.BUILD_PARTIAL);
    lineworkBuilder.setMissingWayNodeStrategy(MissingWayNodeStrategy.SPLIT_POLYLINE);
    RegionBuilder regionBuilder = new RegionBuilder();
    regionBuilder.setMissingEntitiesStrategy(MissingEntitiesStrategy.BUILD_PARTIAL);
    long[] ids = relations.keys();
    Arrays.sort(ids);
    for (long id : ids) {
        OsmRelation relation = relations.get(id);
        logger.info("Relation " + relation.getId());
        lineworkBuilder.build(relation, data);
        regionBuilder.build(relation, data);
    }
}
Also used : InMemoryMapDataSet(de.topobyte.osm4j.core.dataset.InMemoryMapDataSet) TboIterator(de.topobyte.osm4j.tbo.access.TboIterator) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) RegionBuilder(de.topobyte.osm4j.geometry.RegionBuilder) OsmIterator(de.topobyte.osm4j.core.access.OsmIterator) FileInputStream(java.io.FileInputStream) LineworkBuilder(de.topobyte.osm4j.geometry.LineworkBuilder)

Example 5 with OsmIterator

use of de.topobyte.osm4j.core.access.OsmIterator in project osm4j-geometry by topobyte.

the class TestBuildPolygon method main.

public static void main(String[] args) throws MalformedURLException, IOException, ParserConfigurationException, SAXException, EntityNotFoundException {
    String query = "http://overpass-api.de/api/interpreter?data=(rel(8638);>;);out;";
    // Open a stream
    InputStream input = new URL(query).openStream();
    OsmIterator iterator = new OsmXmlIterator(input, false);
    InMemoryMapDataSet data = MapDataSetLoader.read(iterator, false, false, true);
    TLongObjectMap<OsmRelation> relations = data.getRelations();
    if (relations.isEmpty()) {
        System.out.println("No relation found");
        return;
    }
    TLongObjectIterator<OsmRelation> ri = relations.iterator();
    ri.advance();
    OsmRelation relation = ri.value();
    File outputDir = new File("/tmp");
    String filename = String.format("relation-%d.wkt", relation.getId());
    File file = new File(outputDir, filename);
    GeometryBuilder geometryBuilder = new GeometryBuilder();
    geometryBuilder.setMissingEntitiesStrategy(MissingEntitiesStrategy.BUILD_PARTIAL);
    geometryBuilder.setMissingWayNodeStrategy(MissingWayNodeStrategy.OMIT_VERTEX_FROM_POLYLINE);
    Geometry polygon = geometryBuilder.build(relation, data);
    WKTWriter writer = new WKTWriter();
    FileWriter fileWriter = new FileWriter(file);
    writer.write(polygon, fileWriter);
    fileWriter.close();
    System.out.println("Successfully created WKT representation");
}
Also used : WKTWriter(com.vividsolutions.jts.io.WKTWriter) InMemoryMapDataSet(de.topobyte.osm4j.core.dataset.InMemoryMapDataSet) InputStream(java.io.InputStream) OsmRelation(de.topobyte.osm4j.core.model.iface.OsmRelation) FileWriter(java.io.FileWriter) URL(java.net.URL) Geometry(com.vividsolutions.jts.geom.Geometry) OsmXmlIterator(de.topobyte.osm4j.xml.dynsax.OsmXmlIterator) OsmIterator(de.topobyte.osm4j.core.access.OsmIterator) File(java.io.File) GeometryBuilder(de.topobyte.osm4j.geometry.GeometryBuilder)

Aggregations

OsmIterator (de.topobyte.osm4j.core.access.OsmIterator)7 InputStream (java.io.InputStream)5 FileInputStream (java.io.FileInputStream)4 PbfIterator (de.topobyte.osm4j.pbf.seq.PbfIterator)3 InMemoryMapDataSet (de.topobyte.osm4j.core.dataset.InMemoryMapDataSet)2 OsmRelation (de.topobyte.osm4j.core.model.iface.OsmRelation)2 File (java.io.File)2 Geometry (com.vividsolutions.jts.geom.Geometry)1 WKTWriter (com.vividsolutions.jts.io.WKTWriter)1 OsmOutputStream (de.topobyte.osm4j.core.access.OsmOutputStream)1 EntityContainer (de.topobyte.osm4j.core.model.iface.EntityContainer)1 GeometryBuilder (de.topobyte.osm4j.geometry.GeometryBuilder)1 LineworkBuilder (de.topobyte.osm4j.geometry.LineworkBuilder)1 RegionBuilder (de.topobyte.osm4j.geometry.RegionBuilder)1 PbfWriter (de.topobyte.osm4j.pbf.seq.PbfWriter)1 TboIterator (de.topobyte.osm4j.tbo.access.TboIterator)1 OsmXmlIterator (de.topobyte.osm4j.xml.dynsax.OsmXmlIterator)1 FileOutputStream (java.io.FileOutputStream)1 FileWriter (java.io.FileWriter)1 OutputStream (java.io.OutputStream)1