public static void Create(string imageFileName, double pixelSize, string outputDirectory = null) { using (var bitmap = new Bitmap(imageFileName)) { 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")); Common.Helpers.DirectoryHelper.DeleteDirectory(outputDirectory); } }
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 static void CreateFromWebMercatorWorldfile(string imageFileName, double pixelSize, string outputDirectory = null) { var bitmap = new BitmapImage(new Uri(imageFileName)); var worldfileName = WorldfileManager.TryGetAssociatedWorldfileName(imageFileName); if (worldfileName == null) { System.Diagnostics.Debug.Print($"Worldfile not found: '{worldfileName}'"); return; } var webMercatorBoundingBox = WorldfileManager.ReadImageBoundingBox(worldfileName, (int)bitmap.Width, (int)bitmap.Height); int zoomLevel = WebMercatorUtility.GetZoomLevel(bitmap.Height * pixelSize / webMercatorBoundingBox.Height); if (zoomLevel >= 20) { zoomLevel = 19; } if (outputDirectory == null) { //outputDirectory = $"{System.IO.Path.GetDirectoryName(imageFileName)}\\{System.IO.Path.GetFileNameWithoutExtension(imageFileName)}"; outputDirectory = Path.Combine(Path.GetDirectoryName(imageFileName), Path.GetFileNameWithoutExtension(imageFileName)); } if (!Directory.Exists($"{outputDirectory}")) { Directory.CreateDirectory($"{outputDirectory}"); } WriteBoundingBox(webMercatorBoundingBox, outputDirectory); while (zoomLevel > 0 && zoomLevel < 20) { var tiles = WebMercatorUtility.WebMercatorBoundingBoxToGoogleTileRegions(webMercatorBoundingBox, zoomLevel); if (tiles.Count < 1) { break; } var subDirectory = Path.Combine(outputDirectory, zoomLevel.ToString()); if (!Directory.Exists(subDirectory)) { Directory.CreateDirectory(subDirectory); } SplitIntoGoogleTiles(bitmap, webMercatorBoundingBox, tiles, subDirectory); zoomLevel--; } var zipFileName = Path.ChangeExtension(imageFileName, "pyrmd"); if (File.Exists(zipFileName)) { File.Delete(zipFileName); } ZipFile.CreateFromDirectory(outputDirectory, Path.ChangeExtension(imageFileName, "pyrmd")); Sta.Common.Helpers.IOHelper.DeleteDirectory(outputDirectory); }
public static GoogleScale GetNearestScale(double mapScale, double latitude = 35) { var zoomLevel = WebMercatorUtility.GetZoomLevel(mapScale, latitude); return(Scales.Single(i => i.ZoomLevel == zoomLevel)); }