首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从头创建FeatureLayer

从头创建FeatureLayer
EN

Stack Overflow用户
提问于 2020-01-03 11:59:14
回答 1查看 463关注 0票数 0

我正在尝试使用python包创建arcgis.features.FeatureLayer的新实例。

我发现这是不可能的,我穿过文档示例更多的例子,尝试着不同的事情,我发现自己绕着圈,慢慢地,我开始拉出我的声音.

这就是我所拥有的:

代码语言:javascript
复制
import arcgis
import json
from arcgis.gis import GIS

g = GIS(username="my_uname", password="my_pwd")
prop = arcgis.features.FeatureCollection(dictdata={'attributes': {'foo': 'bar', 'lorem': 'ipsum'}})
prop_json=json.dumps({"featureCollection": {"layers": [dict(prop.properties)]}})
item_properties={"type": "Feature Collection", "title": "test_feature_collection_01", "text": prop_json}
it = g.content.add(item_properties=item_properties)

在这一点上-我不明白为什么it.layers产生空的结果。我认为item_properties格式错误导致arcgis忽略了我的层定义.但我没有地方去检查它应该是什么样子。我想我想使用arcgis中的一些东西来为我生成层定义,而不是自己手工处理JSON,所以这是未来的证明。

我以后想要做的是:

代码语言:javascript
复制
lr = arcgis.features.FeatureLayer.fromitem(item=it)

这在TypeError: item must be a type of service, not Feature Collection中失败

所以我想我可以在这里发表文章并使用它。

代码语言:javascript
复制
pit = it.publish()
lr = arcgis.features.FeatureLayer.fromitem(item=pit)

我需要FeatureLayer能够调用append (因此,每当我有任何想要推动的新信息时,我就可以抛出额外的数据)。

但令我惊讶的是,我甚至不能发布这个项目,而且我得到了Exception: Job failed. (对于我的更大的惊喜项目,实际上是通过内容管理器网站发布的)。

我还尝试创建"CSV“项目类型:

代码语言:javascript
复制
import arcgis
import json
from arcgis.gis import GIS


g = GIS(username="my_uname", password="my_pwd")
item_properties={"type": "CSV", "title": "test_feature_collection_01"}
it = g.content.add(item_properties=item_properties, data="/tmp/foo.csv")
pit = it.publish()

lr = arcgis.features.FeatureLayer.fromitem(item=pit)

但是,这会导致没有层的项,这会导致未处理的异常IndexError: list index out of range (因为方法arcgis调用试图到达为空的层.)

请帮帮我..。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-03 13:29:24

我设法得到了我需要的-.然而,我仍然在努力理解如何使arcgis直接从我的硬盘上传一些数据,而不是从另一个项目。总之,这里的代码是:

代码语言:javascript
复制
import arcgis
import json
from arcgis.gis import GIS

g = GIS(username="my_uname", password="my_pwd")

item_properties_1={"type": "CSV", "title": "test_feature_collection_01"}
it_1 = g.content.add(item_properties=item_properties_1, data="/tmp/my_data.csv")
pit_1 = it_1.publish()
table = arcgis.features.Table.fromitem(item=pit_1)

# Now we want to throw some extra data, do we have to create another item to do that??

item_properties_2={"type": "CSV", "title": "test_feature_collection_02"}
it_2 = g.content.add(item_properties=item_properties_2, data="/tmp/more_data.csv")
source_info = g.content.analyze(file_path='/tmp/more_data.csv', file_type='csv', location_type='none')

# Data from `it_2` appears to be appended to `table` container (which is published item, not item itself)

table.append(item_id=it_2.id, upload_format='csv', source_info=source_info["publishParameters"], upsert=False)

因此,要将一些数据附加到现有的项中,我必须创建新项.

编辑:

要上传数据而不必创建临时项,请使用edit_features而不是append

代码语言:javascript
复制
# create table like shown in sample above

from arcgis import features
f = features.Feature.from_dict({"attributes": {"some_attribute": "value"}})
fs = features.FeatureSet(features=[f])
table.edit_features(adds=fs)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59578252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档