我也喜欢字典-一直使用'em'。此方法获取一些空间参考属性并将其全部存储在dict中:
def get_coord_sys(self, in_dataset):
"""Get and return info on dataset coord sys/projection"""
spatial_ref = arcpy.Describe(in_dataset).spatialReference
# Get spatial ref props and put in dictionary
spat_ref_dict = {}
spat_ref_dict["name"] = spatial_ref.name
spat_ref_dict["type"] = spatial_ref.type
spat_ref_dict["gcs_code"] = spatial_ref.GCSCode
spat_ref_dict["gcs_name"] = spatial_ref.GCSName
spat_ref_dict["pcs_code"] = spatial_ref.PCSCode
spat_ref_dict["pcs_name"] = spatial_ref.PCSName
return spat_ref_dict
此方法片段从两个要素类中提取点几何,然后稍后再使用这些几何进行trig:
def build_fields_of_view(self):
"""For all KOPs in a study area, build left, right, center FoV triangles"""
try:
fcs = {os.path.join(self.gdb, "WindFarmArray"):[], os.path.join(self.gdb, "KOPs"):[]}
# Build a dict of WTG and KOP array geometries, looks like:
# {'KOPs': [[1, -10049.2697098718, 10856.699451165374],
# [2, 6690.4377855260946, 15602.12386816188]],
# 'WindFarmArray': [[1, 5834.9321158060666, 7909.3822339441513],
# [2, 6111.1759513214511, 7316.9684107396561]]}
for k, v in fcs.iteritems():
rows = arcpy.SearchCursor(k, "", self.sr)
for row in rows:
geom = row.shape
point = geom.getPart()
id = row.getValue("OBJECTID")
v.append([id, point.X, point.Y])
kops = fcs[os.path.join(self.gdb, "KOPs")] # KOP array
wtgs = fcs[os.path.join(self.gdb, "WindFarmArray")] # WTG array
我目前正在从事的工作涉及从矢量要素类和栅格中提取坐标和属性,以便将数据推送到甚至不知道GIS数据是什么的另一软件中。因此,为此我经常使用列表和字典。