|
POST
|
Hi, I do have a little problem in my business logic of my Python tool. In case the user does not have street and municipality names for the addresses the fields 'Municipality names' and 'Street name' should not only be disabled but also not Required. However, when the appropriate checkbox is set to False these Fields are required. Is there any possibility to disable a parameter in a Python toolbox that the parameterType is neglected? Also, that I have to give a parameterType to a checkbox (or GPBoolean), or that there is a 'Required' given as default value is a bit weird. Looking forward to any suggestion on how to solve these issues. Bests Thomas
... View more
12-19-2014
05:13 AM
|
0
|
3
|
4575
|
|
POST
|
Okay, I just found it... Well, to assign a value you have to say: parameters[1].value = int(str_file[:4]) So, now it works without any problems.
... View more
11-25-2014
05:16 AM
|
1
|
0
|
1104
|
|
POST
|
Thanks Dallas, the stupid thing still comes back saying: File "<string>", line 174, in updateParameters TypeError: 'NoneType' object is not callable
... View more
11-25-2014
04:58 AM
|
0
|
1
|
1104
|
|
POST
|
I have the issue that I want to set value of a parameter from within the updateParameters function in a Python toolbox. The parameter is defined like this:
def getParameterInfo(self):
in_fc_mark = arcpy.Parameter(
displayName="Field Data (calculation year)",
name="pln_classes",
datatype="String",
parameterType="Required",
direction="Input")
# Define calculation year
int_today = datetime.datetime.today().year
in_int_year = arcpy.Parameter(
displayName="Calculation Year",
name="str_years",
datatype="GPLong",
parameterType="Required",
direction="Input")
in_int_year.filter.type = "Range"
in_int_year.filter.list = [1980, int_today+1]
parameters = [in_fc_mark,
in_int_year]
return parameters
and I would like to set the value for it this way:
def updateParameters(self, parameters):
if parameters[0].altered:
str_file = datetime.datetime.strftime(dparser.parse(os.path.basename(parameters[0].valueAsText), fuzzy=True),'%Y%m%d')
if str_file[:4].isdigit():
parameters[1].value(int(str_file[:4]))
return
However, it doesn't work. I can enable parameters of type "GPBoolean" with parameters[1].enabled = True, but setting the value gives me trouble. How can I do this? Bests, Thomas
... View more
11-21-2014
03:18 AM
|
0
|
3
|
3925
|
|
POST
|
I am running into an issue publishing my Python tool as a geoservice. One of the first things in the tool is the selection of a workspace, which I then set as arcpy.env.workspace. Even though the parameter is clearly some the user can choose, when trying to publish the tool this parameter is recognized as a constant. Apart from not being able to write any description for the parameter, that keeps me from publishing the service and it determines default values for the other fields the user can choose from. I can only deselect the fields, or feature classes that haven't been used in the successful run of the tool. My question would be on how to get rid of these values, since I do not want to have any default values in any of the fields provided for user input. Bests, Thomas Environment: ArcGIS Server 10.2, ArcGIS 10.2.1
... View more
10-24-2014
06:19 AM
|
0
|
0
|
2366
|
|
POST
|
Hi Dan, thanks for the link. I am using 'altered' for some string fields earlier in the tool to actually 'enable' the checkbox in the first place. I guess I can make use of 'altered' property, defining an initial value and switch that value forth and back when the checkbox is turned on and off (altered). I am fine using parameters .value. However, I do not know what the value actually is. I know that valueAsText returns 'true' or 'None' but I cannot check explicitly against these values, and I find that strange.
... View more
10-12-2014
04:00 AM
|
0
|
0
|
1138
|
|
POST
|
Writing a tool within a Python toolbox I ran into the problem of checking the status of some checkbox. While setting a default value for the checkbox is no problem,
parameter_bool.value = True
it comes kind of strange to retrieve the status. If I am not completely wrong then every parameter has two possibilities to achieve that: value, and valueAsText. First I tried to check against the value:
if parameters[0].value is True:
then against valueAsText,
if paramaters[0].valueAsText == 'true':
It took me a bit to realize that valueAsText will return either 'true' or 'None'. Why does it not return 'false'? However to check against it did not work. This part of the loop was never touched... I ended up in using:
if parameters[0].value:
or
if not parameter[0].value:
Can somebody explain to me why it is impossible to check against the textual value by using the same strings that will be returned if I retrieve them this way?:
arcpy.AddMessage(str(parameters[0].valueAsText))
Wouldn't it be much easier to simply check the value against True/False?
... View more
10-11-2014
07:28 AM
|
0
|
2
|
2057
|
|
POST
|
I'm also not sure where and why the name should be truncated. However, I would suggest to use arcpy.da.Walk(), simply because you do not have to start over and over again to find all the feature classes within the database.
import arcpy, os
f = open('C:/temp/fc_list.txt', 'a')
arcpy.env.workspace = r'C:/temp/Tracks.gdb'
for dirpath, dirnames, filenames in arcpy.da.Walk(arcpy.env.workspace, datatype='FeatureClass'):
for filename in filenames:
fc_path = os.path.join(dirpath, filename)
f.write(fc_path + '\n')
f.close()
If you don't need the complete path skip line 7 and exchange 'fc_path' in line 8 by 'filename'.
... View more
10-09-2014
10:13 AM
|
4
|
0
|
1525
|
|
POST
|
Hi Jason, there is no difference in the resulting list if I replace DEFeatureClass in line 12 by GPFeatureLayer. Reading the definition below it looks to me as if GPFeatureLayer is in my case actually a detour to the datasets requested. What escapes me at this point as well is why GPFeatureLayer should work, respectively why does it work anyway. According to the Resource Center DEFeatureClass = A collection of spatial data with the same shape type: point, multipoint, polyline, and polygon. GPFeatureLayer = A reference to a feature class, including symbology and rendering properties. finally, a DEFeatureDataset = A collection of feature classes that share a common geographic area and the same spatial reference system. By my understanding, GPFeatureClass would be the way to go, FeatureDatasets should not appear, and the filter list set should only populate the list of FeatureClasses with datasets of type point. Any other suggestions for the problem at hand? I tried to create a minimal example and wrapped it in the attached file. It contains a minimalistic FGDB and the toolbox. Cheers, Thomas
... View more
10-06-2014
12:56 AM
|
0
|
1
|
1224
|
|
POST
|
Hi, as the header says, I do have a problem in getting only the datasets I want. In the following my parameter definition is shown, where from I would expect to get only feature classes of type point to be shown.
p_envWorkS = arcpy.Parameter(
displayName = 'Workspace',
name = 'in_ws',
datatype = 'DEWorkspace',
parameterType = 'Required',
direction = 'Input',
category = '1. Input Settings')
p_envPoints = arcpy.Parameter(
displayName = 'Input FeatureClass',
name = 'in_fc',
datatype = 'DEFeatureClass',
parameterType = 'Required',
direction = 'Input',
category = '1. Input Settings')
p_envPoints.parameterDependencies = [p_envWorkS.name]
p_envPoints.filter.list = ['POINT']
However, the following screenshot shows all kind of content. Even feature datasets are listed... hence the name 'roads' shows twice. Does some of you know where I am going wrong or what I am missing the get the correct feature type shown? Best regards, Thomas
... View more
10-03-2014
02:58 AM
|
0
|
3
|
1982
|
|
POST
|
Dear all, the code below is jamming after a while and I am incapable to see where or why. Background... I have about 14.000 buffers in a feature class and a road network of almost 1.000.000 features in another feature class. Both are within the same FGDB. I have to do a clip for each buffer, do some calculation on the clipped road pieces, and get the sum stored in a separate table. Except the result of the statistics analysis, that is written in file, all other results are kept in memory. In line 31 I empty the memory. Can somebody tell me why the process is getting continuously slower the longer it runs?
import arcpy
# Set environmental parameters
arcpy.env.workspace = r'C:/Path/to/Projects/Project.gdb'
arcpy.env.scratchWorkspace = r'C:/Path/to/Projects/scratchGDB/scratch.gdb'
arcpy.env.overwriteOutput = True
arcpy.MakeFeatureLayer_management('Cohort_noXY_buffer300', 'buffer')
arcpy.MakeFeatureLayer_management('roads', 'road')
expression = "TrafficLoad(!AGTRAF2DIR!, !AADT!, !TB_Length!)"
codeblock = """def TrafficLoad(Road2, ADT, Rlength):
if Road2 == 2:
x = ADT * 2 * Rlength
else:
x = ADT * Rlength
return x"""
# , """ "OBJECTID" >= 2442"""
with arcpy.da.SearchCursor('buffer', ['OID@']) as SCursor:
for row in SCursor:
out = r'C:/Path/to/Projects/noXY.gdb/Export_noXY_300_Buffer_' + str(row[0])
arcpy.SelectLayerByAttribute_management('buffer', 'NEW_SELECTION', """"OBJECTID" = {0}""".format(row[0]))
arcpy.Clip_analysis('road', 'buffer', 'in_memory/clip')
arcpy.AddField_management('in_memory/clip', 'TB_ADT', 'DOUBLE', '', '', '', '', 'NULLABLE', 'NON_REQUIRED', '')
arcpy.CalculateField_management('in_memory/clip', 'TB_Length', '!shape.length!', 'PYTHON_9.3')
arcpy.CalculateField_management('in_memory/clip', 'TB_ADT', expression, 'PYTHON_9.3', codeblock)
arcpy.Statistics_analysis('in_memory/clip', out, "TB_ADT SUM", '')
arcpy.Delete_management('in_memory')
print "{0} processed".format(out)
Best regards, Thomas
... View more
09-30-2014
02:29 AM
|
0
|
2
|
2051
|
|
POST
|
Hi Martin, I checked some of my code in a Python toolbox and was wondering if you can solve the problem by simple omitting the line param3.value = "False". The standard behaviour as far as I can see is anyway to have the checkbox unchecked. When I force my optional parameters to be true by setting param3.value = "True" then it works without any problems. Hope it helps! Otherwise... give me a call 😉 Cheers, Thomas
... View more
09-30-2014
01:44 AM
|
0
|
1
|
2936
|
|
POST
|
Hi Greg, never saw a '%T' and hey Tutorialspoint is a nice starting but nothing official and I would rather stick to the official docs. I solved the problem quick and dirty, and the task is pushing me further, but as soon as I have the time to check on locale and decode I will give it a try. Bests, Thomas
... View more
09-25-2014
12:13 AM
|
0
|
0
|
2487
|
|
POST
|
Hi, yes I can confirm that is has something to do with locale. A first solution was to change the format localization from Danish to English and restart the shell. I have to follow up on your suggestion to use the locale package. Thanks so far. Thomas
... View more
09-25-2014
12:10 AM
|
0
|
0
|
2487
|
|
POST
|
Hi, I want to convert some date strings into correct dates, to be recognized by Python and ArcGIS. Setup: ArcGIS 10.2.1 Python 2.7.5 All data are located within a FGDB... I set the workspace to be the FGDB, created a new Field of type data in my table and went on with the following things within the IDLE Shell import datetime with arcpy.da.UpdateCursor(myTable, [field01, field02]) as UCursor: for row in UCursor: origDate = datetime.datetime.strptime(row[0], '%d%b%Y') row[1] = datetime.date.strftime(origDate, '%Y-%m-%d') UCursor.updateRow(row) Things work fine until the input string is '11MAY2004', where I get the following error message: Traceback (most recent call last): File "<pyshell#9>", line 4, in <module> origDate = datetime.datetime.strptime(row[0], '%d%b%Y') File "C:\Python27\ArcGISx6410.2\lib\_strptime.py", line 325, in _strptime (data_string, format)) ValueError: time data '11MAY2004' does not match format '%d%b%Y' I did try the whole thing in plain Python (same shell) before, where I simply did: orig = '11MAY2004' x = datetime.datetime.strptime(orig, '%d%b%Y') and this works without any problem!!! Can somebody enlighten me where I go wrong? Cheers, Thomas
... View more
09-24-2014
02:28 AM
|
0
|
4
|
6380
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-24-2022 01:23 AM | |
| 1 | 09-15-2021 01:21 AM | |
| 1 | 08-30-2022 04:31 AM | |
| 2 | 04-24-2024 04:23 AM | |
| 3 | 12-12-2023 07:49 AM |
| Online Status |
Offline
|
| Date Last Visited |
11-08-2025
10:36 PM
|