¿Cómo mostrar una imagen en un MKOverlayView?

ACTUALIZAR:

Las imágenes que se proyectan en el MKMapView usando un MKOverlayView usan elProyección de Mercator, mientras que la imagen que uso como datos de entrada usa una proyección WGS84. ¿Hay alguna forma de convertir la imagen de entrada, a la proyección correcta WGS84 -> Mercator, sin colocar la imagen en mosaico y se puede hacer sobre la marcha?

Normalmente, puede convertir una imagen a la proyección correcta utilizando el programagdal2tiles. Sin embargo, los datos de entrada cambian cada quince minutos, por lo que la imagen debe convertirse cada quince minutos. Por lo tanto, la conversión debe hacerse sobre la marcha. También quiero que el mosaico lo haga Mapkit y no yo mismo usando gdal2tiles o el marco GDAL.

ACTUALIZAR FIN

Actualmente estoy trabajando en un proyecto que muestra un radar de lluvia en alguna parte del mundo. El radar i, mage es proporcionado por EUMETSAT, ofrecen un archivo KML que se puede cargar en Google Earth o Google Maps. Si cargo el archivo KML en Google Maps, se muestra perfectamente, pero si dibujo la imagen usando un MKOverlayView en un MKMapView, la imagen es ligeramente de.

Por ejemplo, en el lado izquierdo, Google Maps y en el lado derecho, la misma imagen se muestra en un MKMapView.

La superficie que cubre la imagen se puede ver enmapas de Google, el satélite que se utiliza para la imagen es el satélite "Meteosat 0 Degree".

La superficie que cubren ambas imágenes es del mismo tamaño, este es el LatLonBox del archivo KML, especifica dónde se alinean los lados superior, inferior, derecho e izquierdo de un cuadro delimitador para la superposición del suelo.

  <LatLonBox id="GE_MET0D_VP-MPE-latlonbox">
        <north>57.4922</north>
        <south>-57.4922</south>
        <east>57.4922</east>
        <west>-57.4922</west>
        <rotation>0</rotation>
  </LatLonBox>

Creo un nuevo objeto MKOverlay personalizado llamado RadarOverlay con estos parámetros,

[[RadarOverlay alloc] initWithImageData:[[self.currentRadarData objectAtIndex:0] valueForKey:@"Image"] withLowerLeftCoordinate:CLLocationCoordinate2DMake(-57.4922, -57.4922) withUpperRightCoordinate:CLLocationCoordinate2DMake(57.4922, 57.4922)];

La implementación del objeto MKOverlay personalizado; Radar Superposición

- (id) initWithImageData:(NSData*) imageData withLowerLeftCoordinate:(CLLocationCoordinate2D)lowerLeftCoordinate withUpperRightCoordinate:(CLLocationCoordinate2D)upperRightCoordinate
{
     self.radarData = imageData;

     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;
}

La implementación del MKOverlayView personalizado, RadarOverlayView

- (void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
{
    RadarOverlay* radarOverlay = (RadarOverlay*) self.overlay;

    UIImage *image          = [[UIImage alloc] initWithData:radarOverlay.radarData];

    CGImageRef imageReference = image.CGImage;

    MKMapRect theMapRect    = [self.overlay boundingMapRect];
   CGRect theRect           = [self rectForMapRect:theMapRect];
    CGRect clipRect     = [self rectForMapRect:mapRect];

    NSUserDefaults *preferences = [NSUserDefaults standardUserDefaults];
    CGContextSetAlpha(context, [preferences floatForKey:@"RadarTransparency"]);

    CGContextAddRect(context, clipRect);
    CGContextClip(context);

    CGContextDrawImage(context, theRect, imageReference);

    [image release]; 
}

Cuando descargo la imagen, la volteo para que se pueda dibujar fácilmente en MKOverlayView

size_t width    = (CGImageGetWidth(imageReference) / self.scaleFactor);
size_t height   = (CGImageGetHeight(imageReference) / self.scaleFactor);

// Calculate colorspace for the specified image
CGColorSpaceRef imageColorSpace = CGImageGetColorSpace(imageReference);

// Allocate and clear memory for the data of the image
unsigned char *imageData = (unsigned char*) malloc(height * width * 4);
memset(imageData, 0, height * width * 4);

// Define the rect for the image
CGRect imageRect;
if(image.imageOrientation==UIImageOrientationUp || image.imageOrientation==UIImageOrientationDown) 
    imageRect = CGRectMake(0, 0, width, height); 
else 
    imageRect = CGRectMake(0, 0, height, width); 

// Create the imagecontext by defining the colorspace and the address of the location to store the data
CGContextRef imageContext = CGBitmapContextCreate(imageData, width, height, 8, width * 4, imageColorSpace, kCGImageAlphaPremultipliedLast);

CGContextSaveGState(imageContext);

// Scale the image to the opposite orientation so it can be easylier drawn with CGContectDrawImage
CGContextTranslateCTM(imageContext, 0, height);
CGContextScaleCTM(imageContext, 1.0, -1.0);

if(image.imageOrientation==UIImageOrientationLeft) 
{
    CGContextRotateCTM(imageContext, M_PI / 2);
    CGContextTranslateCTM(imageContext, 0, -width);
}
else if(image.imageOrientation==UIImageOrientationRight) 
{
    CGContextRotateCTM(imageContext, - M_PI / 2);
    CGContextTranslateCTM(imageContext, -height, 0);
} 
else if(image.imageOrientation==UIImageOrientationDown) 
{
    CGContextTranslateCTM(imageContext, width, height);
    CGContextRotateCTM(imageContext, M_PI);
}

// Draw the image in the context
CGContextDrawImage(imageContext, imageRect, imageReference);
CGContextRestoreGState(imageContext);

Después de voltear la imagen, la manipulo y luego la guardo en la memoria como un objeto NSData.

Parece que la imagen se estiró, pero se ve bien en el centro de la imagen, que está en el ecuador.

Respuestas a la pregunta(6)

Su respuesta a la pregunta