使用ArcGIS API for Python可以轻松地连接到ArcGIS Online或ArcGIS Enterprise,并利用Python语言的高级功能来分析、可视化和管理GIS数据。
以下是一个绘制数据的简单代码示例:
import arcgis
from arcgis.gis import GIS
from arcgis.features import FeatureLayer, SpatialDataFrame
import pandas as pd
# Connect to your ArcGIS Online or Enterprise account
gis = GIS("url_to_your_portal", "username", "password")
# Search for the feature layer you want to plot
feature_layer_search = gis.content.search("My Feature Layer")
feature_layer = feature_layer_search[0]
# Get the data from the feature layer
sdf = pd.DataFrame.spatial.from_layer(feature_layer.layers[0])
# Plot the data using matplotlib
ax = sdf.plot(kind="scatter", x="longitude", y="latitude", s=5)
# Display the plot
import matplotlib.pyplot as plt
plt.show()
此示例中,我们首先连接到我们的ArcGIS Online账户,并搜索我们想要绘制的要素图层。然后,我们将要素图层的数据导入到一个pandas的空间数据帧中(SpatialDataFrame
)。最后,我们使用plot
函数和matplotlib库来绘制数据,并显示它。