AGSRaster PNG support

Discussion created by worthsparks on Feb 15, 2017
Latest reply on Feb 28, 2017 by worthsparks

I am unable to load a spatially enabled raster .png file into my map. The raster is made up of three files:

  1. sketch.png
  2. sketch.pgwx
  3. sketch.png.aux.xml

It loads fine in ArcMap. In attachment "ArcMap.png", the red lines are coming from the raster.


By using raster.load(completion: ) to set my own completion block, I was able to see that it is getting an error:

Failed to open raster dataset: /Users/Worth/Library/Developer/CoreSimulator/Devices/5690DA36-3E43-4DE1-881A-CF85BE5E2C43/data/Containers/Bundle/Application/79766C92-DBAD-4169-86AC-1CAECD4FABC9/testMapView.app/sketch.png

Here is my ViewController.swift source code:

import UIKit
import ArcGIS

class ViewController: UIViewController {

    @IBOutlet weak var mapView: AGSMapView!
    private var map: AGSMap!
    private var raster: AGSRaster!
    private var rasterLayer: AGSRasterLayer!

    override func viewDidLoad() {

        // create map with assigned spatial reference "web mercator (alternate sphere)"
        self.map = AGSMap(spatialReference: AGSSpatialReference.webMercator())

        // assign a basemap to map
        self.map.basemap = AGSBasemap.topographic()

        // create raster
        self.raster = AGSRaster(name: "sketch", extension: "png")

        // for debugging, verify we can load the raster
        self.raster.load(completion: { (error: Error?) -> Void in
            if let error = error {

        // create raster layer using the raster and name it
        self.rasterLayer = AGSRasterLayer(raster: self.raster)
        self.rasterLayer.name = "sketch raster"

        // add rasterLayer to the map's operationalLayers
        for case let layer as AGSLayer in self.map.operationalLayers {
            print("\nSpatial reference for raster layer \"\(layer.name)\":")
            if let spatialReference = layer.spatialReference {
                print("   WKID = \(spatialReference.wkid)\n")
            } else {
                print("   <undefined>\n")

        // assign map to mapView
        self.mapView.map = map

        // zoom to hard-coded Esri Charlotte office location where raster should appear
        let point = AGSPoint(x: -8992543.0, y: 4177500.0, spatialReference: AGSSpatialReference.webMercator())
        let viewpoint = AGSViewpoint(center: point, scale: 2400.0)

        // use KVO on drawStatus to know when it thinks it is finished drawing
        mapView.addObserver(self, forKeyPath: "drawStatus", options: .new, context: nil)

    override func didReceiveMemoryWarning() {

    override func observeValue(forKeyPath keyPath: String?,
                               of object:          Any?,
                               change:             [NSKeyValueChangeKey : Any]?,
                               context:            UnsafeMutableRawPointer?) {
        guard let keyPath = keyPath else { return }
        if keyPath == "drawStatus" {
            if mapView.drawStatus == AGSDrawStatus.completed {
                guard let viewpoint = self.mapView.currentViewpoint(with: AGSViewpointType.centerAndScale) else { return }
                print("\ndrawStatus == .completed")
                guard let point = viewpoint.targetGeometry as? AGSPoint else { return }
                print("point: (x: \(point.x), y: \(point.y)), scale: \(viewpoint.targetScale)")


What is the best way to load a .png file as a raster in ArcGIS Runtime SDK for iOS?