本文整理汇总了Python中arcrest.agol.FeatureLayer.deleteFeatures方法的典型用法代码示例。如果您正苦于以下问题:Python FeatureLayer.deleteFeatures方法的具体用法?Python FeatureLayer.deleteFeatures怎么用?Python FeatureLayer.deleteFeatures使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arcrest.agol.FeatureLayer
的用法示例。
在下文中一共展示了FeatureLayer.deleteFeatures方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: DeleteFeaturesFromFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import deleteFeatures [as 别名]
def DeleteFeaturesFromFeatureLayer(self,url,sql):
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler,)
return fl.deleteFeatures(where=sql)
except arcpy.ExecuteError:
line, filename, synerror = Common.trace()
raise ArcRestHelperError({
"function": "DeleteFeaturesFromFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
"arcpyError": arcpy.GetMessages(2),
}
)
except:
line, filename, synerror = Common.trace()
raise ArcRestHelperError({
"function": "DeleteFeaturesFromFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fl = None
del fl
gc.collect()
示例2: DeleteFeaturesFromFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import deleteFeatures [as 别名]
def DeleteFeaturesFromFeatureLayer(self,url,sql):
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
return fl.deleteFeatures(where=sql)
except:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "DeleteFeaturesFromFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fl = None
del fl
gc.collect()
示例3: RemoveAndAddFeatures
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import deleteFeatures [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,
#.........这里部分代码省略.........
示例4: DeleteFeaturesFromFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import deleteFeatures [as 别名]
def DeleteFeaturesFromFeatureLayer(self,url,sql,chunksize=0):
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
totalDeleted = 0
if chunksize > 0:
qRes = fl.query(where=sql, returnIDsOnly=True)
if 'error' in qRes:
print (qRes)
return qRes
elif 'objectIds' in qRes:
oids = qRes['objectIds']
total = len(oids)
if total == 0:
return {'success':True,'message': "No features matched the query"}
i = 0
print ("%s features to be deleted" % total)
while(i <= len(oids)):
oidsDelete = ','.join(str(e) for e in oids[i:i+chunksize])
if oidsDelete == '':
continue
else:
results = fl.deleteFeatures(objectIds=oidsDelete)
if 'deleteResults' in results:
totalDeleted += len(results['deleteResults'])
print ("%s%% Completed: %s/%s " % (int(totalDeleted / float(total) *100), totalDeleted, total))
i += chunksize
else:
print (results)
return {'success':True,'message': "%s deleted" % totalDeleted}
qRes = fl.query(where=sql, returnIDsOnly=True)
if 'objectIds' in qRes:
oids = qRes['objectIds']
if len(oids)> 0 :
print ("%s features to be deleted" % len(oids))
results = fl.deleteFeatures(where=sql)
if 'deleteResults' in results:
totalDeleted += len(results['deleteResults'])
return {'success':True,'message': "%s deleted" % totalDeleted}
else:
return results
return {'success':True,'message': "%s deleted" % totalDeleted}
else:
print (qRes)
else:
results = fl.deleteFeatures(where=sql)
if results is not None:
if 'deleteResults' in results:
return {'success':True,'message': totalDeleted + len(results['deleteResults'])}
else:
return results
except:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "DeleteFeaturesFromFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fl = None
del fl
gc.collect()
示例5: DeleteFeaturesFromFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import deleteFeatures [as 别名]
def DeleteFeaturesFromFeatureLayer(self, url, sql, chunksize=0):
"""Removes features from a hosted feature service layer by SQL query.
Args:
url (str): The URL of the feature service layer.
sql (str): The SQL query to apply against the feature service.
Those features that satisfy the query will be deleted.
chunksize (int): The maximum amount of features to remove at a time. Defaults to 0.
Returns:
The result from :py:func:`arcrest.agol.services.FeatureLayer.deleteFeatures`.
Notes:
If you want to delete all features, it is suggested to use the SQL query ``"1=1"``.
"""
fl = None
try:
fl = FeatureLayer(
url=url,
securityHandler=self._securityHandler)
totalDeleted = 0
if chunksize > 0:
qRes = fl.query(where=sql, returnIDsOnly=True)
if 'error' in qRes:
print (qRes)
return qRes
elif 'objectIds' in qRes:
oids = qRes['objectIds']
total = len(oids)
if total == 0:
return {'success':True,'message': "No features matched the query"}
i = 0
print ("%s features to be deleted" % total)
while(i <= len(oids)):
oidsDelete = ','.join(str(e) for e in oids[i:i+chunksize])
if oidsDelete == '':
continue
else:
results = fl.deleteFeatures(objectIds=oidsDelete)
if 'deleteResults' in results:
totalDeleted += len(results['deleteResults'])
print ("%s%% Completed: %s/%s " % (int(totalDeleted / float(total) *100), totalDeleted, total))
i += chunksize
else:
print (results)
return {'success':True,'message': "%s deleted" % totalDeleted}
qRes = fl.query(where=sql, returnIDsOnly=True)
if 'objectIds' in qRes:
oids = qRes['objectIds']
if len(oids)> 0 :
print ("%s features to be deleted" % len(oids))
results = fl.deleteFeatures(where=sql)
if 'deleteResults' in results:
totalDeleted += len(results['deleteResults'])
return {'success':True,'message': "%s deleted" % totalDeleted}
else:
return results
return {'success':True,'message': "%s deleted" % totalDeleted}
else:
print (qRes)
else:
results = fl.deleteFeatures(where=sql)
if results is not None:
if 'deleteResults' in results:
return {'success':True,'message': totalDeleted + len(results['deleteResults'])}
else:
return results
except:
line, filename, synerror = trace()
raise common.ArcRestHelperError({
"function": "DeleteFeaturesFromFeatureLayer",
"line": line,
"filename": filename,
"synerror": synerror,
}
)
finally:
fl = None
del fl
gc.collect()
示例6: main
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import deleteFeatures [as 别名]
def main():
try:
proxy_port = None
proxy_url = None
securityinfo = {}
securityinfo['security_type'] = 'Portal'#LDAP, NTLM, OAuth, Portal, PKI
securityinfo['username'] = ""#<UserName>
securityinfo['password'] = ""#<Password>
securityinfo['org_url'] = "http://www.arcgis.com"
securityinfo['proxy_url'] = proxy_url
securityinfo['proxy_port'] = proxy_port
securityinfo['referer_url'] = None
securityinfo['token_url'] = None
securityinfo['certificatefile'] = None
securityinfo['keyfile'] = None
securityinfo['client_id'] = None
securityinfo['secret_id'] = None
workforceProjectID = '' #Workforce project number
assignmentAreasID = '' #ID of service to get centroids from
assignmentAreaLayerName = ''#layer in servuce
assignmentAreaNameField = ''#field with name of id area
csvPath = r".\dataToLookup.csv"#<Path with data>
workerCol = 'worker'
areaCol = 'area'
descriptionCol = "description"
notesCol = "notes"
supervisorCol = "supervisor"
assignmentType = 2
status = 1
workerNameToID = {}
dispatcherNameToID = {}
areaNameToID = {}
fst = featureservicetools.featureservicetools(securityinfo)
if fst.valid == False:
print (fst.message)
else:
portalAdmin = arcrest.manageorg.Administration(securityHandler=fst.securityhandler)
#Get the assignment areas
fs = fst.GetFeatureService(itemId=assignmentAreasID,returnURLOnly=False)
if not fs is None:
fs_url = fst.GetLayerFromFeatureService(fs=fs,layerName=assignmentAreaLayerName,returnURLOnly=True)
if not fs_url is None:
fl = FeatureLayer(
url=fs_url,
securityHandler=fst.securityhandler,
proxy_port=proxy_port,
proxy_url=proxy_url,
initialize=True)
areaResults = fl.query(**{'where':"1=1",'outSR':'102100','out_fields':assignmentAreaNameField,'returnGeometry':False,'returnCentroid':True})
for area in areaResults:
arDict = area.asDictionary
areaNameToID[arDict['attributes'][assignmentAreaNameField]] = arDict['centroid']
#Get the workers
item = portalAdmin.content.getItem(itemId=workforceProjectID)
itemData = item.itemData()
if 'workers' in itemData:
fl = FeatureLayer(
url=itemData['workers']['url'],
securityHandler=fst.securityhandler,
proxy_port=proxy_port,
proxy_url=proxy_url,
initialize=True)
workersResults = fl.query(where="1=1",out_fields='OBJECTID, NAME',returnGeometry=False)
for worker in workersResults:
workerNameToID[worker.get_value('name')] = worker.get_value('OBJECTID')
if 'dispatchers' in itemData:
fl = FeatureLayer(
url=itemData['dispatchers']['url'],
securityHandler=fst.securityhandler,
proxy_port=proxy_port,
proxy_url=proxy_url,
initialize=True)
dispatcherResults = fl.query(where="1=1",out_fields='OBJECTID, NAME',returnGeometry=False)
for dispatcher in dispatcherResults:
dispatcherNameToID[dispatcher.get_value('name')] = dispatcher.get_value('OBJECTID')
if 'assignments' in itemData:
features = []
fl = FeatureLayer(
url=itemData['assignments']['url'],
securityHandler=fst.securityhandler,
proxy_port=proxy_port,
proxy_url=proxy_url,
initialize=True)
print(fl.deleteFeatures(where="1=1"))
#.........这里部分代码省略.........
示例7: DeleteFeaturesFromFeatureLayer
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import deleteFeatures [as 别名]
def DeleteFeaturesFromFeatureLayer(self, url, sql, chunksize=0):
fl = None
try:
fl = FeatureLayer(url=url, securityHandler=self._securityHandler)
totalDeleted = 0
if chunksize > 0:
qRes = fl.query(where=sql, returnIDsOnly=True)
if "error" in qRes:
print qRes
return qRes
elif "objectIds" in qRes:
oids = qRes["objectIds"]
total = len(oids)
if total == 0:
return {"success": "true", "message": "No features matched the query"}
minId = min(oids)
maxId = max(oids)
i = 0
print "%s features to be deleted" % total
while i <= len(oids):
oidsDelete = ",".join(str(e) for e in oids[i : i + chunksize])
if oidsDelete == "":
continue
else:
results = fl.deleteFeatures(objectIds=oidsDelete)
if "deleteResults" in results:
totalDeleted += len(results["deleteResults"])
print "%s%% Completed: %s/%s " % (
int(totalDeleted / float(total) * 100),
totalDeleted,
total,
)
i += chunksize
else:
print results
return {"success": "true", "message": "%s deleted" % totalDeleted}
qRes = fl.query(where=sql, returnIDsOnly=True)
if "objectIds" in qRes:
oids = qRes["objectIds"]
if len(oids) > 0:
print "%s features to be deleted" % len(oids)
results = fl.deleteFeatures(where=sql)
if "deleteResults" in results:
totalDeleted += len(results["deleteResults"])
return {"success": "true", "message": "%s deleted" % totalDeleted}
else:
return results
return {"success": "true", "message": "%s deleted" % totalDeleted}
else:
print qRes
else:
results = fl.deleteFeatures(where=sql)
if "deleteResults" in results:
return {"success": "true", "message": totalDeleted + len(results["deleteResults"])}
else:
return results
except:
line, filename, synerror = trace()
raise common.ArcRestHelperError(
{"function": "DeleteFeaturesFromFeatureLayer", "line": line, "filename": filename, "synerror": synerror}
)
finally:
fl = None
del fl
gc.collect()
示例8: RemoveAndAddFeatures
# 需要导入模块: from arcrest.agol import FeatureLayer [as 别名]
# 或者: from arcrest.agol.FeatureLayer import deleteFeatures [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(
#.........这里部分代码省略.........