Esempio n. 1
0
        public async Task <ActionResult> GetImage(GeoRect rect)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult(ModelState));
            }
            var imgTask = await GetImageAsync(rect);

            return(File(imgTask, "image/jpeg"));
        }
Esempio n. 2
0
        public async Task <ActionResult> GetGeoJson(GeoRect rect)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult(ModelState));
            }
            var jsonStr = await GetGeoJSON(rect);

            return(Ok(jsonStr));
        }
Esempio n. 3
0
        public async Task <ActionResult> GetImageMetadata(GeoRect rect)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult(ModelState));
            }
            var str = await GetImageMetadataAsync(rect);

            return(Ok(str));
        }
Esempio n. 4
0
        private async Task <string> GetGeoJSON(GeoRect rect)
        {
            var httpStr = $"http://overpass-api.de/api/interpreter?data=[out:json];(node[\"building\"]({rect.MinLat},{rect.MinLon},{rect.MaxLat},{rect.MaxLon});way[\"building\"]({rect.MinLat},{rect.MinLon},{rect.MaxLat},{rect.MaxLon});relation[\"building\"]({rect.MinLat},{rect.MinLon},{rect.MaxLat},{rect.MaxLon}););out body;>;out skel qt;";
            var http    = new HttpClient();
            var tsk     = await http.GetAsync(httpStr);

            var strTsk = await tsk.Content.ReadAsStringAsync();

            Converter.FilesRoot = _he.WebRootPath + Path.DirectorySeparatorChar.ToString();
            var converter = new Converter();
            var geojson   = converter.OsmToGeoJSON(strTsk);

            return(geojson);
        }
Esempio n. 5
0
        public async Task <byte[]> GetImageAsync(GeoRect rect)
        {
            var bingKey = Environment.GetEnvironmentVariable("BING_MAPS_KEY");
            var httpStr = $"http://dev.virtualearth.net/REST/v1/Imagery/Map/Aerial?";

            httpStr += $"mapArea={rect.MinLat},{rect.MinLon},{rect.MaxLat},{rect.MaxLon}";
            httpStr += $"&mapSize=1500,1500";
            httpStr += $"&key={bingKey}";
            var http = new HttpClient();
            var tsk  = await http.GetAsync(httpStr);

            tsk.EnsureSuccessStatusCode();
            var bytesTsk = await tsk.Content.ReadAsByteArrayAsync();

            return(bytesTsk);
        }
Esempio n. 6
0
        public async Task <ActionResult> Get(GeoRect rect)
        {
            if (!ModelState.IsValid)
            {
                return(new JsonResult(ModelState));
            }

            var result          = new MappingDto();
            var geoJSONTask     = GetGeoJSON(rect);
            var imgTask         = GetImageAsync(rect);
            var imgMetadataTask = GetImageMetadataAsync(rect);

            await Task.WhenAll(geoJSONTask, imgTask, imgMetadataTask);

            result.GeoJSON   = geoJSONTask.Result;
            result.ImageData = new ImageDto
            {
                Image    = imgTask.Result,
                Metadata = imgMetadataTask.Result
            };
            return(Ok(result));
        }