// not used oddly enough public OSMInterface(osmBounds bounds, double scale, double tolerance, double curveTolerance, double tiles, string nodesRequestUrl, string waysRequestUrl) { this.tolerance = tolerance; curveError = curveTolerance; Mapping = new RoadMapping(tiles); fc = new FitCurves(); var client = new WebClient(); var nodesResponse = client.DownloadData(nodesRequestUrl); var waysResponse = client.DownloadData(waysRequestUrl); var nodesReader = new StreamReader(new MemoryStream(nodesResponse)); var waysReader = new StreamReader(new MemoryStream(waysResponse)); var serializer = new XmlSerializer(typeof(OsmDataResponse)); var nodesOsm = (OsmDataResponse)serializer.Deserialize(nodesReader); var waysOsm = (OsmDataResponse)serializer.Deserialize(waysReader); nodesOsm.way = waysOsm.way; nodesReader.Dispose(); waysReader.Dispose(); nodesOsm.bounds = bounds; Init(nodesOsm, scale); }
// used by load osm file public OSMInterface(osmBounds bounds, string path, double scale, double tolerance, double curveTolerance, double tiles) { this.tolerance = tolerance; this.curveError = curveTolerance; Mapping = new RoadMapping(tiles); fc = new FitCurves(); var serializer = new XmlSerializer(typeof(OsmDataResponse)); var reader = new StreamReader(path); var osm = serializer.Deserialize(reader) as OsmDataResponse; reader.Dispose(); if (osm != null) { osm.bounds = bounds; Init(osm, scale); } }
public OSMInterface(osmBounds bounds, double scale, double tolerance, double curveTolerance, double tiles) { this.tolerance = tolerance; this.curveError = curveTolerance; mapping = new RoadMapping(tiles); fc = new FitCurves(); var client = new WebClient(); var response = client.DownloadData("http://www.overpass-api.de/api/xapi?map?bbox=" + string.Format("{0},{1},{2},{3}", bounds.minlon.ToString(), bounds.minlat.ToString(), bounds.maxlon.ToString(), bounds.maxlat.ToString())); var ms = new MemoryStream(response); var reader = new StreamReader(ms); var serializer = new XmlSerializer(typeof(osm)); var osm = (osm)serializer.Deserialize(reader); ms.Dispose(); reader.Dispose(); osm.bounds = bounds; Init(osm, scale); }
public OSMInterface(osmBounds bounds, double scale, double tolerance, double curveTolerance, double tiles) { this.tolerance = tolerance; this.curveError = curveTolerance; mapping = new RoadMapping(tiles); fc = new FitCurves(); var client = new WebClient(); var response = client.DownloadData("http://www.overpass-api.de/api/xapi?map?bbox=" + string.Format("{0},{1},{2},{3}", bounds.minlon.ToString(), bounds.minlat.ToString(), bounds.maxlon.ToString(), bounds.maxlat.ToString())); var ms = new MemoryStream(response); var reader = new StreamReader(ms); var serializer = new XmlSerializer(typeof(OSM)); var osm = (OSM)serializer.Deserialize(reader); ms.Dispose(); reader.Dispose(); osm.bounds = bounds; Init(osm, scale); }
public OSMInterface(osmBounds bounds, double scale, double tolerance, double curveTolerance, double tiles) { this.tolerance = tolerance; curveError = curveTolerance; Mapping = new RoadMapping(tiles); fc = new FitCurves(); var client = new WebClient(); string nodes = "http://overpass-api.de/api/interpreter?data=node(" + string.Format("{0},{1},{2},{3}", bounds.maxlat.ToString(), bounds.minlon.ToString(), bounds.minlat.ToString(), bounds.maxlon.ToString()) + ");out;"; string ways = "http://overpass-api.de/api/interpreter?data=way(" + string.Format("{0},{1},{2},{3}", bounds.maxlat.ToString(), bounds.minlon.ToString(), bounds.minlat.ToString(), bounds.maxlon.ToString()) + ");out;"; var nodesResponse = client.DownloadData(nodes); var waysResponse = client.DownloadData(ways); var nodesMemoryStream = new MemoryStream(nodesResponse); var wayssMemoryStream = new MemoryStream(waysResponse); var nodesReader = new StreamReader(nodesMemoryStream); var waysReader = new StreamReader(wayssMemoryStream); var serializer = new XmlSerializer(typeof(OsmDataResponse)); var nodesOsm = (OsmDataResponse)serializer.Deserialize(nodesReader); var waysOsm = (OsmDataResponse)serializer.Deserialize(waysReader); nodesOsm.way = waysOsm.way; nodesMemoryStream.Dispose(); wayssMemoryStream.Dispose(); nodesReader.Dispose(); waysReader.Dispose(); nodesOsm.bounds = bounds; Init(nodesOsm, scale); }
// used when makeroads is clicked (!) public OSMInterface(osmBounds bounds, byte[] nodesXml, byte[] waysXml, double scale, double tolerance, double curveTolerance, double tiles) { this.tolerance = tolerance; this.curveError = curveTolerance; Mapping = new RoadMapping(tiles); fc = new FitCurves(); var nodesReader = new StreamReader(new MemoryStream(nodesXml)); var waysReader = new StreamReader(new MemoryStream(waysXml)); var serializer = new XmlSerializer(typeof(OsmDataResponse)); var nodesOsm = (OsmDataResponse)serializer.Deserialize(nodesReader); var waysOsm = (OsmDataResponse)serializer.Deserialize(waysReader); nodesOsm.way = waysOsm.way; nodesReader.Dispose(); waysReader.Dispose(); nodesOsm.bounds = bounds; Init(nodesOsm, scale); }
//public void InitBoundingBox(osmNode node) //{ // startLatLon = new Vector2(Math.Min(startLatLon.x, (float)node.lon), Math.Min(startLatLon.y, (float)node.lat)); // endLatLon = new Vector2(Math.Max(endLatLon.x, (float)node.lon), Math.Max(endLatLon.y, (float)node.lat)); //} public void InitBoundingBox(osmBounds bounds,double scale) { this.middleLatLon = new Vector2((float)(bounds.minlon + bounds.maxlon) / 2f, (float)(bounds.minlat + bounds.maxlat) / 2f); var lat = Deg2rad(this.middleLatLon.y); var radius = WGS84EarthRadius(lat); var pradius = radius * Math.Cos(lat); scaleX = scale * GameSizeGameCoordinates / Rad2deg(GameSizeMetres / pradius); scaleY = scale * GameSizeGameCoordinates / Rad2deg(GameSizeMetres / radius); }
private void loadAPIButton_eventClick(UIComponent component, UIMouseEventParameter eventParam) { try { decimal startLat = 0M; decimal startLon = 0M; decimal endLat = 0M; decimal endLon = 0M; var scale = double.Parse(scaleTextBox.text.Trim()); var tt = double.Parse(tiles.text.Trim()); if (!GetCoordinates(tt,scale,ref startLon, ref startLat, ref endLon, ref endLat)) { return; } var ob = new osmBounds(); ob.minlon = startLon; ob.minlat = startLat; ob.maxlon = endLon; ob.maxlat = endLat; var osm = new OSMInterface(ob, scale, double.Parse(tolerance.text.Trim()), double.Parse(curveTolerance.text.Trim()), tt); currentIndex = 0; roadMaker = new RoadMaker2(osm); errorLabel.text = "Data Loaded."; okButton.Enable(); loadMapButton.Disable(); loadAPIButton.Disable(); } catch (Exception ex) { errorLabel.text = ex.ToString(); } }