|
POST
|
I want to find all items in my organization that have not been accessed or opened in say the last 6 months and delete them. I have some code here which gets the item ids, but it appears as if only the first item id is being passed and returning a data frame. Jake Skinner how can I grab every item id in my list and pass it to the usage method and if that item has no activity then delete it? Here is the beginning of my code: from arcgis.gis import GIS, Item
gis = GIS("", "", "")
my_content = gis.content.search(query="owner:" + gis.users.me.username,
max_items=15)
for content in my_content:
item_id = content.id
item = Item(gis, item_id)
itemid = item.id
chardata = item.usage("24H",as_df=True)
print (chardata)
... View more
01-23-2020
06:29 PM
|
0
|
2
|
1277
|
|
POST
|
When a map image layer is created in Portal, what is the underlying component that references the image layer to a service endpoint? For instance, should I be able to see the Item ID in a stack trace for a rest endpoint? Is there a way to view analytics on a map image layer? My organization has duplicated image layers, but we do not consume the image layers into web maps, we use the service URLs, however if we delete the wrong image layer, the service will delete completely also. This is a federated 10.6.1 Portal environment.
... View more
09-09-2019
08:37 AM
|
0
|
0
|
398
|
|
POST
|
Hi Ethan, Here is the refactored code. It looks like the script gets the map properties. Hope it helps. import os
import logging
import logging.handlers
import time
import configparser
import SendEmail
from arcgis.gis import GIS
import arcpy
import sys
def getMapProperties(mapPropsList):
mapProperties = {}
for i in range(0, len(mapPropsList)):
props = mapPropsList[i].split(",")
mapname = props[0]
mapnameupper = mapname.upper()
mapProperties[mapnameupper]={}
mapProperties[mapnameupper]['mapname'] = props[0]
if len(props) > 1:
mapProperties[mapnameupper]['minscale'] = props[1]
else:
mapProperties[mapnameupper]['minscale'] =""
if len(props) > 2:
mapProperties[mapnameupper]['maxscale'] = props[2]
else:
mapProperties[mapnameupper]['maxscale'] =""
if len(props) > 3:
mapProperties[mapnameupper]['vtpkindex'] = props[3]
else:
mapProperties[mapnameupper]['vtpkindex'] = ""
return mapProperties
def createVtpk(m, mapProperties, indexGDBPath, vtpkPath, logger):
mapName = m.name
minscale = ""
maxscale =""
vtpkindexfile = ""
mapNameUpper = mapName.upper()
if mapNameUpper in mapProperties:
minscale = mapProperties[mapNameUpper]['minscale']
if minscale !="":
minscale = float(minscale)
maxscale = mapProperties[mapNameUpper]['maxscale']
if maxscale !="":
maxscale = float(maxscale)
vtpkindex = mapProperties[mapNameUpper]['vtpkindex']
if vtpkindex != "":
vtpkindexfile = os.path.join(indexGDBPath, vtpkindex)
logger.info("Creating Vector Tiles for " + mapName)
arcpy.management.CreateVectorTilePackage(m, vtpkPath, "ONLINE", "", "INDEXED", minscale, maxscale, vtpkindexfile)
return vtpkPath
return ""
def uploadVtpk(gis, vtpkName, vtpk, logger):
vtpkFile = gis.content.search(query="title:"+vtpkName, item_type="Vector Tile Package")
for i in range(0, len(vtpkFile)):
item = vtpkFile[i]
if item.title.upper() == vtpkName.upper():
logger.info("Deleting Old VTPK Package From Portal")
item.delete()
break
logger.info("Uploading VTPK package")
vtpk_item = gis.content.add({}, data=vtpk)
if vtpk_item == None:
logger.error("Error adding " + vtpk + " to Portal")
return vtpk_item
def publishVtpk(gis, vtpkName, vtpk_item, portalGroups, logger):
vtpkLayer = gis.content.search(query=vtpkName, item_type="Vector Tile Service")
for i in range(0, len(vtpkLayer)):
vLayer = vtpkLayer[i]
if vLayer.title.upper() == vtpkName.upper():
logger.info("Deleting Old VTPK Service From Portal")
vLayer.delete()
break
logger.info("Publishing VTPK service")
vtpk_service = vtpk_item.publish()
vtpk_item.delete()
logger.info("Sharing to Group in Portal")
for group in portalGroups:
cp_group = gis.groups.search('title:' + group, max_groups=15)
for i in range(0, len(cp_group)):
cpgroup_share = cp_group[i]
if cpgroup_share.title.upper() == group.upper():
vtpk_service.share(groups=cpgroup_share.id)
break;
return vtpk_service
def SendErrorNotification(emailTo, emailFrom, msg):
for email in emailTo.split(";"):
SendEmail.email_error_msg(emailTo, emailFrom, msg)
def main():
if len(sys.argv) == 1:
print("Please provide parameter for config file")
sys.exit()
if not os.path.isfile(sys.argv[1]):
print("Config file does not exist")
sys.exit()
cfile = configparser.ConfigParser()
cfile.read(sys.argv[1])
portalUrl = cfile.get('Portal', 'PortalUrl')
portalGroupsList = cfile.get('Portal', 'PortalGroup')
portalGroups = portalGroupsList.split(";")
workspace = cfile.get('Folder', 'Workspace')
outputPath = cfile.get('Folder', 'OutputFolder')
logFile = cfile.get('Folder', 'LogFile')
emailTo = cfile.get('Notification', 'EmailTo')
emailFrom = cfile.get('Notification', 'EmailFrom')
vtpkIndexFolder = cfile.get('VTPK', 'VtpkIndexFolder')
project = cfile.get('VTPK', 'ProProject')
mapProps = cfile.get('VTPK','MapProperties')
mapProperties = getMapProperties(mapProps.split(';'))
logger = logging.getLogger('vectortiles_oca')
logger.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(message)s')
handler = logging.handlers.RotatingFileHandler(logFile, maxBytes=100000, backupCount=5)
handler.setFormatter(formatter)
logger.addHandler(handler)
gis = GIS(portalUrl, verify_cert=False)
arcpy.env.workspace = workspace
arcpy.env.overwriteOutput = True
arcpy.env.parallelProcessingFactor = "66%"
logger.info("XXXXXXXXXXXXXXXXXXXXXXXX=Start")
p = arcpy.mp.ArcGISProject(project)
maps = p.listMaps("*")
for i in range(0, len(maps)):
try:
if maps[i].name.upper() in mapProperties:
vtpk = os.path.join(outputPath, maps[i].name + '.vtpk')
if os.path.exists(vtpk):
backupPath = os.path.join(outputPath, "backup")
newname = os.path.join(backupPath, maps[i].name + '_'+ datetime.datetime.today().strftime('%Y%m%d%H%M') + '.vtpk')
logger.info("Renaming existing VTPK to " + newname)
os.rename(vtpk, newname)
tryagain = True
count = 0
while tryagain:
count = count + 1
if count == 5:
break
try:
vtpkPath = createVtpk(maps[i], mapProperties, vtpkIndexFolder, vtpk, logger)
vtpk_item = uploadVtpk(gis, maps[i].name, vtpk, logger)
publishVtpk(gis, maps[i].name, vtpk_item, portalGroups,logger)
tryagain = False
except Exception as e:
logger.error(e, exc_info=True)
if count ==3:
SendErrorNotification(emailTo, emailFrom, "Encountered an error - " + maps[i].name + ". trying again." + str(e))
except Exception as e:
logger.error(e, exc_info=True)
SendErrorNotification(emailTo, emailFrom, "Vector Tiles Script has failed for map " + maps[i].name + ": " + str(e))
del gis
logger.info("XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=Complete")
if __name__ == '__main__':
main()
... View more
06-04-2019
03:46 PM
|
1
|
4
|
2556
|
|
POST
|
Hi Ethan, I don't remember what my solution was with this, a colleague has since taken over the project. I will take a look at her code and get back to you.
... View more
06-04-2019
07:54 AM
|
0
|
6
|
2556
|
|
POST
|
Do we need to launch n+1 EC2 instances with ArcGIS Enterprise Installed, with different license keys? In the example below are the machines configured as standalone EC2 instances with unique keys for ArcGIS Server and added to the ELB? Lastly, can we run CloudFormation for a previously configured EC2 ArcGIS Server and add the new instances. Right now our set up is a single machine ArcGIS Server Enterprise Advanced on EC2. The end goal is to autoscale this instance based on CloudWatch and have this instance and any other under the ELB.
... View more
10-31-2018
08:26 AM
|
0
|
0
|
978
|
|
POST
|
I have been receiving this error when accessing my organization's portal It is intermittent, what could be the cause of it. Typically I am seeing this error occur at line 53. The VTPK is not able to be added to my Portal. The error is not consistent as it appears sometimes, and other times it does not. from arcgis.gis import GIS
import os
import arcpy
import logging
# set environment settings
gis = GIS("myDetails")
arcpy.env.workspace = r"E:\GIS_PROJECTS\VTPK"
arcpy.env.overwriteOutput = True
start = time.time()
outputPath = r"E:\GIS_PROJECTS\VTPK\\"
tileScheme = "ONLINE"
indexScheme = "INDEXED"
vtpkTitle = "title:CPAreasVector"
mapTitle = "CPAreasVector"
vtPackage = "Vector Tile Package"
mapQuery = "CPAreasVector*"
vts = "Vector Tile Service"
indexShp = r'E:\GIS_PROJECTS\VTPK\INDEX\CPAreas\CPAreas.shp'
project = r"E:\GIS_PROJECTS\VTPK\CPVektrTile.aprx"
arcpy.env.parallelProcessingFactor = "66%"
logging.basicConfig(filename=r"E:\GIS_PROJECTS\VTPK\log.log", level=logging.INFO,
format='%(asctime)s %(message)s')
try:
# Query Project for CPAreasVector Map
p = arcpy.mp.ArcGISProject(project)
lyt = p.listMaps(mapQuery)[0]
logging.info("Creating Vector Tiles for " + lyt.name)
# arcpy.management.CreateVectorTilePackage(lyt, outputPath + lyt.name + '.vtpk', tileScheme, "", indexScheme, "", "",
# indexShp)
logging.info("Vector Tile Creation Complete for " + lyt.name)
# Find VTPK File that has been uploaded
vtpkFile = gis.content.search(query=vtpkTitle, item_type=vtPackage)
logging.info(len(vtpkFile))
if len(vtpkFile) > 0:
first_item = vtpkFile[0]
logging.info(first_item)
if first_item.title == mapTitle:
known_item_id = first_item.id
logging.info(known_item_id)
vtpkFileDelete = gis.content.get(known_item_id)
logging.info("Deleting Old VTPK Layer From Test Portal")
vtpkFileDelete.delete()
else:
logging.info("There is no VTPK File Found")
# Add VTPK to Portal
logging.info("Adding VTPK to Test Portal")
vtpk_item = gis.content.add({}, data=outputPath + lyt.name + '.vtpk', folder='packages')
# Delete old Service
vtpkLayer = gis.content.search(query="CPAreasVector", item_type="Vector Tile Service")
logging.info("Number of service items")
logging.info(len(vtpkFile))
if len(vtpkLayer) > 0:
vLayerID = vtpkLayer[0]
if vLayerID.title == mapTitle:
vLayer_item_id = vLayerID.id
logging.info(vLayer_item_id)
vtpkLayerDelete = gis.content.get(vLayer_item_id)
logging.info("Deleting Old VTPK Service From Test Portal")
vtpkLayerDelete.delete()
else:
logging.info("There is no VTPK Layer Found")
# Publish VTPK
logging.info("Publishing & Overwriting VTPK to Test Portal")
vtpk_hLayer = vtpk_item.publish()
# Share to Group
logging.info("Sharing to CP Group in Test Portal")
cp_group = gis.groups.search('title:SCG - Cathodic Protection', max_groups=15)
cpgroup_share = cp_group[0]
vtpk_hLayer.share(groups=cpgroup_share.id)
logging.info("Complete")
except Exception as e :
logging.info(e)
... View more
03-05-2018
02:58 PM
|
1
|
1
|
1389
|
|
POST
|
I have a script which creates a vector tile package. I am receiving the error: ERROR 001856: Cached scale doesn't match tiling scheme only when I run the tool from a standalone Python script. I use the same parameters in the GUI of ArcGIS Pro and the tool works fine. Is this an ArcPy bug? If I don't use a min and max scaling the tool runs successfully but takes forever due to the size of the dataset. Here is my script: from arcgis.gis import GIS
import os
import arcpy
#set environment settings
gis = GIS("myportal")
arcpy.env.overwriteOutput = True
outputPath = r"\\myOutPath\"
arcpy.env.parallelProcessingFactor = "66%"
# Loop through the project, find all the maps, and
# create a vector tile package for each map,
# using the same name as the map
p = arcpy.mp.ArcGISProject(r"\\CPVektrTile.aprx")
for m in p.listMaps():
print("Indexing " + m.name)
arcpy.CreateVectorTileIndex_management(m, outputPath + m.name + '.shp', "ONLINE", "", 10000)
print("Packaging " + m.name)
arcpy.management.CreateVectorTilePackage(m, outputPath + m.name + '.vtpk', "ONLINE", "", "INDEXED", 100000, 3000, r"\\CPAreas.shp")
print ("Adding VTPK to Test Portal")
vtpk_item = gis.content.add({}, data=outputPath + m.name + '.vtpk', folder='packages', overwrite=True)
print ("Publishing & Overwriting VTPK to Test Portal")
vtpk_layer = vtpk_item.publish(overwrite=True)
vtpk_layer.share(groups="SCG - Cathodic Protection")
Screenshot of successful run from geoprocessing tool in ArcGIS Pro: Code sent to Python Window from history: arcpy.management.CreateVectorTilePackage("CPAreas", r"C:\db\vtpktest_2.vtpk", "ONLINE", None, "INDEXED", 100000, 3000, r"\\\CPAreas.shp", None, None)
... View more
02-20-2018
03:43 PM
|
1
|
8
|
3277
|
|
POST
|
I want to write a script where I can find and delete all level 1 users that have not been active in 90 days in Portal. What is the method in the ArcGIS API for Python to find license level of users?
... View more
02-20-2018
10:14 AM
|
0
|
1
|
1092
|
|
POST
|
My input is an external JSON from the Weather Company that has weather data per zip code, I would like update a feature service that has point data with this weather data, so for a zip code that is polled in the external JSON, I would like to give my features the associated weather data in wind speed and wind direction. How should this process be constructed? My input receives features fine, as a JSON object, how do I create a 1-1 relationship between JSON key:values and attributes of my feature service, in this case, the zip code of the JSON to the JSON of the feature service?
... View more
05-12-2017
09:43 AM
|
0
|
0
|
610
|
|
POST
|
I would like to configure a simple Geoevent processor where an email is sent if an inbound polygon intersects with a line feature input or polygon feature input. I have published my inbound polygons as a feature service and am testing in Portal by adding features to a web map to intersect, but the geoevent monitor is not receiving anything. How should this be configured to send an email each time a polygon intersects with a line feature or polygon feature? This example below shows the intersector(which will be changed, if a ticket intersects with HP Pipe, send email. How should the processor and input and output be configured?
... View more
04-19-2017
12:26 PM
|
0
|
0
|
700
|
|
POST
|
My use case is per point in a zip code on a given date and 15 minute interval of a 24 hour time frame. I would like to use a weather API to feed into geoevent and where a feature is intersects the zip code boundary and meets other parameters such as date and time, this would call the weather service and return the given weather data. Can Geoevent extension be used to return historical data?
... View more
03-16-2017
02:33 PM
|
1
|
0
|
1020
|
|
POST
|
"actiondttime" is a string in oracle, the value time above was used in the SQL expression to note to convert a SQL table field from string to time.
... View more
01-20-2017
04:33 PM
|
0
|
0
|
2356
|
|
POST
|
CONVERT in the above statements converts from a string to TIME field from the SQL table.
... View more
01-20-2017
04:13 PM
|
0
|
1
|
2356
|
|
POST
|
Hi Christian, When I print ticket_sql here is what is returned. Is the CONVERT function incorrect for Oracle? When I run this statement with the SQL Server table, it is correct. select jobid from SEU_GIS_GAS.actionaudit where actiondtdate >= '2017-01-17' and CONVERT(time,actiondttime) > '14:28:55' and jobid NOT LIKE '%ZZ%'
... View more
01-20-2017
04:01 PM
|
0
|
3
|
2356
|
|
POST
|
I have a Python script that has thrown this error. The script has remained functional and working properly until I have changed the paths of the data that is being read in it. Initially the application read 3 different tables which were all in a SQL Server DB. I made a very small subset of each table(3 records) and exported these tables to an Oracle DB, when I am reading the data from the Oracle environment this error is thrown. Here is where I make my ArcSDESQLExecute connection. What is the solution for this? ticket_sql = "select {0} from {1} where {2} >= '{3}' and CONVERT(time, {4}) > '{5}' and jobid NOT LIKE '%ZZ%' ".format(self.ticket_id_field, self.ticket_audit_table_name, self.modified_date_field, last_date, self.modified_time_field, last_time) self.logger.debug(ticket_sql) conn = arcpy.ArcSDESQLExecute(self.korterra_sde_path) results = conn.execute(ticket_sql)
... View more
01-20-2017
02:55 PM
|
0
|
7
|
4232
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-16-2017 02:33 PM | |
| 1 | 01-18-2022 07:40 AM | |
| 1 | 04-28-2021 09:29 AM | |
| 1 | 10-24-2016 12:07 PM | |
| 1 | 04-28-2016 09:12 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-18-2022
03:08 PM
|