[Osm4j] I can't correctly read a file in pbf format.
Sebastian Kürten
sebastian.kuerten at fu-berlin.de
Thu Nov 28 21:37:03 UTC 2019
Hi Manuel,
I have now found the time to setup an example for you in the
osm4j-examples repository[1]. There's a new example class[2] called
ListRestaurantsInHavana that reads a PBF file from "/tmp/havana.pbf",
iterates all data in it and increments some counters for restaurant
objects it encounters during iteration. It will count all objects that
represent a restaurant and remembers the number of nodes, ways and
relations that represent a restaurant. It also prints all restaurant
names it encounters. After the iteration it will print a summary such
as this:
...
Restaurante Villa Mirador del Mar
Los Leones
La Tabernita
Don Cuba
-Summary-
nodes: 951, ways: 29, relations: 1
no name: 45
Please, download the data for Havana from our test data server[3],
adapt the path in the example (line 38) to point to the location where
you downloaded that file.
If you manage to reproduce the above output, you could adapt the
example again, point to the files you were working with before and see
what happens then. Try if you can access ways and relations then. It is
possible the files you have are broken for some reason or just do not
contain other data than nodes.
Best,
Sebastian
[1] https://github.com/topobyte/osm4j-examples
[2] https://github.com/topobyte/osm4j-examples/blob/master/src/main/java/de/topobyte/osm4j/examples/misc/ListRestaurantsInHavana.java
[3] http://osmtestdata.topobyte.de/havana.pbf
On Thu, 28 Nov 2019 10:15:57 -0500 (CST)
Manuel Enrique Puebla Martinez via Osm4j <osm4j at openstreetmap.org>
wrote:
> Hi:
>
>
> Please... I can't correctly read a file in pbf format. I've been
> doing this for days and I can't solve the problem. This is my code:
>
> 1) java.nio.file.Path input2 =
> Paths.get("E:\\2019-11-17-cuba-latest.osm.pbf"); 2) File file= new
> File(input2.toUri()); 3) InputStream fis = new FileInputStream(file);
> 4) InputStream bis = new BufferedInputStream(fis);
> 5) iterator = OsmIoUtils.setupOsmIterator(bis,
> FileFormat.PBF, true ,true); 6) InMemoryMapDataSet data =
> MapDataSetLoader.read(iterator, true, true,true);
>
>
> However, when you run line 5, the variable "iterator" is empty, see
> the screenshot attached to this email.
>
> I also reviewed the code on this page:
> https://github.com/topobyte/osm4j-utils/blob/master/cli/src/main/java/de/topobyte/osm4j/utils/executables/OsmCount.java
>
> But in that code they use this: "OsmIterator iterator =
> createIterator();", I couldn't find what they do in "createIterator".
>
> With the XML format everything works great for me, but with the pbf I
> can't do it, however I need it, due to the large size of the
> geographical area I'm working with.
>
>
> Greetings, Manuel Puebla.
> 1519-2019: Aniversario 500 de la Villa de San Cristóbal de La Habana
> Por La Habana, lo más grande. #Habana500 #UCIxHabana500
More information about the Osm4j
mailing list