private List <Poi> QueryPois(int rangeId, State state) { // create overpass object and add clauses var overpass = new Overpass(); var tags = _contentService.GetTagsForCategories( state.User.Categories.Where(c => c.Enabled) .Select(c => c.Id) .ToArray() ); foreach (var tag in tags) { overpass = overpass.AddClause(Overpass.AllTypes, tag); } // generate bounding box var center = state.Coordinates; if (rangeId < 0 || rangeId > _rangeDistances.Length - 1) { throw new ArgumentOutOfRangeException(nameof(rangeId), $"RangeId should be from 0 to {_rangeDistances.Length - 1}"); } var distance = _rangeDistances[rangeId]; var topLeft = GeoUtils.FindPointAtDistanceFrom(center, -Math.PI / 4, distance * RadiusToBoundRatio); var bottomRight = GeoUtils.FindPointAtDistanceFrom(center, 3 * Math.PI / 4, distance * RadiusToBoundRatio); // get points var pois = overpass.Execute(topLeft, bottomRight); pois.ForEach(p => _contentService.FillEmptyData(p)); return(pois); }
public void CanGetOverpassQuery() { Overpass overpass = new Overpass(leftTopLat, leftTopLon, bottomRightLat, bottomRightLon); Assert.IsInstanceOfType(overpass, typeof(Overpass)); string str = overpass.Query(Overpass.Highway); Assert.IsFalse(string.IsNullOrEmpty(str)); Assert.AreEqual("<?xml", str.Substring(0, 5)); //File.WriteAllText(@"C:\Users\John\tmp\testrailway.xml", overpass.Query(Overpass.Railway)); }
public void CreateEnvironment(Coords worldPoint, int worldRadius, Vector3 editorPoint, float height, int editorRadius) { SetupGOInstance(editorPoint); var square = CoordinatesUtils.SquareFromCenter((worldPoint.Latitude, worldPoint.Longitude), worldRadius); var squareSim = CoordinatesUtils.SquareFromCenterSim(new Vector3(0, 0, 0), editorRadius); var tile = new Tile(square[2], square[0], squareSim[2], squareSim[0]); // Retrieve data from API only if necessary var data = SessionState.GetString("prev_environment", ""); if (SettingsHaveChanged(worldPoint, worldRadius, height) == true) { SessionState.SetFloat("prev_latitude", worldPoint.Latitude); SessionState.SetFloat("prev_longitude", worldPoint.Longitude); SessionState.SetInt("prev_radius", worldRadius); SessionState.SetFloat("prev_editor_heigh", height); data = Overpass.GetBuildingsInArea(tile); } var dataObj = JsonConvert.DeserializeObject <DataProperties>(data); SessionState.SetString("prev_environment", data); foreach (Elements elem in dataObj.elements) { Vector3[] points = new Vector3[elem.geometry.Length]; for (int i = 0; i < elem.geometry.Length; i++) { Coords geoPoint = new Coords(elem.geometry[i].lat, elem.geometry[i].lon); Vector3 simPoint = SimCoordinatesUtils.GPSToSim(geoPoint, tile); points[i] = simPoint; } GenerateBuilding(points, height); } }
public void CanGetOverpassHighways() { Overpass overpass = new Overpass(leftTopLat, leftTopLon, bottomRightLat, bottomRightLon); string xml = UnittestTools.ReadResource("testhighway.xml"); // does ReadResource work? (for testing we do NOT need to query overpass.de) Assert.IsFalse(string.IsNullOrEmpty(xml)); Assert.AreEqual("<?xml", xml.Substring(0, 5)); overpass.ParseSegmentsAndNodes(xml); Assert.AreEqual(1325, overpass.Nodes.Count); Assert.AreEqual(285, overpass.Segments.Count); Assert.AreEqual("A2", overpass.Segments[0].Name); Assert.AreEqual("A2", overpass.Segments[0].Ref); Assert.AreEqual(4842325, overpass.Segments[0].Id); Assert.AreEqual(2, overpass.Segments[0].Nodes.Count); Assert.AreEqual(10, overpass.Segments[0].Tags.Count); Segment segment = overpass.Segments.FirstOrDefault(s => s.Id == 329098539); Assert.IsNotNull(segment); Assert.AreEqual(11, segment.Tags.Count); Assert.AreEqual("A2", segment.Ref); Assert.AreEqual("Koning Willem-Alexandertunnel", segment.Name); }
public OsmTrackCollection(double lat, double lon) : base(lat, lon) { overpass = new Overpass(leftTopLat, leftTopLon, rightBottomLat, rightBottomLon); }