POST
|
Ah, that logic makes total sense when I see it like this. I haven't had the opportunity to test this out yet but will do so ASAP. Will do some testing with longName as you suggested, my previous tries included this but didn't use the same logic as you did so might be an excellent building block. Thank you!
... View more
05-21-2022
01:51 AM
|
0
|
0
|
539
|
POST
|
Yes, fully aware of how to get and set the scale thresholds through the mapping module for individual layers. What I can't figure out is how to apply the thresholds from the group layer to every feature layer that falls within that group layer. I hope that clarifies. Any advice? As for why I'm attempting this - One reason (aside from being told to do so by a boss 😉 ) is that I have a requirement to make these projects more bulletproof so that if a layer gets moved out of place it's still being displayed correctly. I also have to output a config file that shows the properties of every layer and this is how I envision making the scales of grouped layers more easy to understand for some users.
... View more
05-20-2022
10:32 AM
|
0
|
0
|
551
|
POST
|
Can someone help me to solve this arcpy problem? I'm using ArcGIS Pro 2.5 if that helps. An example of my issue: I have 20 group layers. Inside each group layer are 20 feature layers (all vector). The grouping only goes one level deep (Group layer Roads --> Feature layer Highways, for example). Values for minScale and maxScale have been applied to the top-level group layers (which control visibility for everything in the group), but not to the feature layers within the group. Using arcpy I'd like to get the minScale and maxScale values from the top-level group and set those values to all feature layers within that group. A bonus would be if there was some operation that could comprehend what higher group layer is controlling the minScale / maxScale of a feature layer and apply that, but for now the rigid structure outlined above with just two levels will do. Can someone help me organize the logic and code around this problem?
... View more
05-20-2022
07:01 AM
|
0
|
4
|
591
|
POST
|
I figured out the problem and it was a stupid amateur mistake that I didn't see until now. I hadn't cleared a selection prior to running the cursor, so the cursor was only running on selected records. Clearing the selection allowed the cursor to run on the entire layer which is what I wanted. Such a silly mistake. Thanks to everyone David Pike Dan Patterson Jeff Kling for their help in organizing the code just a bit better. Here is the code I ended up using (although my original code would've worked just fine too if the selection was cleared beforehand): with arcpy.da.UpdateCursor (in_table="RoadsAnno", field_names=["Status","TextString"] as cursor:
for row in cursor:
if row[1] is None or row[1] =="":
cursor.deleteRow()
else:
row[0] = 0
cursor.updateRow(row)
del cursor
... View more
03-13-2020
08:18 AM
|
1
|
0
|
1614
|
POST
|
No, I don't have access to the software at home in the evenings but I will try out in the morning. As I said in that paragraph however, the order of the updateRow and deleteRow statements didn't seem to affect the functioning of the last example where I changed the attribute to "DeleteMe"
... View more
03-12-2020
04:56 PM
|
0
|
0
|
1614
|
POST
|
Ah yes, that was in the code originally - I was typing out this question from memory at home and forgot that line. I'll amend the question; thanks for the heads up.
... View more
03-12-2020
04:51 PM
|
0
|
0
|
1614
|
POST
|
I have a fairly simple problem, and I've tried everything I can think of to fix it. I am using a data access update cursor in a larger script to update the value of one field, and if the other field is Null I want to delete the record. The update part works fine, but the delete part does not. My input data is an annotation feature class created by ArcMap (turn on labels, right-click layer, create annotation). Nothing fancy or complex. The annotation expression is stored in a field named TextString. If no annotation is created for the feature, the field is Null (as a default, all annotation classes created by ArcMap are nullable). When you look at it the attribute table it appears as <Null>. I cannot use a where clause in this case because of the first update. The following example should work as far as I can tell, but doesn't. with arcpy.da.UpdateCursor (in_table="RoadsAnno", field_names=["Status","TextString"]) as cursor:
for row in cursor:
row[0] = 0
cursor.updateRow(row)
if row[1] is None:
cursor.deleteRow()
del cursor, row (I also tried replacing "if row[1] is None:" with "if row[1] == None:" but no joy. "is None:" is the most proper way to write this according to my Python resources, though "== None:" still works (in other situations) So I then tried the following: with arcpy.da.UpdateCursor (in_table="RoadsAnno", field_names=["Status","TextString"]) as cursor:
for row in cursor:
row[0] = 0
cursor.updateRow(row)
if row[1] is None or row[1] =="" or row[1] == "<Null>":
cursor.deleteRow()
del cursor, row I figured one of those statements would catch the Null value, but it did not. I then changed the value of a previously Null row in the RoadsAnno feature class to read "DeleteMe" (not in quotes) and ran the following just to test if the cursor was picking up the right field: with arcpy.da.UpdateCursor (in_table="RoadsAnno", field_names=["Status","TextString"]) as cursor:
for row in cursor:
row[0] = 0
cursor.updateRow(row)
if row[1] is None or row[1] =="DeleteMe" or row[1] == "<Null>":
cursor.deleteRow()
del cursor, row The row containing the TextString attribute "DeleteMe" was deleted. So what's happening with the Null value? Would anyone be able to help with this? Why doesn't the cursor recognize the Null value in the field? Maybe Arc creates Null values with unseen characters or something that need to be stripped? EDIT: Do I have to put the updateRow statement after the deleteRow statement? Maybe the cursor is moving to the next row with the update and never gets the chance to delete? Although that wasn't the case for the "DeleteMe" example so perhaps this line of thought is not correct.
... View more
03-12-2020
03:45 PM
|
0
|
8
|
1749
|
POST
|
Based on Randy Burton 's reply, I used the following code in the validator which does exactly what I want. Thanks Randy! import arcpy
class ToolValidator(object):
def __init__(self):
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
self.params[0].filter.list = ["Digital Map", "Paper Map"]
self.params[0].value = "Digital Map"
return
def updateParameters(self):
if self.params[0].value == None:
self.params[0].value = "Digital Map"
if self.params[0].valueAsText == "Digital Map":
self.params[1].filter.list = ["Not applicable"]
self.params[1].value = "Not applicable"
self.params[1].enabled = False
else:
self.params[1].filter.list = ["1:10,000", "1:25,000"]
if self.params[1].value not in self.params[1].filter.list:
self.params[1].value = self.params[1].filter.list[0]
self.params[1].enabled = True
return
def updateMessages(self):
return
... View more
11-25-2019
05:35 AM
|
0
|
0
|
1112
|
POST
|
Sorry for the late reply to this - I was moved to another priority job and just got back to my normal work today. I’ve tried things again and as far as I can tell it is working as expected with no changes. Perhaps I just needed to clear some cobwebs from my understanding of the issue. Regardless, thanks for helping out.
... View more
11-21-2019
07:44 AM
|
0
|
0
|
3072
|
POST
|
I have some simple ArcPy script tool validator code that is giving me grief. I am using desktop at 10.3.1. I'm open to whatever help can be offered to get this to work as intended. I have two parameters for my script tool. The first is the type of product to be created, the second is the scale of the product. Digital Map / No scale required are the default values defined in the Tool Validator code. If it is a paper product, the user selects the appropriate scale from the drop-down list. The problem I can't solve is that if the user changes the value in parameter 0 to paper map, the list of scales becomes available but the value is still the default ("No scale required") so an error is thrown because that option is not in the scale list. The error clears when I select the scale from the list, but I want only those choices available and obviously don't want the error to appear at all. Likewise if I then change parameter 0 back to Digital Map the "No scale required" value appears but the error message is thrown again because that value is not in the scale list, which is somehow still appearing. There is no way to clear the error at this point. I'd really appreciate help with how to get these different combinations to appear and change as intended without any errors. If they pick Paper, only the scales appear. If they switch back to Digital, only the "No scale required" value appears. And so on. I can't guarantee the user's behaviour so I'd like for it to be bulletproof. import arcpy
class ToolValidator(object):
def __init__(self):
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
# Define the list of product types the user can choose from
self.params[0].filter.list = ["Digital Map", "Paper Map"]
self.params[0].value = "Digital Map"
return
def updateParameters(self):
if self.params[0].value == "Digital Map":
self.params[1].value = "No scale required"
if self.params[0].value == "Paper Map":
self.params[1].filter.list = ["1:10,000", "1:25,000"]
return
def updateMessages(self):
return
... View more
11-21-2019
06:29 AM
|
0
|
2
|
1218
|
POST
|
I'll see what I can do on Friday. Thank you for your insight so far
... View more
10-10-2019
04:03 PM
|
0
|
2
|
3072
|
POST
|
I’m working in ArcMap 10.3.1. If I type in an underscore in my attribute field and type in the same underscore (or copy-paste it into the code) would that ensure it’s the same character? I’ll keep playing with this and I’ll check for white space. I appreciate your help!
... View more
10-10-2019
11:12 AM
|
0
|
4
|
3072
|
POST
|
The first error you found was from me being sloppy when anonymizing my fields for posting here. The second error was a typo when moving the snippet to a computer connected to the outside world. I've edited the code above to fix those mistakes. Good catches but the real script (of which this is a generic snippet) runs fine without errors, but doesn't do what I expect it to if the underscore character is present. If I amend my data to be "NA" and my script to look for "NA" it works as expected as an error check, but unfortunately editing the source data when doing the real work is not an option at the moment.
... View more
10-10-2019
09:55 AM
|
0
|
6
|
3072
|
POST
|
I am using an update cursor to update one field based on the content of another. I can't get part of the Python script I've written to properly handle the underscore special character that is present in my data. I think I need to do something to ensure the string is read as unicode and not ascii, but I cannot figure out how to do this when referring to an index value. Can someone help? (Below is not the real script but it is the part that I am having trouble with.) with arcpy.da.UpdateCursor (in_table="Test", field_names=["CATS", "DOGS"]) as cursor:
for row in cursor:
if str(row[0].upper()) not in ["PIZZA", "N_A"]:
row[1] = 12345
cursor.updateRow(row)
del cursor, row
... View more
10-10-2019
06:26 AM
|
0
|
8
|
3273
|
POST
|
I have figured out a solution that give me exactly what I want and it is fast (enough). It parses through the large file and writes the data I need in about 2.5 minutes, which is about 4 times faster than the external VB script it replaces, plus it gives me a GIS output within my current workflow. I did not use any of the array code that Dan mentioned but I will be reading those answers very closely and applying whatever I can find there to future projects indeed. Very appreciated Dan Patterson In case anyone is in the same circumstance this is what I am using: Input = arcpy.GetParameterAsText(0)
codes = arcpy.GetParameterAsText(1).split(",")
arcpy.env.workspace = arcpy.GetParameterAsText(2)
sr = arcpy.SpatialReference(4326)
arcpy.env.overwriteOutput = True
Output = arcpy.CreateFeatureclass_management(arcpy.env.workspace, "Output", "POINT", "", "DISABLED", "DISABLED", sr)
arcpy.AddField_management(Output, "LAT", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "LONG", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "IOH", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "MEASURE1", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "MEASURE2", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "MEASURE3", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "CODE", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "TYPECODE", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "TYPENAME", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "FEATCODE", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "FEATNAME", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "COL", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "MULT", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "DATE3", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "DATE5", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
arcpy.AddField_management(Output, "AORD", "TEXT", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
with open(Input, 'r') as file:
with arcpy.da.InsertCursor(Output,["SHAPE@XY", "LAT", "LONG", "IOH", "MEASURE1", "MEASURE2", "MEASURE3", "CODE", "TYPECODE", "TYPENAME", "FEATCODE", "FEATNAME", "COL", "MULT", "DATE3", "DATE5", "AORD"]) as InsCur:
for line in file:
values = line.split("\t")
LAT = values[5]
LONG = values[6]
IOH = values[1]
MEASURE1 = float(values[9])*0.2691
MEASURE2 = float(values[10])*0.2691
MEASURE3 = float(values[11])*0.2691
CODE = values[2]
TYPECODE = values[7]
TYPENAME = values[8]
FEATCODE = values[38]
FEATNAME = values[39]
COL = values[18]
MULT = values[20]
DATE3 = values[23]
DATE5 = values[24]
AORD = values[32]
if values[2] in codes and float(values[9])*0.2691 >= 75:
newGeom = arcpy.PointGeometry(arcpy.Point(LONG,LAT))
InsCur.insertRow([newGeom,LAT,LONG,IOH,MEASURE1,MEASURE2,MEASURE3,CODE,TYPECODE,TYPENAME,FEATCODE,FEATNAME,COL,MULT,DATE3,DATE5,AORD])
OutputCount = arcpy.GetCount_management(Output)
OutputCountInt = int(OutputCount.getOutput(0))
if (OutputCountInt < 1):
arcpy.AddMessage("There are no valid points in your AOI.")
else:
arcpy.AddMessage("Points have been written to the Output feature class in your input database.")
... View more
04-05-2019
09:16 AM
|
1
|
0
|
396
|
Title | Kudos | Posted |
---|---|---|
1 | 04-05-2019 09:16 AM | |
1 | 03-20-2019 10:27 AM | |
1 | 03-13-2020 08:18 AM |
Online Status |
Offline
|
Date Last Visited |
05-21-2022
03:22 AM
|