ArcGIS——图层与数据

该文章翻译至ArcGIS官网教程Layers and data,采用了Google翻译辅助,对不恰当的名称和语句做了修改。有能力的建议直接阅读英文原版。

1. 介绍

图层是可以在Map对象中使用的数据集合。可以在客户端上创建图层数据,由ArcGIS Online和ArcGIS Enterprise托管,或由外部服务器托管。

2. 数据——要素的集合

图层通常用于管理和显示大量要素。要素是地理位置或实体的记录。每个要素都包含为几何图形(点,折线或多边形)定义的空间坐标和存储其他信息的属性字段。这些要素集可以被认为是:

  • 结构化:如果每个要素具有相同的几何图形和相同属性的关键字
  • 非结构化:如果任何要素具有不同几何图形或不同属性的关键字

注意:有时会说要素有模式,而几何图形没有模式。

使用一组要素时,一般的经验法则是:

3. 核心图层的类型

ArcGIS JS API具有许多可用于访问和显示图层数据的图层类。所有类都继承自Layer。使用哪个类取决于数据的格式和数据的存储位置。不同的图层类型显示出不同的功能。

下面是最常见的图层类的列表。

Class Data Storage Capabilities
FeatureLayer 存储在ArcGIS Online或ArcGIS Enterprise中的地理数据 Displaying, querying, filtering and editing large amounts of geographic features.
GraphicsLayer 临时存储在内存中的地理数据 Displaying individual geographic features as graphics, visual aids or text on the map.
CSVLayer/KMLLayer/GeoJSONLayer 存储在通过网络访问的外部文件中的地理或表格数据 Displaying data stored in an external file format as a layer.
TileLayer/VectorTileLayer 数据集存储在切片模式中用于快速渲染 Displaying basemaps and other tiled datasets for geographic context.
MapImageLayer 地理数据存储在ArcGIS Enterprise中并以图像方式呈现 Displaying layers dynamically rendered by an ArcGIS Server service.
ImageryLayer 存储在ArcGIS Enterprise中的地理遥感图像 Displaying satellite or other imagery data.

4. 使用FeatureLayer展示数据源

FeatureLayer是引用地理要素集合的图层。集合中的所有要素必须具有相同的几何类型和属性字段。

要素图层数据源可以在应用程序加载的数据的内存中,也可以从ArcGIS Online或ArcGIS Enterprise上托管的REST API服务请求数据。在ArcGIS Online或ArcGIS Enterprise中托管数据是首选方法,尤其适用于访问和显示大量地理数据。要数图层在客户端和服务器上都经过高度优化,可以快速显示并支持各种功能,包括:

ArcGIS for Developers和ArcGIS Online提供了用于导入GeoJSON,Excel,CSV,geodatabases和shapefile等数据的工具。导入数据会在ArcGIS Online中创建可用作服务器端数据源的要素图层项目。

4.1 客户端数据源

通常,图层数据是从ArcGIS Online或ArcGIS Enterprise上托管的REST API服务加载的,但也可以直接从内存中的一组要素创建要素图层。

例如,下面以JSON格式给出了加利福尼亚州洛杉矶的要素集合。可以将该数据转换为可在FeatureLayer中显示的格式。

{
  "places": [
    {
      "id": 1,
      "address": "200 N Spring St, Los Angeles, CA 90012",
      "longitude": -118.24354,
      "latitude": 34.05389
    },
    {
      "id": 2,
      "address": "419 N Fairfax Ave, Los Angeles, CA 90036",
      "longitude": -118.31966,
      "latitude": 34.13375
    }
  ]
}

