Code Monkey home page Code Monkey logo

kosmparser's Introduction

kosmparser

Java CI with Gradle

This is a simple implementation of an asynchronous streaming parser for the Open Street Map XML Format to make it easier to work with in Kotlin. Support is limited to the XML export format - i.e. it doesn't yet look at things like changesets and the like. Likewise unsupported are exports in Protocol Buffer Format (pbf), etc.

Data Model

The main abstraction is Flow<OsmData>. The data model uses a Kotlin sealed class (for exhaustive pattern matching) and has the following implementations as data classes:

  • OsmMetadata - version, generator, bounds
  • Node
  • Way
  • Relation

The parser ensures that they will be emitted in the expected order, but depending on the input, there is no guarantee that all will be present (other than OsmMetadata).

Usage

The object OsmFlowMapper offers utility functions to generate a Flow<OsmData> via extension functions on java.nio.Path and java.net.URI.

Example code.

import java.nio.Path
import com.jejking.kosmparser.OsmFlowMapper.toOsmDataFlow

Path.of("/tmp/map.osm").toOsmDataFlow()

URI.create("https://example.com/osm").toOsmDataFlow()

Design Notes

The project is also a simple learning experiment with Kotlin Flows - and chains flows together to produce increasing layers of abstraction.

At the bottom layer, we use a Flow<ByteArray> for raw input data that is read from a file or a URI. We feed that into an XML Flow Mapper (wrapping the asynchronous aalto-xml XML parser) to produce a Flow<SimpleXmlParseEvent>. Given the fact that OSM does not use all the features of XML, we use a simplified parse event model using Kotlin data classes. These XML parse events are then fed into an OSM Flow Mapper to produce a Flow<OsmData>.

The OSM Flow Mapper handles validation and conversion logic for the XML Parse Events. Validation is handled programmatically in the absence of official DTDs or XML Schema. The syntactic validation rules are implemented by an internal parser state machine.

kosmparser's People

Contributors

jejking avatar jejking-tw avatar

Watchers

James Cloos avatar  avatar

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.