FeatureLayer(要素图层)
表示由要素组成的图层; FeatureLayer中的要素包括几何和一组一致的字段。FeatureLayer中的功能可以显示在地图上,查询,编辑和选择(以视觉方式突出显示)。
每个FeatureLayer对应一个FeatureTable,它被传递给FeatureLayer构造函数。
FeatureTable
表示要素的表。
FeatureTable提供queryFeaturesAsync(QueryParameters)空间和属性查询,以及添加,更新和删除功能的方法。
使用构造函数创建FeatureTable子类的实例。FeatureTable用于创建FeatureLayer。FeatureLayer添加到地图后,将在地图中显示表格的要素。
要素服务(Feature Service)
String sample_service_url = "http://sampleserver6.arcgisonline.com/arcgis/rest/services/Energy/Geology/FeatureServer/9";
mMapView = (MapView) findViewById(R.id.mapView);
ArcGISMap map = new ArcGISMap(Basemap.createTerrainWithLabels());
map.setInitialViewpoint(new Viewpoint(new Point(-13176752, 4090404, SpatialReferences.getWebMercator()), 500000));
ServiceFeatureTable serviceFeatureTable = new ServiceFeatureTable(sample_service_url);
FeatureLayer featureLayer = new FeatureLayer(serviceFeatureTable);
map.getOperationalLayers().add(featureLayer);
mMapView.setMap(map);
Geodatabase
包含离线要素数据的移动地理数据库。
Geodatabase类用于打开和访问移动地理数据库的内容。地理数据库是ArcGIS服务(由GeodatabaseSyncTask创建)创建的数据的脱机副本,或者可以使用ArcMap或ArcGIS Pro创建。地理数据库包含一个或多个GeodatabaseFeatureTables。每个都GeodatabaseFeatureTable包含属性数据。对于空间要素,它还存储几何和渲染信息。
GeodatabaseFeatureTable可用于创建FeatureLayer可添加到地图并使用mapview查看的地理数据库 。
地理数据库实现可加载的接口; 加载地理数据库后,可以访问地理数据库要素表。
private void loadGeodatabase() {
String path = Environment.getExternalStorageDirectory().getAbsolutePath() + "LA_Trails.geodatabase";
final Geodatabase geodatabase = new Geodatabase(path);
geodatabase.loadAsync();
geodatabase.addDoneLoadingListener(() -> {
if (geodatabase.getLoadStatus() == LoadStatus.LOADED) {
GeodatabaseFeatureTable geodatabaseFeatureTable = geodatabase.getGeodatabaseFeatureTable("Trailheads");
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(FeatureLayerGeodatabaseActivity.this, "Feature Layer failed to load!", Toast.LENGTH_LONG).show();
Log.e(TAG, "Feature Layer failed to load!");
}
});
// add feature layer to the map
mMapView.getMap().getOperationalLayers().add(featureLayer);
} else {
Toast.makeText(FeatureLayerGeodatabaseActivity.this, "Geodatabase failed to load!", Toast.LENGTH_LONG).show();
Log.e(TAG, "Geodatabase failed to load!");
}
});
}
GeoPackage
GeoPackage是一种开放的,基于标准的,独立于平台的,可移植的,自我描述的紧凑格式,用于传输地理空间信息。它是一个独立于平台的SQLite数据库文件,包含GeoPackage数据和元数据表。
/**
* Opens a GeoPackage from local storage and adds it to a map.
*/
private void openGeoPackage() {
// Get the full path to the local GeoPackage
String geoPackagePath = Environment.getExternalStorageDirectory().getAbsolutePath() + "/AuroraCO.gpkg";
// Open the GeoPackage
GeoPackage geoPackage = new GeoPackage(geoPackagePath);
geoPackage.loadAsync();
geoPackage.addDoneLoadingListener(() -> {
if (geoPackage.getLoadStatus() == LoadStatus.LOADED) {
// Read the feature tables and get the first one
FeatureTable geoPackageTable = geoPackage.getGeoPackageFeatureTables().get(0);
// Make sure a feature table was found in the package
if (geoPackageTable == null) {
Toast.makeText(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(this, "GeoPackage failed to load! " + geoPackage.getLoadError(), Toast.LENGTH_LONG).show();
Log.e(TAG, "GeoPackage failed to load!" + geoPackage.getLoadError());
}
});
}
shp文件
private void featureLayerShapefile() {
ShapefileFeatureTable shapefileFeatureTable = new ShapefileFeatureTable(
Environment.getExternalStorageDirectory().getAbsolutePath() + "/xhj.shp");
shapefileFeatureTable.loadAsync();
shapefileFeatureTable.addDoneLoadingListener(() -> {
if (shapefileFeatureTable.getLoadStatus() == LoadStatus.LOADED) {
// create a feature layer to display the shapefile
FeatureLayer shapefileFeatureLayer = new FeatureLayer(shapefileFeatureTable);
// add the feature layer to the map
mMapView.getMap().getOperationalLayers().add(shapefileFeatureLayer);
// zoom the map to the extent of the shapefile
mMapView.setViewpointAsync(new Viewpoint(shapefileFeatureLayer.getFullExtent()));
} else {
String error = "Shapefile feature table failed to load: " + shapefileFeatureTable.getLoadError().toString();
Toast.makeText(this, error, Toast.LENGTH_LONG).show();
Log.e(TAG, error);
}
});
}