本文整理汇总了Python中arcrest.agol.FeatureLayer.addFeatures方法的典型用法代码示例。如果您正苦于以下问题:Python FeatureLayer.addFeatures方法的具体用法?Python FeatureLayer.addFeatures怎么用?Python FeatureLayer.addFeatures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arcrest.agol.FeatureLayer
的用法示例。
在下文中一共展示了FeatureLayer.addFeatures方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AddFeaturesToFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import addFeatures [as 别名]
def AddFeaturesToFeatureLayer(self,url,pathToFeatureClass):
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
return fl.addFeatures(fc=pathToFeatureClass)
except arcpy.ExecuteError:
line, filename, synerror = Common.trace()
raise ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
"arcpyError": arcpy.GetMessages(2),
}
)
except:
line, filename, synerror = Common.trace()
raise ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fl = None
del fl
gc.collect()
示例2: RemoveAndAddFeatures
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import addFeatures [as 别名]
def RemoveAndAddFeatures(self, url, pathToFeatureClass,id_field,chunksize=1000):
fl = None
try:
if arcpyFound == False:
raise common.ArcRestHelperError({
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": 'featureservicetools',
"synerror": "ArcPy required for this function"
})
arcpy.env.overwriteOutput = True
tempaddlayer= 'ewtdwedfew'
if not arcpy.Exists(pathToFeatureClass):
raise common.ArcRestHelperError({
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": 'featureservicetools',
"synerror": "%s does not exist" % pathToFeatureClass
}
)
fields = arcpy.ListFields(pathToFeatureClass,wild_card=id_field)
if len(fields) == 0:
raise common.ArcRestHelperError({
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": 'featureservicetools',
"synerror": "%s field does not exist" % id_field
})
strFld = True
if fields[0].type != 'String':
strFld = False
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
id_field_local = arcpy.AddFieldDelimiters(pathToFeatureClass, id_field)
idlist = []
print( arcpy.GetCount_management(in_rows=pathToFeatureClass).getOutput(0) + " features in the layer")
with arcpy.da.SearchCursor(pathToFeatureClass, (id_field)) as cursor:
allidlist = []
for row in cursor:
if (strFld):
idlist.append("'" + row[0] +"'")
else:
idlist.append(row[0])
if len(idlist) >= chunksize:
allidlist.append(idlist)
idlist = []
if len(idlist) > 0:
allidlist.append(idlist)
for idlist in allidlist:
idstring = ' in (' + ','.join(idlist) + ')'
sql = id_field + idstring
sqlLocalFC = id_field_local + idstring
results = fl.deleteFeatures(where=sql,
rollbackOnFailure=True)
if 'error' in results:
raise common.ArcRestHelperError({
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": 'featureservicetools',
"synerror":results['error']
})
elif 'deleteResults' in results:
print ("%s features deleted" % len(results['deleteResults']))
for itm in results['deleteResults']:
if itm['success'] != True:
print (itm)
else:
print (results)
arcpy.MakeFeatureLayer_management(pathToFeatureClass,tempaddlayer,sqlLocalFC)
results = fl.addFeatures(fc=tempaddlayer)
if 'error' in results:
raise common.ArcRestHelperError({
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": 'featureservicetools',
"synerror":results['error']
})
elif 'addResults' in results:
print ("%s features added" % len(results['addResults']))
for itm in results['addResults']:
if itm['success'] != True:
print (itm)
else:
print (results)
idlist = []
if 'error' in results:
raise common.ArcRestHelperError({
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
#.........这里部分代码省略.........
示例3: AddFeaturesToFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import addFeatures [as 别名]
def AddFeaturesToFeatureLayer(self,url,pathToFeatureClass,chunksize=0,lowerCaseFieldNames=False):
if arcpyFound == False:
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": inspect.currentframe().f_back.f_lineno,
"filename": 'featureservicetools',
"synerror": "ArcPy required for this function"
})
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
if chunksize > 0:
fc = os.path.basename(pathToFeatureClass)
inDesc = arcpy.Describe(pathToFeatureClass)
oidName = arcpy.AddFieldDelimiters(pathToFeatureClass,inDesc.oidFieldName)
arr = arcpy.da.FeatureClassToNumPyArray(pathToFeatureClass, (oidName))
syncSoFar = 0
messages = {'addResults':[],'errors':[]}
total = len(arr)
errorCount = 0
if total == '0':
print ("0 features in %s" % pathToFeatureClass)
return "0 features in %s" % pathToFeatureClass
print ("%s features in layer" % (total))
arcpy.env.overwriteOutput = True
if int(total) < int(chunksize):
return fl.addFeatures(fc=pathToFeatureClass,lowerCaseFieldNames=lowerCaseFieldNames)
else:
newArr = chunklist(arr,chunksize)
exprList = ["{0} >= {1} AND {0} <= {2}".format(oidName, nArr[0][0], nArr[len(nArr)-1][0])
for nArr in newArr]
for expr in exprList:
UploadLayer = arcpy.MakeFeatureLayer_management(pathToFeatureClass, 'TEMPCOPY', expr).getOutput(0)
#print(arcpy.GetCount_management(in_rows=UploadLayer).getOutput(0) + " features in the chunk")
results = fl.addFeatures(fc=UploadLayer,lowerCaseFieldNames=lowerCaseFieldNames)
chunkCount = arcpy.GetCount_management(in_rows=UploadLayer).getOutput(0)
print(chunkCount + " features in the chunk")
if chunkCount > 0:
if results is not None and 'addResults' in results and results['addResults'] is not None:
featSucces = 0
for result in results['addResults']:
if 'success' in result:
if result['success'] == False:
if 'error' in result:
errorCount = errorCount + 1
print ("\tError info: %s" % (result))
else:
featSucces = featSucces + 1
syncSoFar = syncSoFar + featSucces
print ("%s features added in this chunk" % (featSucces))
print ("%s/%s features added, %s errors" % (syncSoFar,total,errorCount ))
if 'addResults' in messages:
messages['addResults'] = messages['addResults'] + results['addResults']
else:
messages['addResults'] = results['addResults']
else:
messages['errors'] = result
return messages
else:
return fl.addFeatures(fc=pathToFeatureClass,lowerCaseFieldNames=lowerCaseFieldNames)
except arcpy.ExecuteError:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
"arcpyError": arcpy.GetMessages(2),
}
)
except:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fl = None
del fl
gc.collect()
示例4: AddFeaturesToFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import addFeatures [as 别名]
def AddFeaturesToFeatureLayer(self, url, pathToFeatureClass, chunksize=0, lowerCaseFieldNames=False):
"""Appends local features to a hosted feature service layer.
Args:
url (str): The URL of the feature service layer.
pathToFeatureClass (str): The path of the feature class on disk.
chunksize (int): The maximum amount of features to upload at a time. Defaults to 0.
lowerCaseFieldNames (bool): A boolean value indicating if field names should be converted
to lowercase before uploading. Defaults to ``False``.
Returns:
The result from :py:func:`arcrest.agol.services.FeatureLayer.addFeatures`.
Raises:
ArcRestHelperError: if ``arcpy`` can't be found.
Notes:
If publishing to a PostgreSQL database, it is suggested to to set ``lowerCaseFieldNames`` to ``True``.
"""
if arcpyFound == False:
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": inspect.currentframe().f_back.f_lineno,
"filename": 'featureservicetools',
"synerror": "ArcPy required for this function"
})
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
if chunksize > 0:
fc = os.path.basename(pathToFeatureClass)
inDesc = arcpy.Describe(pathToFeatureClass)
oidName = inDesc.oidFieldName
arr = arcpy.da.FeatureClassToNumPyArray(pathToFeatureClass, (oidName))
syncSoFar = 0
messages = {'addResults':[],'errors':[]}
total = len(arr)
errorCount = 0
if total == '0':
print ("0 features in %s" % pathToFeatureClass)
return "0 features in %s" % pathToFeatureClass
print ("%s features in layer" % (total))
arcpy.env.overwriteOutput = True
if int(total) < int(chunksize):
return fl.addFeatures(fc=pathToFeatureClass,lowerCaseFieldNames=lowerCaseFieldNames)
else:
newArr = chunklist(arr,chunksize)
exprList = ["{0} >= {1} AND {0} <= {2}".format(oidName, nArr[0][0], nArr[len(nArr)-1][0])
for nArr in newArr]
for expr in exprList:
UploadLayer = arcpy.MakeFeatureLayer_management(pathToFeatureClass, 'TEMPCOPY', expr).getOutput(0)
#print(arcpy.GetCount_management(in_rows=UploadLayer).getOutput(0) + " features in the chunk")
results = fl.addFeatures(fc=UploadLayer,lowerCaseFieldNames=lowerCaseFieldNames)
chunkCount = arcpy.GetCount_management(in_rows=UploadLayer).getOutput(0)
print(chunkCount + " features in the chunk")
if chunkCount > 0:
if results is not None and 'addResults' in results and results['addResults'] is not None:
featSucces = 0
for result in results['addResults']:
if 'success' in result:
if result['success'] == False:
if 'error' in result:
errorCount = errorCount + 1
print ("\tError info: %s" % (result))
else:
featSucces = featSucces + 1
syncSoFar = syncSoFar + featSucces
print ("%s features added in this chunk" % (featSucces))
print ("%s/%s features added, %s errors" % (syncSoFar,total,errorCount ))
if 'addResults' in messages:
messages['addResults'] = messages['addResults'] + results['addResults']
else:
messages['addResults'] = results['addResults']
else:
messages['errors'] = result
return messages
else:
return fl.addFeatures(fc=pathToFeatureClass,lowerCaseFieldNames=lowerCaseFieldNames)
except arcpy.ExecuteError:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
"arcpyError": arcpy.GetMessages(2),
}
)
except:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
#.........这里部分代码省略.........
示例5: AddFeaturesToFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import addFeatures [as 别名]
def AddFeaturesToFeatureLayer(self,url,pathToFeatureClass,chunksize=0,lowerCaseFieldNames=False):
if arcpyFound == False:
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": inspect.currentframe().f_back.f_lineno,
"filename": 'featureservicetools',
"synerror": "ArcPy required for this function"
})
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
if chunksize > 0:
messages = {'addResults':[]}
total = arcpy.GetCount_management(pathToFeatureClass).getOutput(0)
if total == '0':
print ("0 features in %s" % pathToFeatureClass)
return "0 features in %s" % pathToFeatureClass
arcpy.env.overwriteOutput = True
if int(total) < int(chunksize):
return fl.addFeatures(fc=pathToFeatureClass,lowerCaseFieldNames=lowerCaseFieldNames)
else:
inDesc = arcpy.Describe(pathToFeatureClass)
oidName = arcpy.AddFieldDelimiters(pathToFeatureClass,inDesc.oidFieldName)
sql = '%s = (select min(%s) from %s)' % (oidName,oidName,os.path.basename(pathToFeatureClass))
cur = arcpy.da.SearchCursor(pathToFeatureClass,[inDesc.oidFieldName],sql)
minOID = cur.next()[0]
del cur, sql
sql = '%s = (select max(%s) from %s)' % (oidName,oidName,os.path.basename(pathToFeatureClass))
cur = arcpy.da.SearchCursor(pathToFeatureClass,[inDesc.oidFieldName],sql)
maxOID = cur.next()[0]
del cur, sql
breaks = range(minOID,maxOID)[0:-1:chunksize]
breaks.append(maxOID+1)
exprList = [oidName + ' >= ' + str(breaks[b]) + ' and ' + \
oidName + ' < ' + str(breaks[b+1]) for b in range(len(breaks)-1)]
for expr in exprList:
UploadLayer = arcpy.MakeFeatureLayer_management(pathToFeatureClass, 'TEMPCOPY', expr).getOutput(0)
result = fl.addFeatures(fc=UploadLayer,lowerCaseFieldNames=lowerCaseFieldNames)
if messages is None:
messages = result
else:
if result is not None and 'addResults' in result:
if 'addResults' in messages:
messages['addResults'] = messages['addResults'] + result['addResults']
print ("%s/%s features added" % (len(messages['addResults']),total))
else:
messages['addResults'] = result['addResults']
print ("%s/%s features added" % (len(messages['addResults']),total))
else:
messages['errors'] = result
return messages
else:
return fl.addFeatures(fc=pathToFeatureClass,lowerCaseFieldNames=lowerCaseFieldNames)
except arcpy.ExecuteError:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
"arcpyError": arcpy.GetMessages(2),
}
)
except:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fl = None
del fl
gc.collect()
示例6: AddFeaturesToFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import addFeatures [as 别名]
def AddFeaturesToFeatureLayer(self,url,pathToFeatureClass,chunksize=0):
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
if chunksize > 0:
messages = {'addResults':[]}
total = arcpy.GetCount_management(pathToFeatureClass).getOutput(0)
arcpy.env.overwriteOutput = True
inDesc = arcpy.Describe(pathToFeatureClass)
oidName = arcpy.AddFieldDelimiters(pathToFeatureClass,inDesc.oidFieldName)
sql = '%s = (select min(%s) from %s)' % (oidName,oidName,os.path.basename(pathToFeatureClass))
cur = arcpy.da.SearchCursor(pathToFeatureClass,[inDesc.oidFieldName],sql)
minOID = cur.next()[0]
del cur, sql
sql = '%s = (select max(%s) from %s)' % (oidName,oidName,os.path.basename(pathToFeatureClass))
cur = arcpy.da.SearchCursor(pathToFeatureClass,[inDesc.oidFieldName],sql)
maxOID = cur.next()[0]
del cur, sql
breaks = range(minOID,maxOID)[0:-1:chunksize]
breaks.append(maxOID+1)
exprList = [oidName + ' >= ' + str(breaks[b]) + ' and ' + \
oidName + ' < ' + str(breaks[b+1]) for b in range(len(breaks)-1)]
for expr in exprList:
UploadLayer = arcpy.MakeFeatureLayer_management(pathToFeatureClass, 'TEMPCOPY', expr).getOutput(0)
result = fl.addFeatures(fc=UploadLayer)
if messages is None:
messages = result
else:
if 'addResults' in result:
if 'addResults' in messages:
messages['addResults'] = messages['addResults'] + result['addResults']
print "%s/%s features added" % (len(messages['addResults']),total)
else:
messages['addResults'] = result['addResults']
print "%s/%s features added" % (len(messages['addResults']),total)
else:
messages['errors'] = result
return messages
else:
return fl.addFeatures(fc=pathToFeatureClass)
except arcpy.ExecuteError:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "create_report_layers_using_config",
"line": line,
"filename": filename,
"synerror": synerror,
"arcpyError": arcpy.GetMessages(2),
}
)
except:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "AddFeaturesToFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fl = None
del fl
gc.collect()
示例7: RemoveAndAddFeatures
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import addFeatures [as 别名]
def RemoveAndAddFeatures(self, url, pathToFeatureClass, id_field, chunksize=1000):
fl = None
try:
arcpy.env.overwriteOutput = True
tempaddlayer = "ewtdwedfew"
if not arcpy.Exists(pathToFeatureClass):
raise common.ArcRestHelperError(
{
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": "featureservicetools",
"synerror": "%s does not exist" % pathToFeatureClass,
}
)
fields = arcpy.ListFields(pathToFeatureClass, wild_card=id_field)
if len(fields) == 0:
raise common.ArcRestHelperError(
{
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": "featureservicetools",
"synerror": "%s field does not exist" % id_field,
}
)
strFld = True
if fields[0].type != "String":
strFld = False
fl = FeatureLayer(url=url, securityHandler=self._securityHandler)
id_field_local = arcpy.AddFieldDelimiters(pathToFeatureClass, id_field)
idlist = []
print arcpy.GetCount_management(in_rows=pathToFeatureClass).getOutput(0) + " features in the layer"
with arcpy.da.SearchCursor(pathToFeatureClass, (id_field)) as cursor:
for row in cursor:
if strFld:
idlist.append("'" + row[0] + "'")
else:
idlist.append(row[0])
if len(idlist) >= chunksize:
idstring = " in (" + ",".join(idlist) + ")"
sql = id_field + idstring
sqlLocalFC = id_field_local + idstring
results = fl.deleteFeatures(where=sql, rollbackOnFailure=True)
if "error" in results:
raise common.ArcRestHelperError(
{
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": "featureservicetools",
"synerror": results["error"],
}
)
elif "deleteResults" in results:
print "%s features deleted" % len(results["deleteResults"])
for itm in results["deleteResults"]:
if itm["success"] != True:
print itm
else:
print results
arcpy.MakeFeatureLayer_management(pathToFeatureClass, tempaddlayer, sqlLocalFC)
results = fl.addFeatures(fc=tempaddlayer)
if "error" in results:
raise common.ArcRestHelperError(
{
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": "featureservicetools",
"synerror": results["error"],
}
)
elif "addResults" in results:
print "%s features added" % len(results["addResults"])
for itm in results["addResults"]:
if itm["success"] != True:
print itm
else:
print results
idlist = []
if "error" in results:
raise common.ArcRestHelperError(
{
"function": "RemoveAndAddFeatures",
"line": inspect.currentframe().f_back.f_lineno,
"filename": "featureservicetools",
"synerror": results["error"],
}
)
else:
print results
except arcpy.ExecuteError:
line, filename, synerror = trace()
raise common.ArcRestHelperError(
#.........这里部分代码省略.........