【问题标题】:MapKit Adding Raster Map via MKOverlay Weird Rendering IssueMapKit 通过 MKOverlay 奇怪的渲染问题添加光栅地图
【发布时间】:2023-04-02 01:45:01
【问题描述】:

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

叠加层:

@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 Earth 上,它们会正确呈现。这就像它没有补偿地球的曲率或其他东西。我已经尝试过使用不同的地理参考栅格图层,它具有类似的效果。有什么想法吗?

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>

渲染不良的图像:

【问题讨论】:

    标签: mapkit mkoverlay


    【解决方案1】:

    问题在于图像的空间投影。我最终使用了一个名为 gdalwarp 的工具来重新投影像 MapKit 使用的墨卡托投影中的图像。我在 MapKit 中看到了很多地面叠加层的示例,所有这些示例都忽略了这些重要信息。我认为大多数地理栅格地图都是为 Google 地球或 GIS 应用程序等应用程序投影的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-02-15
      • 2014-02-20
      • 2012-08-25
      • 1970-01-01
      • 2021-08-16
      • 2011-07-30
      • 2023-01-02
      • 2018-07-14
      相关资源
      最近更新 更多