Parsing ".osm" file which is either exported from "openstreetmap.org" or generated in similar manner with Open Street Map.
implementation group: 'net.mahmutkocas', name: 'osmparser', version: '[VERSION]'
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.
Ex:
List<BasicRouteModel> routeModels = osmDocument.getType(Tag.Type.HIGHWAY) // Only returns highways.
Possible BasicRouteModels are OSMNode, OSMWay, OSMRelation. Also see "getTypeAll" and "getTypeAny".
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 MemberNotExistsException for these relations. MemberNotExistsException contains the member which is the cause of the exception.