|
POST
|
Dan's method works if all values have a suffix like '-1234'. But if some records don't have that, e.g. they just have the 5 digit zip, you'll be getting rid of that part of the field and would end up with no zip. You might want to try: >>> a = "MAPLE GROVE MN 55369-3466" >>> lst = a.split('-') >>> if len(lst) > 1: # i.e., you have a '-' in the field ... b = lst[0] # this is the value you want Even this isn't foolproof, since a '-' anywhere in the field will get caught, for instance, a street named Sans-Souci. There are ways to catch that, but trying to keep it simple.
... View more
05-15-2014
11:30 AM
|
0
|
0
|
1959
|
|
POST
|
Try something like:
# 1. list fields (from here)
import arcpy
featureclass = "c:/data/municipal.gdb/hospitals"
field_names = [f.name for f in arcpy.ListFields(featureclass)]
# 2. another method
import arcpy
lstflds = arcpy.ListFields("yourfeatureclass")
for fld in lstflds:
if fld.name == "somefield":
arcpy.DeleteField_management("yourfeatureclass", "somefield")
# 3. simpler, if you know your feature class; no need to check field name, you provide it
arcpy.DeleteField_management("yourfeatureclass", "somefield")
... View more
05-15-2014
06:52 AM
|
0
|
0
|
1899
|
|
POST
|
I think what you want to do is change 'get_backlink(count + 1)' to 'get_backlink(chr(count + 64)) ', or possibly to 65 0r 66, can't be sure from your code, since it looks like you first use count when it's 1. Depends on the rest of your code. Since you're first looking for 'A', you want to add whichever number gets you to 65, assuming this is ascii. However, you'll never get past 'C' , since your loop exits once it hits 2. edit: oh, and don't forget to increment count or you'll be in an infinite loop. Maybe that's elsewhere in your code.
... View more
05-13-2014
01:44 PM
|
0
|
0
|
2064
|
|
POST
|
You may want to look at chr(). This will return the string version of the numeric value, for example, chr(97) = 'a'. You'd have to look up the value of the character in your encoding and add that to your counter. For example, in ascii, A = 65, B = 66, C = 67...a = 97, b = 98...etc. So in ascii, if your counter starts at 0, add 65 to it so that 0 will become A, 1 will become B, etc. Unicode and other encodings are probably different.
... View more
05-13-2014
12:01 PM
|
0
|
0
|
2064
|
|
POST
|
No, don't use this in Field Calculator. Open the Python window from the toolbar and enter it there. Check your CalculateField call though. It appears you're trying to calculate data2 on itself, but there's nothing in data2. You probably want to change data2.lstrip(' ') to data1.lstrip(' '). You're also not enclosing both datax fields in !'s. Also, since you already created data2, no need, and probably throw an error, to add it again. If you have data2 already, delete the AddField line. edit - I see you populated data2 first, but there's no need to do this. edit * 2 - since you already have field data2, you can just use regular Field Calculator. If the leading character in your values for data2 is the only space in them, you can use Replace(' ', '') with the default VB parser (all characters in Replace() are single quotes). If you have other spaces in the values, switch to Python parser, add data2 (or data1, won't matter), and add [1:]. So !data2![1:]. Or you can use lstrip as above - !data2!.lstrip(). Lstrip will default to using whitespace, so no need to add ' ' to it.
... View more
05-13-2014
03:23 AM
|
0
|
0
|
4885
|
|
POST
|
Not to my knowledge. This would be a text field, where characters are evaluated independently. Here, 2 will always come after 1 in the same position in the text. Maybe there's some font encoding trick I don't know, or maybe you could sort on a different field, say datecreated, that might achieve the same effect, but that depends on what's in your data. One possible way to achieve this would be to add a new integer field, calculate it in python to int(field[1:]), which would give you a numeric field with just the number portion of your original field. Then sort on that. This won't work if you later have values like B1, B10, B20, B200... because it won't distinguish between A200 and B200, for example. But if all your values begin with A, should work.
... View more
05-12-2014
11:42 AM
|
0
|
0
|
917
|
|
POST
|
Where are you performing this calculation? Script, python window, field calculator? Also, there's nothing to calculate for data2. You're adding the field data1, but there's no data in it at that point. There's nothing to run lstrip() on. You need to populate it. edit: you also want to use "PYTHON_9.3" for your setup, not just "PYTHON"
... View more
05-12-2014
03:28 AM
|
0
|
0
|
4885
|
|
POST
|
Title pretty much says it all. I extruded a building footprint fc in ArdScene based on a height field, which worked fine. I'd like them to display that way in ArcMap, and eventually as a service as part of a basemap. Is this possible? Thanks.
... View more
05-08-2014
08:08 AM
|
0
|
0
|
1324
|
|
POST
|
Can you use row.distanceField instead of row.getValue(distanceField)? Also, make sure distanceField is numeric, not text, although that would probably be a different error.
... View more
05-08-2014
05:21 AM
|
0
|
0
|
2244
|
|
POST
|
Thanks Wayne. It's kind of on the back burner for now. Turns out a former co-worker wrote a vb.net tool that does this (or similar, not sure since the tool is used by someone else) a few years ago. The problem with that is that the installer he included throws a LoadException error and won't install on Windows 7 (or maybe the problem is with Arc 10.1 and above). It appears to be an issue of the dll looking for a missing or bad pathed assembly. It was installed previously on an XP machine with Arc 10.0, which was upgraded to 10.2.2, and appears there. Which would be good except that machine doesn't support the SQL Native Client drivers needed to edit. So now we're trying to locate an old laptop that has Visual Studio so we can open and hopefully fix it. For reasons above my pay grade VS Express is not an option. In regards to your fix to the code, though, I'm confused. Why would I append to lstDoubleCheck? That will have the data sorted in OID order. I'm only using it to make sure that any selected features weren't missed in lstChanged. If I do work on this further, I may see if I can skip the batch update of all features, and just increment a counter and update individually as a feature is selected. I think that may be the vb tool behavior.
... View more
05-08-2014
05:15 AM
|
0
|
0
|
2762
|
|
POST
|
Here's a very simple way to call another script (there are many other ways): Or just import it.
... View more
05-07-2014
11:48 AM
|
0
|
0
|
1733
|
|
POST
|
That looks like it may be a bug. What version of Arc are you running? All I can think of is to put the out of scale layers at the top or botton (or if just two, one at top one at bottom) on the items tab of Legend Properties. There will still be a gap, but it won't be between items, it will be between the items and the legend frame, maybe between the word Legend if you use that.
... View more
05-07-2014
11:00 AM
|
0
|
0
|
925
|
|
POST
|
Well, that's not using InsertLayer. There's a good example at the link I provided. Anyway, if you want to use AddLayer. change this: df = arcpy.mapping.ListDataFrames(mxd, "Parks")[0] to this: df = arcpy.mapping.ListDataFrames(mxd, "Parks")[1] and so on. the [0] refers to your first data frame. [1] is the second, [2] is the third, etc. You can call the function twice, or put it in a loop something like: import arcpy
mxd = arcpy.mapping.MapDocument(r"P:\G4910\G4910_06\Data\Data\Exercise10\Austin_TX.mxd") dfList = arcpy.mapping.ListDataFrames(mxd, "Parks") addLayer = arcpy.mapping.Layer("parks.lyr")
for df in dfList:
arcpy.mapping.AddLayer(df, addLayer, "BOTTOM")
mxd.saveACopy(r"P:\G4910\G4910_06\Data\Data\Exercise10\Austin_TX.mxd") del mxd, addLayer
... View more
05-07-2014
10:53 AM
|
0
|
0
|
1043
|
|
POST
|
Ok, getting there slowly, not there yet. In the code below, as soon as I start editing, onEditorSelectionChanged runs through all the OIDs, although none are selected at that point - no change has occurred. When I then select one, it runs through them again, but raises an 'index out of range' exception on .pop(), presumably for the one I selected. I thought SearchCursor honored selections. Then, when I click the button, onClick raises a 'list object not callable' exception on 'if lstChanged(item) not in lstDoubleCheck'. This is puzzling. I must be missing something simple, but nothing's popping out at me. import arcpy
import pythonaddins
lstChanged = []
fc = r"C:\path\to\file\Lots"
field = "OBJECTID"
class CheckSelectionChange(object):
"""Implementation for PyAddInWizard_addin.ext1 (Extension)"""
def __init__(self):
# For performance considerations, please remove all unused methods in this class.
self.enabled = True
def onEditorSelectionChanged(self):
for row in arcpy.SearchCursor(fc, '', '', field):
print "Row: " + str(row.OBJECTID) + "\n" # just for testing
if row.OBJECTID in lstChanged:
lstChanged.pop(row.OBJECTID) # raises error
else:
lstChanged.append(row.OBJECTID)
class CreateLotNum(object):
"""Implementation for PyAddInWizard_addin.btn1 (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
lstDoubleCheck = []
for row in arcpy.SearchCursor(fc, '', '', field):
lstDoubleCheck.append(row.OBJECTID)
for item in lstChanged:
if lstChanged(item) not in lstDoubleCheck: # raises error
lstChanged.append(item)
with open(r"C:\Temp\id.txt", "w") as f: # also for testing
for item in lstChanged:
f.write(lstChanged(item) + "\n")
... View more
05-07-2014
05:34 AM
|
0
|
0
|
2762
|
| Title | Kudos | Posted |
|---|---|---|
| 6 | 08-22-2019 07:41 AM | |
| 1 | 05-05-2014 04:30 AM | |
| 1 | 08-15-2018 06:23 AM | |
| 3 | 08-06-2018 07:31 AM | |
| 1 | 03-30-2012 08:38 AM |
| Online Status |
Offline
|
| Date Last Visited |
12-12-2021
01:00 PM
|