从上面的JSON数据创建要素图层的第一步是将两个场所数据转换为具有attributesgeometry属性的Graphic`对象。

Property Type Description
attributes Object Key-value 形式用于存储有关要素的地理信息
geometry Geometry 提供相对于坐标系的位置要素。可能的值是Point(点),Polygon(多边形)和Polyline(多线段)对象

以下代码示例将包含两个场所数据的数组转换为Graphic对象数组。

var graphics = places.map(function (place) {
  return new Graphic({
    attributes: {
      ObjectId: place.id,
      address: place.address
    },
    geometry: {
      longitude: place.longitude,
      latitude: place.latitude
    }
  });
});

第二个步骤是创建一个FeatureLayer对象,并指定至少所述objectIdFieldfieldsrenderer,和source以下代码示例将场所数组转换为Graphic对象数组。

var graphics = places.map(function (place) {
  return new Graphic({
    attributes: {
      ObjectId: place.id,
      address: place.address
    },
    geometry: {
      longitude: place.longitude,
      latitude: place.latitude
    }
  });
});

在创建第二个步骤FeatureLayer是实际创建一个FeatureLayer对象,并至少指定下表中所所述的objectIdFieldfieldsrenderer,和source属性。

Property Type Description
source Collection<Graphic> Graphic对象的集合用于创建要素图层
renderer Renderer 渲染器用于在要素的位置显示符号
objectIdField String 标识要素图层的名称
fields Object[] 包含字段的名称和值的JavaScript对象数组
popupTemplate PopupTemplate 要素图层中要素的弹出模板

以下代码示例创建一个 FeatureLayer并将该source属性显式设置为graphicsAutocasting用于设置的rendererpopupfields特性。

var featureLayer = new FeatureLayer({
  source: graphics,
  renderer: {
    type: "simple",                    // autocasts as new SimpleRenderer()
    symbol: {                          // autocasts as new SimpleMarkerSymbol()
      type: "simple-marker",
      color: "#102A44",
      outline: {                       // autocasts as new SimpleLineSymbol()
        color: "#598DD8",
         2
      }
    }
  },
  popupTemplate: {                     // autocasts as new PopupTemplate()
    title: "Places in Los Angeles",
    content: [{
      type: "fields",
      fieldInfos: [
        {
          fieldName: "address",
          label: "Address",
          visible: true
        }
      ]
    }]
  },
  objectIdField: "ObjectID",   // This must be defined when creating a layer from `Graphic` objects
  fields: [
    {
      name: "ObjectID",
      alias: "ObjectID",
      type: "oid"
    },
    {
      name: "address",
      alias: "address",
      type: "string"
    }
  ]
});

map.layers.add(featureLayer);

了解有关自动 autocasting从graphic数组创建要素图层的详细信息。探索如何在示例代码中使用要素图层的所有功能。

4.2 服务器端数据源

FeatureLayer还支持从url属性指定的REST API服务返回的要素集合。这是访问和显示大型数据集的最有效方法。要素图层将与要素服务一起使用,以尽可能高效地检索要素,如果启用,将提供对其他功能(如编辑)的访问。

var layer = new FeatureLayer({
  url: "https://services3.arcgis.com/GVgbJbqm8hXASVYi/arcgis/rest/services/Trailheads/FeatureServer/0"
});

map.layers.add(layer);

add a layer to a map教程中了解有关向地图添加图层的详细信息。

除URL外,您还可以引用存储在ArcGIS Online或ArcGIS Enterprise中的图层项。这些项引用REST API服务,该服务存储层的数据以及其他配置选项。

var layer = new FeatureLayer({
  portalItem: {
    id: "883cedb8c9fe4524b64d47666ed234a7",
    portal: "https://www.arcgis.com"               // Default: The ArcGIS Online Portal
  }
});

map.layers.add(layer);

adding a layer from an item教程中了解从项目中添加图层的详细信息。

5. 用GraphicsLayer(图形层)显示图形

图形通常用于将文本、形状和具有不同几何形状的图像添加到地图中。创建图形图层的最简单方法是将Graphic对象创建为数组,并将此数组传递给GraphicsLayer对象的属性graphics

每个Graphic类都包含以下属性:

属性 类型 描述
attributes Object 用于存储有关要素的地理信息的键值对
geometry Geometry 提供的位置相对于一个特征的坐标系 可能的值是PointPolygonPolyline对象
popupTemplate PopupTemplate 图形的弹出模板
symbol Symbol 定义图形在图层中的渲染方式

下面的代码示例创建一个Graphic,该对象具有Point几何类型、弹出窗口和符号的新对象。然后通过将一组Graphic对象传递给graphics属性来创建一个新的GraphicsLayer

var pointGraphic = new Graphic({
  attributes: {
    name: "LA City Hall",
    address: "200 N Spring St, Los Angeles, CA 90012"
  },
  geometry: {
    type: "point",                     // autocasts as new Point()
    longitude: -118.24354,
    latitude: 34.05389
  },
  symbol: {
    type: "simple-marker",             // autocasts as new SimpleMarkerSymbol()
    color: [ 226, 119, 40 ],
    outline: {                         // autocasts as SimpleLineSymbol()
      color: [ 255, 255, 255 ],
       2
    }
  },
  popupTemplate: {                     // autocasts as new PopupTemplate()
    title: "Places in Los Angeles",
    content: [{
      type: "fields",
      fieldInfos: [
        {
          fieldName: "name",
          label: "Name",
          visible: true
        },
        {
          fieldName: "address",
          label: "Address",
          visible: true
        }
      ]
    }]
  },
});

var graphicsLayer = new GraphicsLayer({
  graphics: [ pointGraphic ]
});

map.layers.add(graphicsLayer);

通过 displaying point, polyline, and polygon graphics教程了解更多向视图添加图形的信息,通过autocasting了解更多自动转换的信息。

6. 使用外部数据源

其他类型的数据和文件由特定Layer的子类直接支持。其中包括用于处理外部文件(如CSV或GeoJSON文件)或集成外部服务(如必应地图)的特定类型的图层。

图层子类 数据源 数据类型 特征 限制
CSVLayer CSV文件 矢量图形作为点下载 Client-side processing, popup templates, renderers with 2D and 3D symbols 可能需要大量下载,具体取决于功能的数量
GeoRSSLayer GeoRSS feed 矢量图形作为点,折线和多边形 - Graphics storage
- Popup templates
- 无3D支持 不支持渲染器
GeoJSONLayer GeoJSON文件 矢量图形作为点,折线和多边形 GeoJSON数据创建图层 - 每个GeoJSON层都接受单一几何类型
- 数据必须符合RFC 7946规范
KMLLayer KML数据源 N / A N / A N / A
WMSLayer WMS Service Portal Item 栅格数据导出为单个图像 OGC规范 N / A
WMTSLayer - WMTS tile services
- Portal Item
图像切片 OGC规范 N / A
OpenStreetMapLayer OpenStreetMap tile services 图像切片 Displays OpenStreetMap tiled content N / A
BingMapsLayer Bing Spatial Data Service data N / A N / A N / A

每个层都需要不同的属性,具体取决于它们的初始化方式。有关详细信息,请参阅每个图层类型。创建CSVLayer图层的示例如下所示。

var earthquakesLayer = new CSVLayer({
  url: "https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/2.5_week.csv",
  copyright: "USGS Earthquakes",
  latitudeField: "latitude", // Defaults to "latitude"
  longitudeField: "longitude" // Defaults to "longitude"
});

map.layers.add(earthquakesLayer)

通过 displaying point, polyline, and polygon graphics教程了解更多向视图添加图形的信息,通过autocasting了解更多自动转换的信息。

7. 使用底图和切片图层

底图用于通过显示道路,边界,建筑物和其他数据来为地图提供地理背景。底图通常用切片方式提供服务以便更快地渲染。栅格底图请求预先创建的图像。矢量底图以压缩二进制格式请求数据并在客户端上设置样式。

可以使用 Vector Tile Style Editor自定义矢量底图。自定义数据也可以使用ArcGIS Online或ArcGIS Enterprise作为矢量或栅格切片发布。

Map可以使用basemap属性控制特定对象的底图,该属性可以是标识特定底图或Basemap对象的字符串。

var map = new Map({
  basemap: "streets-navigation-vector"
})

Selecting a basemap的教程中了解更多信息。

8. 使用ArcGIS Enterprise中的地图服务

MapImageLayer用于在ArcGIS Enterprise中显示地图服务中的数据。地图服务通常包含多个子图层和复杂的制图。Map Services将数据呈现为动态生成并在客户端上显示的服务器端图像。

9. 使用栅格和图像数据

ImageryLayer用于显示存储在ArcGIS Enterprise 中的图像服务中的图像或其他基于栅格的数据。ImageryLayer通常用于显示和分析从无人机或卫星捕获的原始图像数据或用于显示科学数据。

原文地址:https://www.cnblogs.com/koubeisi/p/11366773.html