AGSRasterLayer spatialReference

1340
7
01-13-2017 05:39 AM
WorthSparks1
New Contributor

My code generates a local .png file accompanied by a .pgwx world file. I wish to layer it up as either an operationalLayer or a basemap referenceLayer. I am able to generate the layer object using AGSRasterLayer. And I am able to add it to map.operationalLayers. But nothing shows. Debugging shows me it does not inherit the spatial reference of the map. Maybe this is why it isn't showing. How do I set the spatialReference of a new AGSRasterLayer?

7 Replies
SuganyaBaskaran1
Esri Contributor

Regular png does not have spatial reference, and therefore adding it as an operational layer in a map does not render the layer. It can be added as a base map layer. 

There is an exception though. If the png file is created from ArcGIS desktop and comes with an .aux.xml metadata file, the spatial reference and extent information can be stored in an xml, in which case, the info can be read. 

For the more common case when it's just a png file, there is no spatial reference. 

0 Kudos
WorthSparks
New Contributor III

I just added the the .aux.xml file into the same directory as the .png and .pgwx files. I am still getting the same result, which is no spatial reference on the layer. I am using AGSRaster(fileURL:) to load the raster. Here are the files in the directory:

  • image.png
  • image.pgwx
  • image.png.aux.xml

The app I am building is 100% AGSSpatialReference.webMercator(). Is there any way to verify it is trying to load the .aux.xml file?

0 Kudos
SuganyaBaskaran1
Esri Contributor

I misspoke. The capability to set or define spatial reference is not present in V100.0. You will be able to do that in a future release. Apologies for the inconvenience. 

Suganya

0 Kudos
BernardoArevalo
New Contributor II

Im rather confused as to how were suppose to add the image raster to the operationalLayers, given this code, its says to add it as a basemap but that clearly isn't being done.

https://github.com/Esri/arcgis-runtime-samples-ios/blob/master/arcgis-ios-sdk-samples/Layers/Raster%...

//create raster layer using raster
self.rasterLayer = AGSRasterLayer(raster: raster)
//initialize map with raster layer as the basemap
self.map = AGSMap(basemap: AGSBasemap.imagery())
//assign map to the map view
self.mapView.map = map
//add the raster layer to the operational layers of the map
self.mapView.map?.operationalLayers.add(rasterLayer!)
//set map view's viewpoint to the raster layer's full extent
self.rasterLayer.load { [weak self] (error) in
guard error == nil else {
SVProgressHUD.show(withStatus: error!.localizedDescription, maskType: .gradient)
return
}
if let center = self?.rasterLayer.fullExtent?.center {
self?.mapView.setViewpoint(AGSViewpoint(center: center, scale: 80000))
}
}
0 Kudos
WorthSparks
New Contributor III

Until it is ready, I've changed my code to maintain an affine transform of my graphics and superimpose it in another view. It works well enough for now. Thanks for getting back to me. I look forward to seeing it in a future release.

0 Kudos
BernardoArevalo
New Contributor II

Hey there, I'm having the same problem as you are. Can you explain what affine transform of your graphics means?

I checked the spatial reference as well as the extent, they both came back completely wrong. I tried JPG as well as PNG formats but neither maintain the values correctly.

0 Kudos
BernardoArevalo
New Contributor II

This is what I'm currently doing, I make a call to 

http://resources.arcgis.com/en/help/arcgis-rest-api/index.html#/Export_Image/02r3000000wm000000/

to download a tif file. I store the extent in the result to construct a world file using the algorithm provided here
raster - How to get values to create world file format? - Geographic Information Systems Stack Excha... .

Afterwards given the tif file and constructed tfw file, I download them to the apps documents library. I then try and load the ads raster with the given constructor

let raster = AGSRaster.init(name: extension: )

I then load the raster however when I check the extent, the spatial reference id, extent values, and center point are all wrong regardless of what I set in the tfw.

How did you go about getting around this??

0 Kudos