1. 程式人生 > 其它 >ArcGIS runtime sdk 移動端常見資料來源載入方式

ArcGIS runtime sdk 移動端常見資料來源載入方式

技術標籤:ArcGIS Proarcgis runtime安卓移動端

1. 載入線上的ArcGIS Portal webmap資源

// inflate MapView from layout
mMapView = (MapView) findViewById(R.id.mapView);

String theURLString = "webmap url";
ArcGISMap mainArcGISMap = new ArcGISMap(theURLString);
Basemap mainBasemap = mainArcGISMap.getBasemap();
LayerList mainLayerList = mainArcGISMap.getOperationalLayers();
mMapView.setMap(mainArcGISMap);

2.支援載入離線的tpk檔案

String theOfflineTiledLayers =getSDCardPath()+ "/ArcGIS/china.tpk";
mainMapView = (MapView) findViewById(R.id.mainMapView);
TileCache mainTileCache = new TileCache(theOfflineTiledLayers);
ArcGISTiledLayer mainArcGISTiledLayer = new ArcGISTiledLayer(mainTileCache);
Basemap mainBasemap = new Basemap(mainArcGISTiledLayer);
ArcGISMap mainArcGISMap = new ArcGISMap(mainBasemap);
mainMapView.setMap(mainArcGISMap);

3.支援載入離線的向量切片包vtpk檔案

String theOfflineTiledLayers = getSDCardPath()+"/ArcGIS/china.vtpk";
mainMapView = (MapView) findViewById(R.id.mainMapView);
ArcGISVectorTiledLayer mainArcGISVectorTiledLayer = new ArcGISVectorTiledLayer(theOfflineTiledLayers);
Basemap mainBasemap = new Basemap(mainArcGISVectorTiledLayer);
ArcGISMap mainArcGISMap = new ArcGISMap(mainBasemap);
mainMapView.setMap(mainArcGISMap);

4. 載入本地shp檔案

// 取消本地shapefile檔案
String path = getSDCardPath()+"/ArcGIS/Shapefile/China.shp";
ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(path);

shapefileFeatureTable.loadAsync();
shapefileFeatureTable.addDoneLoadingListener(() -> {
  if (shapefileFeatureTable.getLoadStatus() == LoadStatus.LOADED) {

    // 利用shapefile檔案建立一個FeatureServer檔案
    FeatureLayer shapefileFeatureLayer = new FeatureLayer(shapefileFeatureTable);

    // 將shapefile圖層新增到業務圖層
    mMapView.getMap().getOperationalLayers().add(shapefileFeatureLayer);

    // 縮放到shapefile範圍
    mMapView.setViewpointAsync(new Viewpoint(shapefileFeatureLayer.getFullExtent()));
  } else {
    String error = "Shapefile feature table failed to load: " + shapefileFeatureTable.getLoadError().toString();
    Toast.makeText(MainActivity.this, error, Toast.LENGTH_LONG).show();
    Log.e(TAG, error);
  }
});

5. 載入移動地圖包mmpk

String mainMMPKPath = getSDCardPath()+"/ArcGIS/China.mmpk";
mainMapView = (MapView) findViewById(R.id.mainMapView);
mainMobileMapPackage = new MobileMapPackage(mainMMPKPath);
mainMobileMapPackage.loadAsync();
mainMobileMapPackage.addDoneLoadingListener(new Runnable() {
    @Override
    public void run() {
        LoadStatus mainLoadStatus = mainMobileMapPackage.getLoadStatus();
        if (mainLoadStatus == LoadStatus.LOADED) {
            List<ArcGISMap> mainArcGISMapL = mainMobileMapPackage.getMaps();

            ArcGISMap mainArcGISMap = mainArcGISMapL.get(0);
            //獲取mmpk中的基礎底圖
            Basemap mainBasemap = mainArcGISMap.getBasemap();
            //後去mmpk中的業務圖層
            LayerList mainMMPKLL = mainArcGISMap.getOperationalLayers();

            mainMapView.setMap(mainArcGISMap);
        }
    }
});

6. 載入桌面匯出的geodatabase檔案

