Giter Club home page Giter Club logo

osmonaut's Introduction

This project is unmaintained in favour of gOSMonaut (Go) which is faster, has a lower memory footprint and is better tested.

OSMonaut is a Java library that makes it easy to parse OpenStreetMap data from binary files (PBF). The main feature is that it always returns complete OSM objects. That means a relation comes with all the members and not just member IDs and ways come with all the nodes including the tags and location of those nodes.

To achieve this it is necessary to implement the two methods of the IOsmonautReceiver interface: needsEntity() and foundEntity(). needsEntity() helps reducing the amount of memory needed. For example if a relation is not needed there is no need to keep all the member ways and nodes in memory. foundEntity() is called when all the members of the entity have been prepared and includes the complete entity.

OSMonaut offers basic geometric functions and can handle multipolygons. Multithreading is used for parsing the PBF file and a low memory mode is available that stores the caches on disk. Super-relations are not yet supported.

Sample

Here is a small sample that prints the names and center coordinates of all lakes:

// Set which OSM entities should be scanned (only nodes and ways in this case)
EntityFilter filter = new EntityFilter(true, true, false);
	
// Set the binary OSM source file
Osmonaut naut = new Osmonaut("planet.osm.pbf", filter);
	
// Start scanning by implementing the interface
naut.scan(new IOsmonautReceiver() {
	@Override
	public boolean needsEntity(EntityType type, Tags tags) {
		// Only lakes with names
		return (tags.hasKeyValue("natural", "water") && tags.hasKey("name"));
	}
	
	@Override
	public void foundEntity(Entity entity) {
		// Print name and center coordinates
		String name = entity.getTags().get("name");
		System.out.println(name + ": " + entity.getCenter());
	}
});

→ Full documentation

osmonaut's People

Contributors

morbz avatar laurentg avatar guillaumerose avatar

Stargazers

scofield avatar  avatar Ganeshan Venkataraman avatar yafengstark avatar Pooya Alamirpour avatar Serge Helfrich avatar Stefan Ortgies avatar hiasel avatar Michalis Korakakis avatar Yasir Arfat avatar Łukasz Kolek avatar Norbert Renner avatar Peter avatar Tobias Gassmann avatar  avatar

Watchers

 avatar  avatar James Cloos avatar  avatar  avatar  avatar

osmonaut's Issues

Reducing memory requirements?

I've a couple of questions as we currently do this import process with own custom code for GraphHopper and your projects looks cleaner.

  • I've read at OsmPoisPbf that one needs 9gb for the world. Maybe MapDB could be used to reduce this? (Probably a bit slower but RAM could be more expensive)
  • What about the time to read the whole planet? (-> okay found that it takes ~1h for OsmPoisPbf) And could this improved via threading?
  • What about OSM ID stability? E.g. if I rerun will the sink consume the objects in the same order for an unchanged OSM source? Or is this randomized somewhere?
  • And the license is MIT?

maven central

Hi could you please publish your library on maven central?
Thanks

Exceptions in foundEntity() are swallowed

Instead an IllegalMonitorStateException somewhere in the pbfparser is thrown.

Here is an example:

Exception in thread "main" java.lang.IllegalMonitorStateException
        at java.util.concurrent.locks.ReentrantLock$Sync.tryRelease(ReentrantLock.java:151)
        at java.util.concurrent.locks.AbstractQueuedSynchronizer.release(AbstractQueuedSynchronizer.java:1261)
        at java.util.concurrent.locks.ReentrantLock.unlock(ReentrantLock.java:457)
        at net.morbz.osmonaut.binary.pbf.PbfDecoder.scan(PbfDecoder.java:240)
        at net.morbz.osmonaut.Osmonaut.finalScan(Osmonaut.java:246)
        at net.morbz.osmonaut.Osmonaut.scan(Osmonaut.java:150)
        at haagch.routeserver.MapDataReader.<init>(MapDataReader.java:39)
        at haagch.routeserver.Main.main(Main.java:33)

In this case it was really a com.carrotsearch.hppc.BufferAllocationException: which was Caused by: java.lang.OutOfMemoryError: Java heap space, but I only saw that after wrapping the content of my foundEntity() method in try {} catch (Exception e) { e.printStackTrace(); }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.