| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- param(
- [int]$Zoom = 15,
- [double[]]$Bounds = @(110.328749941417, 28.3917230659234, 110.465779226663, 28.4913038992907),
- [int]$MaxWidth = 6500,
- [string]$Output = 'E:\City-Lifeline-Cockpit-TvT\.scratch\gis-investigation-subagent\city-z15.jpg'
- )
- $ErrorActionPreference = 'Stop'
- Add-Type -AssemblyName System.Drawing
- $n = [math]::Pow(2, $Zoom)
- function TileX([double]$lon) { return [int][math]::Floor(($lon + 180) / 360 * $n) }
- function GoogleY([double]$lat) {
- $rad = $lat * [math]::PI / 180
- return [int][math]::Floor((1 - [math]::Log([math]::Tan($rad) + 1 / [math]::Cos($rad)) / [math]::PI) / 2 * $n)
- }
- $x0 = TileX $Bounds[0]; $x1 = TileX $Bounds[2]
- $y0 = GoogleY $Bounds[3]; $y1 = GoogleY $Bounds[1]
- $scale = [math]::Min(1.0, [double]$MaxWidth / (($x1 - $x0 + 1) * 256.0))
- $tileSize = 256 * $scale
- $width = [int][math]::Round(($x1 - $x0 + 1) * $tileSize)
- $height = [int][math]::Round(($y1 - $y0 + 1) * $tileSize)
- $bitmap = New-Object System.Drawing.Bitmap($width, $height)
- $graphics = [System.Drawing.Graphics]::FromImage($bitmap)
- $graphics.Clear([System.Drawing.Color]::Black)
- $graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
- $loaded = 0; $missing = 0
- for ($x = $x0; $x -le $x1; $x++) {
- for ($gy = $y0; $gy -le $y1; $gy++) {
- $tmsY = [int]$n - 1 - $gy
- $path = "D:\GIS\GIS\yuanlingPic3\$Zoom\$x\$tmsY.png"
- if (-not (Test-Path $path)) { $missing++; continue }
- $tile = [System.Drawing.Image]::FromFile($path)
- try {
- $left = [int][math]::Round(($x - $x0) * $tileSize)
- $top = [int][math]::Round(($gy - $y0) * $tileSize)
- $right = [int][math]::Round(($x - $x0 + 1) * $tileSize)
- $bottom = [int][math]::Round(($gy - $y0 + 1) * $tileSize)
- $graphics.DrawImage($tile, [System.Drawing.Rectangle]::new($left, $top, $right - $left, $bottom - $top))
- $loaded++
- } finally { $tile.Dispose() }
- }
- }
- $graphics.Dispose()
- $format = if ([System.IO.Path]::GetExtension($Output) -eq '.jpg') { [System.Drawing.Imaging.ImageFormat]::Jpeg } else { [System.Drawing.Imaging.ImageFormat]::Png }
- $bitmap.Save($Output, $format)
- $bitmap.Dispose()
- Write-Output "zoom=$Zoom x=$x0..$x1 googleY(top..bottom)=$y0..$y1 TMSY(top..bottom)=$([int]$n - 1 - $y0)..$([int]$n - 1 - $y1) dimensions=${width}x${height} loaded=$loaded missing=$missing output=$Output"
|