arcgis runtime sdk for android 系列 - 加载地形数据小结

1
分享 2020-04-07
三维场景中有时候需要使用地形图,展现真实感。

 这篇文章就总结一下现在安卓端支持的加载地形图的方式。
 
包括两种加载离线地形数据和一种在线地图服务方式
 
1. 直接在安卓端加载影像数据,支持的格式:

ASRP/USRP
CIB1, 5, 10
DTED0, 1, 2
GeoTIFF
HFA
HRE
IMG
JPEG
JPEG 2000
NITF
PNG
RPF
SRTM1, 2

关键代码:
try {
// add an elevation source to the scene by passing the URI of the raster package to the constructor
RasterElevationSource rasterElevationSource = new RasterElevationSource(filePaths);

// add a listener to perform operations when the load status of the elevation source changes
rasterElevationSource.addLoadStatusChangedListener(loadStatusChangedEvent -> {
// when elevation source loads
if (loadStatusChangedEvent.getNewLoadStatus() == LoadStatus.LOADED) {
// add the elevation source to the elevation sources of the scene
mSceneView.getScene().getBaseSurface().getElevationSources().add(rasterElevationSource);
} else if (loadStatusChangedEvent.getNewLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
// notify user that the elevation source has failed to load
logErrorToUser(getString(R.string.error_raster_elevation_source_load_failure_message,
rasterElevationSource.getLoadError()));
}
});

// load the elevation source asynchronously
rasterElevationSource.loadAsync();
} catch (IllegalArgumentException e) {
// catch exception thrown by RasterElevationSource when a file is invalid/not found
logErrorToUser(getString(R.string.error_raster_elevation_source_load_failure_message, e.getMessage()));
}

 2. 使用高程影像切片包tpk,切片的压缩格式使用lerc方式。
 
关键代码:
 // add a ArcGISTiledElevationSource to the scene by passing the URI of the local tile package to the constructor
ArcGISTiledElevationSource tiledElevationSource = new ArcGISTiledElevationSource(
Environment.getExternalStorageDirectory() + getString(R.string.local_tile_package_location));

// add a listener to perform operations when the load status of the ArcGISTiledElevationSource changes
tiledElevationSource.addLoadStatusChangedListener(loadStatusChangedEvent -> {
// when ArcGISTiledElevationSource loads
if (loadStatusChangedEvent.getNewLoadStatus() == LoadStatus.LOADED) {
// add the ArcGISTiledElevationSource to the elevation sources of the scene
mSceneView.getScene().getBaseSurface().getElevationSources().add(tiledElevationSource);
} else if (loadStatusChangedEvent.getNewLoadStatus() == LoadStatus.FAILED_TO_LOAD) {
// notify user that the ArcGISTiledElevationSource has failed to load
logErrorToUser(getString(R.string.error_tiled_elevation_source_load_failure_message));
}
});

// load the ArcGISTiledElevationSource asynchronously
tiledElevationSource.loadAsync();

3. 加载在线的地形图服务,也就是将高程影像服务发布切片服务,切片的压缩格式使用lerc格式即可。
 
关键代码:
 // add base surface for elevation data
final Surface surface = new Surface();
ArcGISTiledElevationSource elevationSource = new ArcGISTiledElevationSource(getString(R.string.elevation_image_service_url));
surface.getElevationSources().add(elevationSource);
scene.setBaseSurface(surface);

 
参考资料:
  1. https://developers.arcgis.com/android/latest/java/sample-code/create-terrain-from-a-local-raster/
  2. https://developers.arcgis.com/android/latest/java/sample-code/create-terrain-from-a-local-tile-package
  3. https://github.com/Esri/arcgis-runtime-samples-android/blob/master/java/terrain-exaggeration/src/main/java/com/esri/arcgisruntime/sample/terrainexaggeration/MainActivity.java 

0 个评论

要回复文章请先登录注册