POST
|
I’m trying to build a Python Toolbox which uses a Field Mappings control (GPFieldMapping parameter). For some reason I don’t manage to get the same behaviour of the Field Mappings control as in the standard geoprocessing tools: Append, Merge …. On my tool, the context menu doesn’t show the Add Input Field command as it does in the Append tool (see print screen below). Any clues of why this might happen? Please find below my code: import arcpy
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [TestFieldMappings]
class TestFieldMappings(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Test Field Mappings"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
prm_base_feature = arcpy.Parameter(displayName = 'Base Feature Class',
name = 'BaseFeatureClass',
datatype = 'DETable',
parameterType = 'Required',
direction = 'Input')
prm_test_feature = arcpy.Parameter(displayName = 'Test Feature Class',
name = 'TestFeatureClass',
datatype = 'DETable',
parameterType = 'Required',
direction = 'Input')
prm_field_mappings = arcpy.Parameter(displayName = 'Field Mappings',
name = 'FieldMappings',
datatype = 'GPFieldMapping',
parameterType = 'Optional',
direction = 'Input')
params = [prm_base_feature,
prm_test_feature,
prm_field_mappings]
# return parameters array
return params
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
if parameters[0].altered and parameters[1].altered:
if not (parameters[0].hasBeenValidated and parameters[1].hasBeenValidated):
tmp_fms = arcpy.FieldMappings() # Create empty FieldMappings object
base_fields = [f for f in arcpy.ListFields(parameters[0].valueAsText) \
if f.type not in ['Geometry', 'Raster']]
test_fields = [f for f in arcpy.ListFields(parameters[1].valueAsText)
if f.type not in ['Geometry', 'Raster']]
# loop base fields
for f in base_fields:
tmp_fm = arcpy.FieldMap()
tmp_fm.outputField = f
# loop test fields
for g in test_fields:
# if name matches, add the input field
if f.name == g.name:
tmp_fm.addInputField(parameters[1].valueAsText, g.name)
# add the field map
tmp_fms.addFieldMap(tmp_fm)
parameters[2].value = tmp_fms.exportToString()
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
return Notes: I managed to make the Add Input Field show on my tool by using the initializing script of the Field Mappings in the getParameterInfo routine. This is of no use as I want the Field Mappings to be updated each time the input is changed
... View more
09-17-2019
07:54 AM
|
0
|
0
|
336
|
POST
|
Hi Jonathan. Please find below my results. The first thing I did was to run my script on my machine (locally using a web map as JSON string prepared beforehand) with good results (1min 7sec). Then I ran the same test like last time (using the web map): two consecutive runs with similar results as my previous tests (54 mins for first run and 54 secs for second run). Local run----------------------------------------------------------------------- Start Time: Fri Mar 02 09:25:08 2018 Running script PARprintPP... Time: 09:25:09.182000; Duration from last: 0:00:00; Info: My first line of code... Time: 09:25:09.182000; Duration from last: 0:00:00; Info: GetParameterAsText... Time: 09:25:09.182000; Duration from last: 0:00:00; Info: ConvertWebMapToMapDocument... Time: 09:25:55.732000; Duration from last: 0:00:46.535000; Info: ListDataFrames... Time: 09:25:55.732000; Duration from last: 0:00:00; Info: ListDataFrames... Time: 09:25:55.732000; Duration from last: 0:00:00; Info: ListLayers to collect info... Time: 09:25:55.794000; Duration from last: 0:00:00.062000; Info: MoveLayer... Time: 09:25:55.982000; Duration from last: 0:00:00.188000; Info: ListLayoutElements... Time: 09:25:55.997000; Duration from last: 0:00:00.015000; Info: ListLayers to apply changes... Time: 09:25:56.075000; Duration from last: 0:00:00.078000; Info: listLegendItemLayers... Time: 09:25:57.339000; Duration from last: 0:00:01.264000; Info: ListLayoutElements... Time: 09:25:57.386000; Duration from last: 0:00:00.047000; Info: ExportToPNG... Time: 09:26:15.762000; Duration from last: 0:00:18.376000; Info: Clean up... Time: 09:26:15.762000; Duration from last: 0:00:00; Info: Last line of code... Completed script PARprintPP... Succeeded at Fri Mar 02 09:26:16 2018 (Elapsed Time: 1 minutes 7 seconds) First Web run----------------------------------------------------------------------- Start Time: Fri Mar 02 11:10:10 2018 Running script PARprintPP... Time: 11:10:10.934000; Duration from last: 0:00:00.002000; Info: My first line of code... Time: 11:10:10.937000; Duration from last: 0:00:00; Info: GetParameterAsText... Time: 11:10:10.941000; Duration from last: 0:00:00.001000; Info: ConvertWebMapToMapDocument... Time: 12:03:03.146000; Duration from last: 0:52:52.205000; Info: ListDataFrames... Time: 12:03:03.152000; Duration from last: 0:00:00; Info: ListDataFrames... Time: 12:03:03.174000; Duration from last: 0:00:00.019000; Info: ListLayers to collect info... Time: 12:03:03.354000; Duration from last: 0:00:00.176000; Info: MoveLayer... Time: 12:03:05.770000; Duration from last: 0:00:02.412000; Info: ListLayoutElements... Time: 12:03:06.215000; Duration from last: 0:00:00.441000; Info: ListLayers to apply changes... Time: 12:03:06.599000; Duration from last: 0:00:00.379000; Info: listLegendItemLayers... Time: 12:03:10.864000; Duration from last: 0:00:04.260000; Info: ListLayoutElements... Time: 12:03:10.916000; Duration from last: 0:00:00.047000; Info: ExportToPNG... Time: 12:04:33.508000; Duration from last: 0:01:22.590000; Info: Clean up... Time: 12:04:33.525000; Duration from last: 0:00:00.012000; Info: Last line of code... Completed script PARprintPP... Succeeded at Fri Mar 02 12:04:39 2018 (Elapsed Time: 54 minutes 29 seconds) Second Web run----------------------------------------------------------------------- Start Time: Fri Mar 02 12:54:46 2018" Running script PARprintPP..." Time: 12:54:47.011000; Duration from last: 0:00:00.001000; Info: My first line of code..." Time: 12:54:47.014000; Duration from last: 0:00:00; Info: GetParameterAsText..." Time: 12:54:47.018000; Duration from last: 0:00:00.001000; Info: ConvertWebMapToMapDocument..." Time: 12:55:23.646000; Duration from last: 0:00:36.627000; Info: ListDataFrames..." Time: 12:55:23.652000; Duration from last: 0:00:00; Info: ListDataFrames..." Time: 12:55:23.673000; Duration from last: 0:00:00.018000; Info: ListLayers to collect info..." Time: 12:55:23.852000; Duration from last: 0:00:00.175000; Info: MoveLayer..." Time: 12:55:26.108000; Duration from last: 0:00:02.253000; Info: ListLayoutElements..." Time: 12:55:26.536000; Duration from last: 0:00:00.424000; Info: ListLayers to apply changes..." Time: 12:55:26.846000; Duration from last: 0:00:00.307000; Info: listLegendItemLayers..." Time: 12:55:30.950000; Duration from last: 0:00:04.100000; Info: ListLayoutElements..." Time: 12:55:30.994000; Duration from last: 0:00:00.040000; Info: ExportToPNG..." Time: 12:55:38.124000; Duration from last: 0:00:07.127000; Info: Clean up..." Time: 12:55:38.145000; Duration from last: 0:00:00.017000; Info: Last line of code..." Completed script PARprintPP..." Succeeded at Fri Mar 02 12:55:41 2018 (Elapsed Time: 54.63 seconds)" Below is a diagram of how our ESRI infrastructure is configured. GIS011 is configured to run geoprocessing services. This is where my geoprocessing service is hosted but the print tool will call map services hosted on all servers (GIS014, GIS010, GIS011). The Web Map App is hosted on GIS012. I also looked into this thread. Find below my configs on GIS012: Advanced settings on ArcGISWebAdaptorAppPool: All others: Remark: A restart on all the above servers will not trigger a slow run of my geoprocessing service.
... View more
03-02-2018
05:53 AM
|
0
|
0
|
911
|
POST
|
Hi Jonathan, The logs are below. Info section describes the arcpy function called by my script. The required time by each function is printed in the next logged line. It looks like every function called by my script is slower in the first run, especially ConvertWebMapToMapDocument (24 mins compared to 22 seconds) Start Time: Tue Feb 20 10:46:09 2018 Running script PARprintPP... Time: 10:46:25.351000; Duration from last logged action: 0:00:00.002000; Info: My first line of code... Time: 10:46:25.364000; Duration from last logged action: 0:00:00.001000; Info: GetParameterAsText... Time: 10:46:25.377000; Duration from last logged action: 0:00:00.001000; Info: ConvertWebMapToMapDocument... Time: 11:10:39.084000; Duration from last logged action: 0:24:13.699000; Info: ListDataFrames... Time: 11:10:39.149000; Duration from last logged action: 0:00:00; Info: ListDataFrames... Time: 11:10:39.194000; Duration from last logged action: 0:00:00.025000; Info: ListLayers to collect info... Time: 11:10:39.439000; Duration from last logged action: 0:00:00.227000; Info: MoveLayer... Time: 11:12:27.515000; Duration from last logged action: 0:01:48.058000; Info: ListLayoutElements... Time: 11:12:27.955000; Duration from last logged action: 0:00:00.425000; Info: ListLayers to apply changes... Time: 11:12:28.291000; Duration from last logged action: 0:00:00.323000; Info: listLegendItemLayers... Time: 11:12:32.671000; Duration from last logged action: 0:00:04.366000; Info: ExportToPDF... Time: 11:15:42.012000; Duration from last logged action: 0:03:09.329000; Info: Clean up... Time: 11:15:42.040000; Duration from last logged action: 0:00:00.013000; Info: Last line of code... Completed script PARprintPP... Succeeded at Tue Feb 20 11:15:44 2018 (Elapsed Time: 29 minutes 34 seconds) Succeeded at Tue Feb 20 11:15:44 2018 (Elapsed Time: 29 minutes 34 seconds) ---------------------------------------------------------------------------------------------------------- Start Time: Tue Feb 20 11:42:54 2018 Running script PARprintPP Time: 11:43:09.747000; Duration from last logged action: 0:00:00.001000; Info: My first line of code... Time: 11:43:09.760000; Duration from last logged action: 0:00:00; Info: GetParameterAsText... Time: 11:43:09.772000; Duration from last logged action: 0:00:00; Info: ConvertWebMapToMapDocument... Time: 11:43:32.735000; Duration from last logged action: 0:00:22.950000; Info: ListDataFrames... Time: 11:43:32.747000; Duration from last logged action: 0:00:00; Info: ListDataFrames... Time: 11:43:32.778000; Duration from last logged action: 0:00:00.021000; Info: ListLayers to collect info... Time: 11:43:32.968000; Duration from last logged action: 0:00:00.179000; Info: MoveLayer... Time: 11:43:34.909000; Duration from last logged action: 0:00:01.930000; Info: ListLayoutElements... Time: 11:43:35.341000; Duration from last logged action: 0:00:00.420000; Info: ListLayers to apply changes... Time: 11:43:35.667000; Duration from last logged action: 0:00:00.313000; Info: listLegendItemLayers... Time: 11:43:40.001000; Duration from last logged action: 0:00:04.317000; Info: ExportToPDF... Time: 11:45:07.315000; Duration from last logged action: 0:01:27.306000; Info: Clean up... Time: 11:45:07.341000; Duration from last logged action: 0:00:00.012000; Info: Last line of code... Completed script PARprintPP... Succeeded at Tue Feb 20 11:45:10 2018 (Elapsed Time: 2 minutes 16 seconds) Succeeded at Tue Feb 20 11:45:10 2018 (Elapsed Time: 2 minutes 16 seconds) Remark: If I change the recycle time interval for my geoprocessing service to 1 hour and test it after the recycle process has been completed I get normal timings which suggests that the slow performance has to be related with something else, something that happens over the night with ArcGIS Server and/or the server where is being hosted.
... View more
02-21-2018
08:00 AM
|
0
|
2
|
911
|
POST
|
Hello, I’ve developed a custom print service for ArcGIS Server using a very similar approach to this one. When this service is called for the first time in a day, it times out or it requires 20-30 mins to complete. After this happens, everything seems to be back to normal and the service runs in approx. 2-3 mins. I would much appreciate any thoughts of why this is happening or how it can be fixed. Please find details below: ArcGIS Servers (10.4.1) geoprocessing service config: Execution mode: Asynchronous Minimum/ Maximum number of instances per machine: 1/4 The maximum time a client can use a service: 1800 secs The maximum time a client will wait to get a service: 400 secs The maximum time an idle instance can be kept running: 1800 secs Run instances of this configuration: In a separate process for each instance (high isolation) Recycle this configuration every: 24 hours, Starting at: 00:00 ArcGIS Server logs: Processing request took longer than the usage timeout for service ../Print.GPServer'. Server request timed out. Check that the usage timeout is appropriately configured for such requests. Python script info: Imports: arcpy, os, uuid, json A template which has all the layers (approx. 80) of the web map is being used to compare the legend entries with the ones from the web app. The main purpose of it is to use the symbology of the template, not the one used by the web app. The template references Feature Classes stored in Oracle. General remarks: If I capture the JSON string sent to the server by the print widget and run it locally in ArcMap, it always completes in less than 2 minutes I think it is related with the service being recycled each night at 00:00 which is why the first run takes so long NB: I would be interested to know if there is another option rather than just increasing the time a client can use this service (I’ve got 30 mins already)
... View more
02-14-2018
03:41 AM
|
0
|
5
|
1561
|
POST
|
No, I don’t mind splitting this into separate script/tools. In fact, this GUI has only one purpose: to collect valid input for a new record in a polygon feature class. So to be able to replicate this with scripts/tools I guess that eventually I will run a master tool (that groups all the other ones) to get the same result: add a new record to a polygon feature class. Do you think that I will be able to get all the aforementioned functionality with (Python) scripts and tools only? Functionality list: Input Criteria: Allow/Disallow users for input based on a previous input Input ID: Allow the user to edit a list that was previously built based on a search in a specified location. I think this one can be easily solved by adding another input for manual entries so the final result will be a merged list between found files and user specified files. Input Geometry: Allow the user to select a feature on the map or to draw it using the built in functionality that comes with ArcMap and then get the Spatial Related Input. Without having a good understanding of how (Python) scripts/tools work I do believe that for this approach the way of getting the input must be simplified. I was thinking to start from an already drawn feature that has an attribute for the ID (the one used to search for the files). This way it will be possible for a tool to solve the ID related Input and Spatial Related Input.
... View more
07-13-2016
09:54 AM
|
0
|
0
|
220
|
POST
|
I’m trying to find the best solution for adding/update a new/old record in a feature class in ArcMap 10.3 environment using a GUI. I’ve done some research for the last couple of days trying to identify the solution that will best fit my needs but because I haven’t got experience with developing for ArcMap I’ve ended up on this forum. My experience in programming is related to using VBA with Excel and AutoCAD and some Java and Python codding. The main structure of the input is described in the picture bellow. Basically it should collect some data based on a user input, get some additional input based on the initial input and add a new record in a polygon feature class. Considering what I’ve understood so far it looks like I can use ArcObjects or a combination between Custom Script Tool and Python with a possibility of including PyQT as well . I’ve spent some time in trying to see if ArcObjects for .Net is the proper tool and looks like I will be able to get what I need but I was wondering if there is a better approach or if I can do it without ArcObjects. I am most worried about the select/create feature from the drawing with snapping capabilities and branching functionalities. I would also much appreciate answers that can help in how or what NOT to use to achieve my goal.
... View more
07-13-2016
07:49 AM
|
0
|
2
|
1487
|
Online Status |
Offline
|
Date Last Visited |
02-17-2022
03:09 AM
|