// 本地geodatabase檔案路徑
String path = getSDCardPath() + "/ArcGIS/China.geodatabase";
// 建立geodatabase
final Geodatabase geodatabase = new Geodatabase(path);
//非同步載入geodatabase
geodatabase.loadAsync();
// 當geodatabase讀取成功後將geodatabase載入到資料庫
geodatabase.addDoneLoadingListener(() -> {
  if (geodatabase.getLoadStatus() == LoadStatus.LOADED) {
    List<GeodatabaseFeatureTable> geodatabaseFeatureTables = geodatabase.getGeodatabaseFeatureTables();
    for (int i=0;i<geodatabaseFeatureTables.size();i++){
      GeodatabaseFeatureTable geodatabaseFeatureTable = geodatabaseFeatureTables.get(i);
      geodatabaseFeatureTable.loadAsync();
      //建立要素圖層
      final FeatureLayer featureLayer = new FeatureLayer(geodatabaseFeatureTable);
      featureLayer.addDoneLoadingListener(() -> {
        if (featureLayer.getLoadStatus() == LoadStatus.LOADED) {
          // set viewpoint to the feature layer's extent
          mMapView.setViewpointAsync(new Viewpoint(featureLayer.getFullExtent()));
        } else {
          Toast.makeText(MainActivity.this, "Feature Layer failed to load!", Toast.LENGTH_LONG).show();
          Log.e(TAG, "Feature Layer failed to load!");
        }
      });
      // 新增到地圖
      mMapView.getMap().getOperationalLayers().add(featureLayer);
    }


  } else {
    Toast.makeText(MainActivity.this, "Geodatabase failed to load!", Toast.LENGTH_LONG).show();
    Log.e(TAG, "Geodatabase failed to load!");
  }
});

7. 載入geopackage檔案(開源)

//GeoPackage路徑
String geoPackagePath =getSDCardPath()+"/ArcGIS/China.gpkg";
Log.d(TAG, geoPackagePath);
// 開啟GeoPackage
GeoPackage geoPackage = new GeoPackage(geoPackagePath);
geoPackage.loadAsync();
geoPackage.addDoneLoadingListener(() -> {
  if (geoPackage.getLoadStatus() == LoadStatus.LOADED) {
    List<GeoPackageFeatureTable> geoPackageFeatureTables = geoPackage.getGeoPackageFeatureTables();
    for (int i = 0; i < geoPackageFeatureTables.size(); i++) {
      // 載入圖層
      FeatureTable geoPackageTable = geoPackage.getGeoPackageFeatureTables().get(i);
      // Make sure a feature table was found in the package
      if (geoPackageTable == null) {
        Toast.makeText(MainActivity.this, "No feature table found in the package!", Toast.LENGTH_LONG).show();
        Log.e(TAG, "No feature table found in this package!");
        return;
      }
      // Create a layer to show the feature table
      FeatureLayer featureLayer = new FeatureLayer(geoPackageTable);
      // Add the feature table as a layer to the map (with default symbology)
      mMap.getOperationalLayers().add(featureLayer);
    }
  }else {
    Toast.makeText(MainActivity.this, "GeoPackage failed to load! " + geoPackage.getLoadError(), Toast.LENGTH_LONG).show();
    Log.e(TAG, "GeoPackage failed to load!" + geoPackage.getLoadError());
  }
});

8. 載入slpk

ArcGISSceneLayer sceneLayer = new ArcGISSceneLayer("slpk檔案地址");
scene.getOperationalLayers().add(sceneLayer);

附錄

歡迎大家關注我的收費課程《ArcGIS Pro 2.6和ArcGIS Enterprise學習》,共8小時,有理論有實操:https://edu.csdn.net/course/detail/31690

課程主要包含:

  1. ArcGIS Pro2.6學習

①GIS中的資料

②GIS中的座標系

③企業級地理資料庫(SDE)設定

④資料編輯及拓撲檢查

⑤簡單製圖

⑥空間分析

2.ArcGIS Enterprise學習

①環境部署

②二三維服務釋出(向量切片、要素服務、地圖切片、地形服務、三維服務等)

③使用及運維(詳細介紹如何確定enterprise部署架構,簡單介紹相應的運維工具)

3.開發體系梳理

參考:

https://developers.arcgis.com/arcgis-runtime/