MapKit 通过 MKOverlay 添加栅格地图奇怪的渲染问题

2023-11-29

我已将 NOAA 雷达图像添加到我的天气应用程序中。经过一些测试后,我注意到图像没有在地图上正确绘制。图像的角点似乎接近正确,但当您远离角点时,它会倾斜。下面是相关代码。

Overlay:

@implementation FMRadarOverlay

- (id)initWithImage:(UIImage*)radarImage withLowerLeftCoordinate:(CLLocationCoordinate2D)lowerLeftCoordinate withUpperRightCoordinate:(CLLocationCoordinate2D)upperRightCoordinate{
    self.radarImage = radarImage;

    MKMapPoint lowerLeft = MKMapPointForCoordinate(lowerLeftCoordinate);
    MKMapPoint upperRight = MKMapPointForCoordinate(upperRightCoordinate);
    mapRect = MKMapRectMake(lowerLeft.x, upperRight.y, upperRight.x - lowerLeft.x, lowerLeft.y - upperRight.y);
    return self;
}

- (CLLocationCoordinate2D)coordinate{
    return MKCoordinateForMapPoint(MKMapPointMake(MKMapRectGetMidX(mapRect), MKMapRectGetMidY(mapRect)));
}

- (MKMapRect)boundingMapRect{
    return mapRect;
}

@end

渲染器:

@implementation FMRadarOverlayRenderer

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context {
    FMRadarOverlay *radarOverlay = (FMRadarOverlay*)self.overlay;
    CGImageRef imageReference = radarOverlay.radarImage.CGImage;

    MKMapRect theMapRect = [radarOverlay boundingMapRect];
    CGRect theRect = [self rectForMapRect:theMapRect];

    CGContextScaleCTM(context, 1.0, -1.0);
    CGContextTranslateCTM(context, 0.0, -theRect.size.height);
    CGContextSetAlpha(context, 0.6);
    CGContextDrawImage(context, theRect, imageReference);
}

@end

以及创建图层的示例:

//using url with map and drawing transparent to check accuracy of rendering
//url for radar data only is http://radar.weather.gov/Conus/RadarImg/latest_radaronly.gif   
NSURL *radarUrl = [NSURL URLWithString:@"http://radar.weather.gov/Conus/RadarImg/latest.gif"];
NSData *radarData = [NSData dataWithContentsOfURL:radarUrl];
UIImage *rawImage = [UIImage imageWithData:radarData];
FMRadarOverlay *radarOverlay = [[FMRadarOverlay alloc] initWithImage:rawImage withLowerLeftCoordinate:CLLocationCoordinate2DMake(21.652538062803, -127.620375523875420) withUpperRightCoordinate:CLLocationCoordinate2DMake(50.406626367301044, -66.517937876818)];

如果您拍摄相同的图像和坐标并使用 kml 文件将它们覆盖在 google 地球上,它们会正确渲染。就好像它没有补偿地球的曲率或其他东西。我已经尝试使用不同的地理参考栅格图层进行此操作,它具有类似的效果。有任何想法吗?

KML 示例:

<?xml version="1.0" encoding="UTF-8"?><kml xmlns="http://earth.google.com/kml/2.0"><Document><name>NWS Radar Images</name><open>1</open><Folder>  <name>National Weather Service</name> <ScreenOverlay>  <name>National Weather Service</name>   <description>National Weather Service Doppler Radar RIDGE Imagery http://radar.weather.gov</description>   <visibility>1</visibility> <Icon>  <href>http://radar.weather.gov/ridge/graphics/nws_google.gif</href>  </Icon>  <overlayXY x="0" y="1" xunits="fraction" yunits="fraction" />  <screenXY x="0" y="1" xunits="fraction" yunits="fraction" />  <rotationXY x="0" y="0" xunits="fraction" yunits="fraction" />  <size x="0" y="0" xunits="fraction" yunits="fraction" />  </ScreenOverlay><ScreenOverlay>  <name>NOAA</name>   <description>National Oceanic and Atomospheric Administration  http://www.noaa.gov</description>   <visibility>1</visibility> <Icon>  <href>http://radar.weather.gov/ridge/graphics/noaa_google.gif</href>  </Icon>  <overlayXY x=".2" y="1" xunits="fraction" yunits="fraction" />  <screenXY x=".2" y="1" xunits="fraction" yunits="fraction" />  <rotationXY x="0" y="0" xunits="fraction" yunits="fraction" />  <size x="0" y="0" xunits="fraction" yunits="fraction" />  </ScreenOverlay></Folder><Folder><name>LATEST_RADARONLY</name><Folder><name>Mosaic</name><ScreenOverlay><name>Legend</name><visibility>1</visibility><Icon><href></href><refreshMode>onInterval</refreshMode><refreshInterval>120</refreshInterval></Icon><overlayXY x="1.0" y="0.5" xunits="fraction" yunits="fraction"/><screenXY x="1.0" y="0.5" xunits="fraction" yunits="fraction"/><rotationXY x="0" y="0" xunits="fraction" yunits="fraction"/></ScreenOverlay><GroundOverlay><name>Mosaic</name><Icon><href>http://radar.weather.gov/ridge/Conus/RadarImg/latest.gif</href><refreshMode>onInterval</refreshMode><refreshInterval>120</refreshInterval></Icon><visibility>1</visibility><LatLonBox><north>50.406626367301044</north><south>21.652538062803</south><east>-66.517937876818</east><west>-127.620375523875420</west></LatLonBox></GroundOverlay></Folder></Folder></Document></kml>

Images of bad rendering: map not drawn correctly

enter image description here


