I try to load local tif files with flowing codes (I do not set any license), but get errors, I make sure the path is ok, and the tif file can be opened in other GIS software.
so how to load the local tif files?
my code:
val path = Environment.getExternalStorageDirectory().absolutePath + "/tiftest/tiftest/tiftest.tif"
val raster = Raster.createWithPath(path)
val rasterLayer = RasterLayer(raster)
activity.lifecycleScope.launch {
rasterLayer.load().onSuccess {
map!!.operationalLayers.add(rasterLayer)
}.onFailure {
it.printStackTrace()
Log.e("TAG", "Raster layer failed to load.")
}
}
error info :
Hello,
it looks like an issue with the tif file path on the device
Tried this in 100.15.0 and 200.1.0 and I am able to see the local raster .tif load fine.
Pushed the local TIF file using the below ADB command
./adb push XXX.tif /sdcard/Android/data/com.esri.arcgismaps.sample.displaydimensions/files
Code snippet:
val map = ArcGISMap(BasemapStyle.ArcGISTopographic)
mapView.map = map
val rasterFile = getExternalFilesDir(null)?.path + "/XXX.tif"
val raster = Raster.createWithPath(rasterFile)
val rasterLayer = RasterLayer(raster)
lifecycleScope.launch {
rasterLayer.load().onSuccess {
map.operationalLayers.add(rasterLayer)
rasterLayer.fullExtent?.let { it ->
mapView.setViewpointGeometry(
it.extent,
50.0
)
}
Log.i(localClassName, "rasterLayer loaded successfully.")
}.onFailure {
showError("Error loading rasterLayer: ${it.message}")
}
}
Let me know, if this helps?
Thanks for the answer, using your code, it doesn't report a file error when loading the tif anymore, but he doesn't show up on the map. Is there any other action I need to do? I put the .tif / .prj / .tfw / . tif.aux.xml / .tig.ovr all five files into the same directory, specifying that the .tif file be loaded.
Thanks for the answer, using your code, it doesn't report a file error when loading the tif anymore, but he doesn't show up on the map. Is there any other action I need to do? I put the .tif / .prj / .tfw / . tif.aux.xml / .tig.ovr all five files into the same directory, specifying that the .tif file be loaded.
val path = activity.getExternalFilesDir(null)?.path + "/CHY.tif"
val raster = Raster.createWithPath(path)
val rasterLayer = RasterLayer(raster)
activity.lifecycleScope.launch {
rasterLayer.load().onSuccess {
Log.d("joker", "success!!!!!!!!!!!")
map?.operationalLayers?.clear()
map!!.operationalLayers.add(rasterLayer)
rasterLayer.fullExtent?.let { p ->
mapView!!.setViewpoint(viewpoint)
}
}.onFailure {
it.printStackTrace()
Log.e("joker", it.message!!)
Log.e("TAG", "Raster layer failed to load.")
}
Looks like an issue with the viewpoint. Probably need to zoom more to that area, you might be able to see it.