/// <summary> /// Initialize OsmSnapper, which allows you to snap GPS tracks to on-road geometries /// </summary> /// <param name="overpassApi"></param> /// <param name="boundingBox"></param> /// <param name="parameters"></param> /// <param name="printConsoleUpdates"></param> public OsmSnapper(OverpassApi overpassApi, BoundingBox boundingBox = null, MapMatcherParameters parameters = null, bool printConsoleUpdates = false, bool useSearchGrid = true) { _printConsoleUpdates = printConsoleUpdates; _useSearchGrid = useSearchGrid; if (parameters == null) { parameters = MapMatcherParameters.Default; } Parameters = parameters; if (overpassApi == OverpassApi.DeloreanGray) { _overpassApi = Config.Urls.DeloreanGray; } else if (overpassApi == OverpassApi.MainOverpass) { _overpassApi = Config.Urls.MainOverpassApi; } else { throw new ArgumentException("Invalid overpass enum"); } if (boundingBox != null) { SnappingArea = boundingBox; // Build graph in bounding box and initialize map matcher (involves computing search grid data structure) var graph = OsmGraphBuilder.BuildInRegion(_overpassApi, boundingBox); MapMatcher = new OsmMapMatcher(graph, parameters, _useSearchGrid); } }
public void GetOsmNodeTest() { var client = new OverpassApi(); var result = client.GetOsmNode(3657889771); Assert.IsNotNull(result); Assert.AreEqual("Spiegel", result.Name); Assert.AreEqual(1, result.Tags.Count); Assert.AreEqual("amenity", result.Tags[0].Key); Assert.AreEqual("bar", result.Tags[0].Value); }
public static void FixPhones(ILoggerFactory loggerFactory, IConfigurationRoot config, OsmGeo scope) { var rejectLogger = loggerFactory.CreateLogger("Unfixable"); Action <OsmGeo> rejector = a => rejectLogger.LogWarning($"Rejected {a.Type}:{a.Id} {a.Tags[Tag]}"); var osmApi = new OsmApiEnder(loggerFactory.CreateLogger(typeof(OsmApiEnder)), config["OsmApiUrl"], config["OsmUsername"], config["OsmPassword"], ChangeTags); var badPhones = OverpassApi.Get(BadPhoneQuery(scope, Tag)).GetElements(); var betterPhones = FixPhones(badPhones, Tag, rejector).ToArray(); var change = Changes.FromGeos(null, betterPhones, null, nameof(OsmPipeline)); osmApi.Upload(change); }
public void TestGetCities() { var client = new OverpassApi(); OSMPointsLayer layer = new OSMPointsLayer(); layer.CityTypeNeighbourhood = true; layer.CityTypeCity = true; layer.CityTypeSuburb = true; layer.CityTypeTown = true; layer.CityTypeVillage = true; layer.MaxDistanceToCity = 40000; layer.MaxDistaToTag = 2000; var result = client.GetOsmNodes(layer, new PointLatLng(51.4894273, 9.1421818), 10000); //if the city isn't found, it throws an exception -> Test failed :-) result.First(x => x.Name.Equals("Warburg")); result.First(x => x.Name.Equals("Nörde")); result.First(x => x.Name.Equals("Hohenwepel")); result.First(x => x.Name.Equals("Menne")); }