问题在于图像的空间投影。我最终使用了一个名为 gdalwarp 的工具来重新投影墨卡托投影中的图像,就像 MapKit 使用的那样。我在 MapKit 中看到过很多地面覆盖的例子,但它们都忽略了这个重要信息。我认为大多数地理栅格地图都是针对 Google Earth 或 GIS 应用程序等应用程序进行投影的。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

MapKit 通过 MKOverlay 添加栅格地图奇怪的渲染问题 的相关文章

随机推荐

  • 如何在clip()之后在canvas中执行clearRect()?

    我需要在画布中执行clip 后执行clearRect 不幸的是 它对我不起作用 如果我排除 Clip 的意思 则clearRect 工作得很好 我需要在执行clip 后执行clearRect 这可能吗 请找到fidd
  • Scrum:任务依赖性和架构设计任务[关闭]

    Closed 这个问题是无关 目前不接受答案 我有一些 Scrum 问题 任务依赖性 我读过的大多数书籍似乎都将任务视为彼此独立的 一个程序员的任务不会影响另一个程序员的任务 因此可以并行运行 如何处理依赖于另一项任务的任务 任务基于故事
  • UIImagePickerControllerDelegate 未正确响应

    我在 iPhone 3Gs 上使用 iOS 4 2 1 中的 UIImagePickerController 我之前使用过已弃用的方法 void imagePickerController didFinishPickingImage edi
  • 使用事件处理程序更改背景颜色

    我正在尝试创建一个简单的表单 其中将三个 div 堆叠在一起 单击每个框时 它们的颜色需要更改 一红 一绿 一蓝 我只需要使用一个事件处理程序来完成此操作 我被我的代码困住了 我希望你们中的一位能指导我完成这个任务 我真的很感激 这是我的代
  • MIPS 装配标签

    MIPS 的组件会读取每个标签吗 忽略任务和语法 我只是快速地将一些东西放在一起 add reg3 reg1 zero add reg1 reg1 reg2 beq reg1 reg3 BRANCH1 reg2 contents are z
  • 如何在 Windows 机器上的 Python 3.4 中安装 lxml

    我已经花了几个小时在这上面 我是 Python 新手 不知道解决方案是什么 我有 Python 3 4 并且想要使用 docx 这需要lxml 到目前为止我所做的工作流程是 我转到Pythonlxml软件包安装程序页面 但很难知道我需要哪个
  • MongoDB 中的 $unwind 运算符是什么?

    这是我使用 MongoDB 的第一天 所以请慢慢来 我无法理解 unwind接线员 也许是因为英语不是我的母语 db article aggregate project author 1 title 1 tags 1 unwind tags
  • 使用 Jquery 和 '.css' 的 CSS 动画

    所以我有一段代码 目的是播放从中选择的动画动画 css on click The code container gt parent click function element css animation fadeInUp 2s webki
  • 如何重新发送失败的ajax请求?

    我有多个 ajax 请求 每分钟有一些请求数据 其他请求由用户通过 ui 发起 get myurl data done function data do stuff 由于身份验证失败 请求可能会失败 我已经设置了一个全局 ajaxError
  • 如何排除故障 - ImportError: 部署 django 时无法导入设置“mysite.settings”?

    我已经根据 apache 部署说明部署了 django 应用程序 并且与 apache 和 mod python 完美配合 但由于我稍微改变了项目结构 我一直无法让它工作 无论我尝试什么 我都会不断收到以下页面 MOD PYTHON ERR
  • 段落行上单独的背景颜色 - CSS

    I am trying to add background color on lines of title But I can t make it perfect as my client needs me to do My client
  • 无限循环数据库检查

    我正在使用 JDBC 需要不断检查数据库是否有更改的值 我目前拥有的是一个无限循环运行 内部循环迭代不断变化的值 并且每次迭代都会检查数据库 public void runInBG this method called from anoth
  • Jackson - 使用自我引用序列化实体

    我有以下实体 Entity Table name registry entry JsonIgnoreProperties ignoreUnknown true public class RegistryEntry extends Gener
  • Python对包含整数和内部有整数的字符串的列表进行排序

    我如何使用 python 对列表格式进行排序 format 12 sheet 4 sheet 48 sheet 6 sheet busrear phonebox train 像这样 format 4 sheet 6 sheet 12 she
  • 如何在 cc:implementation 中引用 cc:attribute 中声明的值

    我有一个简单的 JSF 2 0 复合组件示例
  • 如何获取Hibernate配置属性?

    我正在使用 hibernate 和 jpa 它是用 persistence xml 配置的 是否可以从 Web 应用程序获取休眠连接属性 Thanks 如果不使用反射并依靠 Hibernate 来保证将来不会破坏您的代码 可能就不行了 您需
  • 如何使标签静态化

    所以我有一个程序 我在其中告诉用户两个骨架是否匹配 但问题是我需要访问label via a class 我不断收到的错误是 Error1 An object reference is required for the non static
  • 如何防止bash中的for循环中的文件名扩展

    在这样的 for 循环中 for i in cat input do echo i done 如果输入文件之一包含类似的条目 a 它会 并且给出 以 a 结尾的文件名 有没有一种简单的方法来防止这种文件名扩展 由于使用多个文件 通配符 se
  • 当 io.py 位于同一目录中时,pandas ImportError C 扩展

    不确定这是否是 pandas 问题 或者我对绝对 相对导入缺乏了解 python c import pandas print pandas version 0 17 1 python V Python 2 7 12 Anaconda 2 4
  • MapKit 通过 MKOverlay 添加栅格地图奇怪的渲染问题

    我已将 NOAA 雷达图像添加到我的天气应用程序中 经过一些测试后 我注意到图像没有在地图上正确绘制 图像的角点似乎接近正确 但当您远离角点时 它会倾斜 下面是相关代码 Overlay implementation FMRadarOverl