You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 4-6.RSVP
Socket
Book a DemoInstallSign in
Socket

net.mahmutkocas:osmparser

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

net.mahmutkocas:osmparser

Open Street Map XML Parser written in Java

0.5
Source
mavenMaven
Version published
Maintainers
1
Source

Open Street Map XML/.OSM Parser

Purpose

Parsing ".osm" file which is either exported from "openstreetmap.org" or generated in similar manner with Open Street Map.

Gradle

Maven Central License: The MIT

implementation group: 'net.mahmutkocas', name: 'osmparser', version: '[VERSION]'

How to use

OSMParser has static function called "parseXML(String)", by passing file path one can easily parse the XML file.

OSMDocument osmDocument = OSMParser.parseXML(file);

OSMDocument provides parsed OSM Nodes, Ways and Relations with getter methods.

Map<Long, OSMNode> nodeMap = osmDocument.getNodes(); // Returns nodes.
Map<Long, OSMWay> wayMap = osmDocument.getWays(); // Returns ways.
Map<Long, OSMRelation> relationMap = osmDocument.getRelations(); // Returns relations.

Returned values are maps. Keys are the IDs of the elements. By calling ".values()" method, one can get values.

List<OSMNode> nodes = nodeMap.values(); // Raw Node List.

Filtering by Tags

Ex:

List<BasicRouteModel> routeModels = osmDocument.getType(Tag.Type.HIGHWAY) // Only returns highways.

Possible BasicRouteModels are OSMNode, OSMWay, OSMRelation. Also see "isTypeAll" and "isTypeAny".

Getting Vector Data of the Route Model(Lat Long)

Ex:

// Assuming routeModels contain at least one item.
List<LatLon> highway = routeModels.get(0).getPath();

Note: OSM's XML file may not contain all the information about "Relation"s it provides. So "getPath()" method may throw NullPointerException for these relations.

FAQs

Package last updated on 25 Aug 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts