Coder Social home page Coder Social logo

basicosmparser's Introduction

BasicOSMParser

Read-me

BasicOSMParser is a collection of Java classes allowing to parse raw OSM XML files. Then you are able to manipulate those Java objects in your program. You can also export data as CSV files. This library is very simple to understand. It uses the default Java SAX parser (org.xml.sax). The application tests use JUnit 4 framework.

Installation (for developers)

In order to use BasicOSMParser, you can download the BasicOSMParser.jar file. Alternatively, you can put the content of src/main/ folder in the source directory of your project. Then, add this code in your classes to import the parser :

import info.pavie.basicosmparser.controller.*;
import info.pavie.basicosmparser.model.*;

Usage

In another project

Here is a simple example of how to use the parser. You just need to create a new parser object, and then call the parse method.

OSMParser p = new OSMParser();						//Initialization of the parser
File osmFile = new File("/path/to/your/data.osm");	//Create a file object for your OSM XML file

try {

	Map<String,Element> result = p.parse(osmFile);		//Parse OSM data, and put result in a Map object

} catch (IOException | SAXException e) {
	e.printStackTrace();								//Input/output errors management
}

The parser returns a Map<String,Element> object. This is a collection of key/value pairs. In this collection, keys are read OSM object identifiers, and values are read OSM objects. Keys are in a specific format : a letter followed by several digits. The letter corresponds to the kind of OSM object ('N' for nodes, 'W' for ways, 'R' for relations), and following digits are the OSM numeric ID. The read OSM objects are represented by Element objects, which can be Node, Way or Relation depending of the OSM object. You can access the different attributes of objects : ID, user ID, timestamp, version, object tags, ...

You can also directly pass a string which contains XML content, or use an InputSource object. See the Javadoc of these classes for more details about the available methods.

If you want to get parsed data as several CSV files, use a CSVExporter object :

Map<String,Element> result = p.parse(osmFile);
CSVExporter exporter = new CSVExporter();
exporter.export(result, new File("/output/path/for/csv/"));	//Throws IOException if error occurs during writing

See the Javadoc of CSVExporter to know more about output CSV format.

As a data consumer

If you only want to use this parser to create CSV files, you can execute the JAR with the following command :

java -jar BasicOSMParser.jar /path/to/data.osm /path/to/output/folder/

The command will parse the given OSM XML file, and create the CSV files in the output folder.

License

Copyright 2014 Adrien PAVIE

See LICENSE for complete GPL3 license.

BasicOSMParser is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

BasicOSMParser is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with BasicOSMParser. If not, see http://www.gnu.org/licenses/.

basicosmparser's People

Contributors

camilleh9 avatar

Watchers

 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.