private void GeneralizeByAreaAdditivePlus_Click(object sender, RoutedEventArgs e) { var fileName = this.SelectShapefile(); if (string.IsNullOrEmpty(fileName)) { return; } var shapes = GetShapes(fileName); var result = Utilities.SimplifyAlgorithms.AdditiveSimplifyByAreaPlus(shapes, Presenter.AreaThreshold); var unitDistance = WebMercatorUtility.CalculateGroundResolution(Presenter.ZoomLevel, 35); string output; if (unitDistance * unitDistance - Presenter.AreaThreshold < .001) { output = TodayDirectory + System.IO.Path.GetFileNameWithoutExtension(fileName) + "AreaAdditivePlus" + Presenter.ZoomLevel + ".shp"; } else { output = TodayDirectory + System.IO.Path.GetFileNameWithoutExtension(fileName) + "AreaAdditivePlus" + Presenter.AreaThreshold + ".shp"; } IRI.Ket.ShapefileFormat.Writer.ShpWriter.Write(output, result, true); }
public async Task <List <Tuple <TileInfo, GeoReferencedImage> > > GetTiles(BoundingBox mbb, double mapScale) { var zoom = IRI.Ham.SpatialBase.Mapping.WebMercatorUtility.GetZoomLevel(mapScale); var tilesBoundary = WebMercatorUtility.WebMercatorBoundingBoxToGoogleTileRegions(mbb, zoom); Debug.Print($"#GetTiles: {string.Join(" # ", tilesBoundary.Select(i => i.ToShortString()))}"); var result = new List <Tuple <TileInfo, GeoReferencedImage> >(); var tasks = new List <Task <Tuple <TileInfo, GeoReferencedImage> > >(); foreach (var item in tilesBoundary) { //int width = (int)(item.MercatorExtent.Width * mapScale / unitDistance); //int height = (int)(item.MercatorExtent.Height * mapScale / unitDistance); await Task.Delay(300); //result.Add(await GetTile(width, height, item, mapScale)); tasks.Add(GetTile(item, mapScale)); } tasks = tasks.Where(i => i != null).ToList(); await Task.WhenAll(tasks); foreach (var item in tasks) { result.Add(await item); } return(result); }
public static IShapeCollection SimplifyByArea(IShapeCollection shapes, int zoomLevel) { var unitDistance = WebMercatorUtility.CalculateGroundResolution(zoomLevel, 35); var unitArea = unitDistance * unitDistance; return(SimplifyByArea(shapes, unitArea)); }
public static void Create(string imageFileName, double pixelSize, string outputDirectory = null) { using (var bitmap = new Bitmap(imageFileName)) //using (var bitmap = (Bitmap)Image.FromStream(new System.IO.StreamReader(imageFileName).BaseStream, false, false)) { var worldfileName = WorldfileManager.TryGetAssociatedWorldfileName(imageFileName); if (worldfileName == null) { System.Diagnostics.Debug.Print($"Worldfile not found: '{worldfileName}'"); return; } var webMercatorBoundingBox = WorldfileManager.ReadImageBoundingBox(worldfileName, bitmap.Width, bitmap.Height); int zoomLevel = WebMercatorUtility.GetZoomLevel(bitmap.Height * pixelSize / webMercatorBoundingBox.Height); if (outputDirectory == null) { outputDirectory = $"{System.IO.Path.GetDirectoryName(imageFileName)}\\{System.IO.Path.GetFileNameWithoutExtension(imageFileName)}"; } while (zoomLevel > 0 && zoomLevel < 20) { var tiles = WebMercatorUtility.WebMercatorBoundingBoxToGoogleTileRegions(webMercatorBoundingBox, zoomLevel); if (tiles.Count < 1) { break; } if (!System.IO.Directory.Exists($"{outputDirectory}\\{zoomLevel}")) { System.IO.Directory.CreateDirectory($"{outputDirectory}\\{zoomLevel}"); } SplitIntoGoogleTiles(bitmap, webMercatorBoundingBox, tiles, $"{outputDirectory}\\{zoomLevel}"); zoomLevel--; } var zipFileName = System.IO.Path.ChangeExtension(imageFileName, "pyrmd"); if (System.IO.File.Exists(zipFileName)) { System.IO.File.Delete(zipFileName); } ZipFile.CreateFromDirectory(outputDirectory, System.IO.Path.ChangeExtension(imageFileName, "pyrmd")); Sta.Common.Helpers.IOHelper.DeleteDirectory(outputDirectory); } }
public List <GeoReferencedImage> GetTiles(BoundingBox geographicBoundingBox, double mapScale) { //94.12.17 //int zoomLevel = GetZoomLevel(mapScale); int zoomLevel = IRI.Ham.SpatialBase.Mapping.WebMercatorUtility.GetZoomLevel(mapScale); var result = new List <IRI.Ham.SpatialBase.GeoReferencedImage>(); //What if there were no imagesource for this zoom level if (!this.ImageSources.Any(i => i.ZoomLevel == zoomLevel)) { return(result); } var lowerLeft = WebMercatorUtility.LatLonToImageNumber(geographicBoundingBox.YMin, geographicBoundingBox.XMin, zoomLevel); var upperRight = WebMercatorUtility.LatLonToImageNumber(geographicBoundingBox.YMax, geographicBoundingBox.XMax, zoomLevel); var imageSource = this.ImageSources.Single(i => i.ZoomLevel == zoomLevel); for (int i = (int)lowerLeft.X; i <= upperRight.X; i++) { for (int j = (int)upperRight.Y; j <= lowerLeft.Y; j++) { //94.12.17 //string imageName; //if (imageSource.IsZoomLevelIncluded) //{ // imageName = string.Format("{0}{1}_{2}_{3}.{4}", imageSource.ImagePrefix, i, j, zoomLevel, imageSource.FileExtension); //} //else //{ // imageName = string.Format("{0}{1}_{2}.{3}", imageSource.ImagePrefix, i, j, imageSource.FileExtension); //} //string fileName = System.IO.Path.Combine(imageSource.ImageDirectory, imageName); string fileName = imageSource.GetFileName(j, i); if (System.IO.File.Exists(fileName)) { result.Add(new IRI.Ham.SpatialBase.GeoReferencedImage( System.IO.File.ReadAllBytes(fileName), WebMercatorUtility.GetWgs84ImageBoundingBox(j, i, zoomLevel))); } } } System.Diagnostics.Trace.WriteLine(string.Format("{0} Images founded; zoom level = {1}", result.Count, zoomLevel)); return(result); }
public void SaveAsGoogleTiles(string outputFolderPath, int minLevel = 1, int maxLevel = 13) { if (maxLevel < minLevel) { throw new NotImplementedException("(ERROR IN VECTOR LAYER): minLevel must be less than maxLevel"); } var zoomLevels = Enumerable.Range(minLevel, maxLevel - minLevel + 1); foreach (var zoom in zoomLevels) { var googleTiles = WebMercatorUtility.WebMercatorBoundingBoxToGoogleTileRegions(this.Extent, zoom); var scale = GoogleScale.Scales.Single(i => i.ZoomLevel == zoom).InverseScale; var directory = $"{outputFolderPath}\\{zoom}"; if (!System.IO.Directory.Exists(directory)) { System.IO.Directory.CreateDirectory(directory); } foreach (var tile in googleTiles) { var geometries = this.GetGeometries(scale, tile.WebMercatorExtent); var transform = IRI.Ham.SpatialBase.Mapping.MapUtility.GetMapToScreen(tile.WebMercatorExtent, 256, 256); Func <Point, Point> mapToScreen = p => { return(transform(p.AsPoint()).AsWpfPoint()); }; var pen = this.VisualParameters.GetGdiPlusPen(); pen.Width = 2; var image = SqlSpatialToGdiBitmap.ParseSqlGeometry( geometries, 256, 256, mapToScreen, pen, this.VisualParameters.Fill.AsGdiBrush(), this.VisualParameters.PointSize, this.PointSymbol); image.Save($"{directory}\\{tile.ZoomLevel}, {tile.RowNumber}, {tile.ColumnNumber}.jpg"); } } }
public List <GeoReferencedImage> GetTiles(BoundingBox geographicBoundingBox, double mapScale) { //94.12.17 //int zoomLevel = GetZoomLevel(mapScale); int zoomLevel = IRI.Ham.SpatialBase.Mapping.WebMercatorUtility.GetZoomLevel(mapScale); var result = new List <IRI.Ham.SpatialBase.GeoReferencedImage>(); //What if there were no imagesource for this zoom level if (!_archive.Entries.Any(i => i.FullName.StartsWith(zoomLevel.ToString(), StringComparison.OrdinalIgnoreCase))) { return(result); } var lowerLeft = WebMercatorUtility.LatLonToImageNumber(geographicBoundingBox.YMin, geographicBoundingBox.XMin, zoomLevel); var upperRight = WebMercatorUtility.LatLonToImageNumber(geographicBoundingBox.YMax, geographicBoundingBox.XMax, zoomLevel); for (int i = (int)lowerLeft.X; i <= upperRight.X; i++) { for (int j = (int)upperRight.Y; j <= lowerLeft.Y; j++) { //var zipArchive = new System.IO.Compression.ZipArchive(archive.Open()); if (_archive.Entries.Any(e => e.FullName.Equals(_fileNameRule(zoomLevel, j, i), StringComparison.OrdinalIgnoreCase))) { var stream = _archive.Entries.Single(e => e.FullName.Equals(_fileNameRule(zoomLevel, j, i), StringComparison.OrdinalIgnoreCase)).Open(); byte[] bytes = Common.Helpers.StreamHelper.ToByteArray(stream); //using (var memoryStream = new System.IO.MemoryStream()) //{ // stream.CopyTo(memoryStream); // bytes = memoryStream.ToArray(); //} result.Add(new GeoReferencedImage(bytes, WebMercatorUtility.GetWgs84ImageBoundingBox(j, i, zoomLevel))); } } } System.Diagnostics.Trace.WriteLine(string.Format("{0} Images founded; zoom level = {1}", result.Count, zoomLevel)); return(result); }
private IShapeCollection GetShapes(string fileName) { var shapes = IRI.Ket.ShapefileFormat.Shapefile.Read(fileName); var width = Math.Max(shapes.MainHeader.MinimumBoundingBox.Width, shapes.MainHeader.MinimumBoundingBox.Height); //this.Presenter.EstimatedScale = WebMercatorUtility.EstimateMapScale(width, 30, 900); var z1 = WebMercatorUtility.GetZoomLevel(width, 30, 900); var z2 = WebMercatorUtility.GetZoomLevel(width, 30, 900); Trace.WriteLine($"Z1: {z1}"); Trace.WriteLine($"Z2: {z2}"); return(shapes); }
public List <GeoReferencedImage> GetTilesForGoogleEarth(BoundingBox geographicBoundingBox, double mapScale) { //94.12.17 //int zoomLevel = GetZoomLevel(mapScale); int zoomLevel = IRI.Msh.Common.Mapping.WebMercatorUtility.GetZoomLevel(mapScale); var result = new List <GeoReferencedImage>(); //What if there were no imagesource for this zoom level if (!this.ImageSources.Any(i => i.ZoomLevel == zoomLevel)) { return(result); } var lowerLeft = WebMercatorUtility.LatLonToImageNumber(geographicBoundingBox.YMin, geographicBoundingBox.XMin, zoomLevel); var upperRight = WebMercatorUtility.LatLonToImageNumber(geographicBoundingBox.YMax, geographicBoundingBox.XMax, zoomLevel); var imageSource = this.ImageSources.Single(i => i.ZoomLevel == zoomLevel); for (int i = (int)lowerLeft.X; i <= upperRight.X; i++) { for (int j = (int)upperRight.Y; j <= lowerLeft.Y; j++) { string fileName = imageSource.GetFileName(j, i); if (System.IO.File.Exists(fileName)) { result.Add(new GeoReferencedImage( System.IO.File.ReadAllBytes(fileName), WebMercatorUtility.GetWgs84ImageBoundingBox(j, i, zoomLevel))); } } } System.Diagnostics.Trace.WriteLine(string.Format("{0} Images founded; zoom level = {1}", result.Count, zoomLevel)); return(result); }
public static GoogleScale GetNearestScale(double mapScale, double latitude = 35) { var zoomLevel = WebMercatorUtility.GetZoomLevel(mapScale, latitude); return(Scales.Single(i => i.ZoomLevel == zoomLevel)); }