- Notifications
You must be signed in to change notification settings - Fork0
OSM Legal Speed is a Java SDK which help determine the legal max speed for most of the countries of the world, with respect to regional legal restrictions, based on OSM tags.
License
chargetrip/osm-legal-speed
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
OSM Legal Speed
is a Java SDK which help determine the legal max speed for most of the countries of the world, with respect to regional legal restrictions, based on OSM tags.
This project is highly inspired byOSM Legal Default Speeds. Under the hood, we are using the JSON file generated by itsparser (legal_default_speeds.json
).
OSM Legal Speed is a complete package to determine the legal speed based on a set of GPS coordinates and a vehicle type. Also, its providing support for different situation, including time based speed restrictions.
packagecom.chargetrip.example;importcom.chargetrip.osmLegalSpeed.types.VehicleType;importcom.chargetrip.osmLegalSpeed.types.Options;importjava.io.IOException;importjava.text.ParseException;importjava.time.LocalDateTime;importjava.util.HashMap;importjava.util.Map;publicclassMain {publicstaticvoidmain(String[]args) {Map<String,String>tags =newHashMap<>();tags.put("type","route");tags.put("route","road");tags.put("highway","motorway");try {Optionsoptions =newOptions();options.latitude =52.3727598;options.longitude =4.8936041;options.datetime =LocalDateTime.now().withHour(12).withMinute(0);LegalSpeedlegalSpeed =newLegalSpeed();// How to get a country with region codeStringcountryWithRegion =legalSpeed.getCountryWithRegion(options.latitude,options.longitude);System.out.println("Country with region: " +countryWithRegion);// How to search for max speed tagsLegalSpeed.SearchResultsearchResult =legalSpeed.searchSpeedLimits(tags,countryWithRegion,true);System.out.println("SearchResult: ");System.out.println("- certitude: " +searchResult.certitude);System.out.println("- tags: " +searchResult.speedType);// How to get the legal speed for all vehiclesSystem.out.println("Legal speeds:");for (VehicleTypevehicle :VehicleType.values()) {options.vehicle =vehicle;System.out.println("- " +vehicle +": " +legalSpeed.getSpeedLimit(tags,options)); } }catch (IOException |ParseExceptione) {e.printStackTrace(); } }}
This example will output:
Country with region: NLSearchResult: - certitude: Exact- tags: motorway: {maxspeed:motorhome:conditional=80 @ (maxweightrating>3.5), maxspeed:conditional=100 @ (06:00-19:00); 90 @ (trailer); 80 @ (maxweightrating>3.5 AND trailer), maxspeed:hgv=80, maxspeed=130, minspeed=60, maxspeed:bus=80, maxspeed:coach=100}Legal speeds:- Car: 100.0- Bus: 80.0- MiniBus: 100.0- SchoolBus: 100.0- TruckBus: 100.0- Coach: 100.0- Goods: 100.0- Hazmat: 100.0- Hgv: 80.0- Motorcycle: 100.0- Tricycle: 100.0- MotorHome: 100.0
The SDK is usinglegal_default_speeds.json
rules to determine the legal max speed andcountries.json
to determine country and/or region (is necessary) based on GPS coordinates. The legal rules file was generated using thisparser based on thiswiki page. Once more rules will be added to this page or changed, we will parse it again and build a new set of rules.
Thecountries.json
file contains definitions only for countries and regions which are present inlegal_default_speeds.json
. Every time we updatelegal_default_speeds.json
, we also check to see if we need to adjustcountries.json
.
- OSM Legal Default Speeds - Kotlin multiplatform library that provides information about legal default speed limits. Runs on JVM, native and JavaScript.
SDK | OSM legal speed tags | Country with region | Speed based on GPS |
---|---|---|---|
OSM Legal Speed | ✓ | ✓ | ✓ |
OSM Legal Default Speeds | ✓ | x | x |
About
OSM Legal Speed is a Java SDK which help determine the legal max speed for most of the countries of the world, with respect to regional legal restrictions, based on OSM tags.