|
POST
|
I want to make sure I understand your work flow. You are selecting the first text file in a directory. Is this the only text file in the directory, or do you plan to process other files in the same directory? I'm curious why you are not setting up the tool to use a text file as the first parameter in place of a folder location. For the "calcrow[0] is not None" test, is this for just the first row, or for any row in that field? Can it be assumed that the min and max value will be selected from one of the fields that is in the field selected list?
... View more
02-20-2019
11:20 PM
|
0
|
1
|
6143
|
|
POST
|
If you know the spatial reference of your x,y coordinates, you could use something like the following: inSR = arcpy.SpatialReference(3857) # web mercator (use your spatial reference here)
outSR = arcpy.SpatialReference(4326) # wgs_1984 (lon-lat)
ptGeo = arcpy.PointGeometry(arcpy.Point(x,y),inSR).projectAs(outSR)
print (ptGeo.centroid.X, ptGeo.centroid.Y) # lon-lat of point See Reprojecting tabular data without creating feature class? for more discussion.
... View more
02-20-2019
02:35 PM
|
0
|
0
|
994
|
|
POST
|
And auto correct can be so helpful , like adding an accented e at the end of "café" etc. and thus sending it into extended ASCII or Unicode.
... View more
02-19-2019
03:42 PM
|
1
|
0
|
5163
|
|
POST
|
As an alternative to field mapping (and for future reference), look at Xander Bakker's code near the bottom of this thread: FieldMap and FieldMappings arrgh....
... View more
02-19-2019
03:16 PM
|
2
|
1
|
11039
|
|
POST
|
I think the second "True" (where you have non-editable) is actually "nullable", and the last 2 items (both -1) is the start text and end text positions. See also: Field Map Field Mappings Mapping input fields to output fields
... View more
02-19-2019
10:14 AM
|
2
|
0
|
11039
|
|
POST
|
For a bit of clarity, here is the execute section formatted as Dan suggests. I've added the return on line 28, but I think you have additional code that goes before that line. class Tool(object):
#......
def execute(self, parameters, messages):
"""The source code of the tool."""
DataSource = parameters[0].valueAsText
InputPoint = parameters[1].valueAsText
OutputTB = parameters[2].valueAsText
# Add geometry attributes to inupt point
arcpy.AddField_management(InputPoint, "POINTID", "SHORT")
arcpy.AddGeometryAttributes_management(InputPoint, "POINT_X_Y_Z_M", "", "", 4326)
with arcpy.da.UpdateCursor(InputPoint, "POINTID") as cursor:
index = 0
for row in cursor:
row[index] = index
index += 1
del row
del cursor
# add fields to output table to hold the temporal data
arcpy.AddField_management(OutputTB, "POINTID", "SHORT")
arcpy.AddField_management(OutputTB, "DATAINDEX", "SHORT")
arcpy.AddField_management(OutputTB, "VALUE", "DOUBLE")
return I believe you need to use Create Table before lines 23-26 that are adding fields. Your third parameter appears to be the name for the table, but the table is not created just by giving it a name in the parameter form. I'm also not sure if your code is getting past line 17, which probably should be row[0] = index. Since you are incrementing index, the value of row[index] would quickly be out of range. If I understand what you are trying to do, you are adding longitude and latitude fields to a point feature with the Add Geometry Attributes tool. This will add two fields of type double to the feature (POINT_X and POINT_Y as default names). You are also adding an id field as a short integer instead of using the OID@ field. I am assuming that you want to read the point id, longitude and latitude into your table. Your table will need 2 fields of type double for the xy coordinates. So it seems you may want to rethink your table design. Since things can be a bit tricky to debug inside a python toolbox, I would suggest trying the execute function as a stand-alone script. Then add it back into your toolbox script. Hope this helps.
... View more
02-17-2019
09:01 PM
|
1
|
1
|
3700
|
|
POST
|
It might be possible to navigate through your point feature using a dictionary, where the value of the point (down) becomes the key for the next point (up). From your sample data, the points starting and ending a line segment, do not match other points. That is, the starting point's up value does not have a match in the down column, and the ending point's down value does not have a match the up column. In my test, I converted your shape file to a file geodatabase feature. To the feature, I added fields for line segment and segment order. The name for the line segment is the up value for the starting point. Here's a debug printout: OID UP DOWN LINE ORDER
1 1118 1113 1118 1
2 1113 1121 1118 2
3 1121 1115 1118 3
4 1115 1114 1118 4
5 1114 1123 1118 5
6 1123 1119 1118 6
...
20 1031 1041 1118 20
21 1041 1009 1118 21
22 1009 1035 1118 22
23 1035 1040 1118 23
24 1040 1069 1118 24
25 995 1000 1184 4
26 1000 1103 1184 5
27 1003 987 1003 1
28 987 985 1003 2
29 985 993 1003 3
...
794 156 184 259 104
795 171 149 173B 2
796 149 164 173B 3
797 164 157 173B 4
798 157 137 173B 5
799 137 155 173B 6
800 688 670 743 56
801 680 688 743 55
802 683 680 743 54
803 184 178 259 105
804 178 L-14 259 106
805 L-14 178B 259 107
806 173B 171 173B 1
807 687 704 743 52
808 704 683 743 53
809 173 192 259 79
...
851 116 94 133 18
852 94 109 133 19
853 109 115 133 20
854 115 123 133 21
855 123 131 133 22
856 L-63A 744 L-63A 1
857 744 L-57A L-63A 2
858 L-57A 675 L-63A 3
859 675 744A L-63A 4
860 168 159 168 1
861 159 151 168 2
862 151 158 168 3
863 158 166 168 4
864 166 145 168 5
865 145 144 168 6
866 144 120 168 7
867 120 154 168 8
868 655 630 743 112
869 630 L-60 743 113
870 L-60 630A 743 114
871 630A 666C 743 115
872 666C 635 743 116
873 635 L-24A 743 117
874 L-24A 1083 743 118 Here's the code I used: import arcpy
import numpy as np
sourceFC = r'C:\Path\to\example.gdb\example'
# use OID@ token
sourceFieldsList = ["JOINT___UP", "JOINT___DO", "OID@"]
updateFields = ["OID@", "LineSeg", "SegOrder" ] # LineSeg is text, SegOrder is long int
valueDict = {r[0]:(r[1:]) for r in arcpy.da.SearchCursor(sourceFC, sourceFieldsList)}
up = [] # values of JOINT___UP (the up point list)
do = [] # values of JOINT___DO (the down point list)
for k in valueDict:
dn, id = valueDict[k] # k = key = JOINT___UP, dn = JOINT___DO, id = OID@, LineSeg, SegOrder
up.append(k) # up point values
do.append(dn) # down point values
# https://stackoverflow.com/questions/41125909
# determine line start : up point doesn't have matching value in down point list
lineStart = np.setdiff1d(up,do)
# determine line end : down point doesn't have matching value in up point list
lineEnd = np.setdiff1d(do,up)
updateDict = {}
for ln in lineStart:
# print "New line: {}".format(ln)
seg_order = 1
# key, next point, oid, line_seg, seg_order
# print "\t{}\t{}\t{}\t{}\t{}".format(ln, valueDict[ln][0],valueDict[ln][1], ln, seg_order)
updateDict[valueDict[ln][1]] = (ln, valueDict[ln][0], ln, seg_order)
pt_next = valueDict[ln][0]
while True:
next_pt = pt_next
seg_order += 1
# print "\t{}\t{}\t{}\t{}\t{}".format(next_pt, valueDict[next_pt][0],valueDict[next_pt][1], ln, seg_order)
updateDict[valueDict[next_pt][1]] = (next_pt, valueDict[next_pt][0], ln, seg_order)
pt_next = valueDict[next_pt][0]
if valueDict[next_pt][0] in lineEnd:
break
print # for debugging
print "OID\tUP\tDOWN\tLINE\tSEGMENT"
for k in sorted(updateDict):
print "{}\t{}\t{}\t{}\t{}".format( k, updateDict[k][0],updateDict[k][1],updateDict[k][2],updateDict[k][3])
with arcpy.da.UpdateCursor(sourceFC, updateFields) as cursor:
for row in cursor:
row[1] = updateDict[row[0]][2] # line segment (starting point's JOINT___UP value)
row[2] = updateDict[row[0]][3] # segment order
cursor.updateRow(row) This will update the feature with a line segment name and a segment order. From there you should be able to use the Points to Line tool. PointsToLine_management (Input_Features, Output_Feature_Class, {Line_Field}, {Sort_Field}, {Close_Line}) Hope this helps. UPDATE: The while block (lines 35-42 above) should be replaced with the following code. A line segment with only one point (because of a data entry error) would cause an error. while pt_next not in lineEnd:
next_pt = pt_next
seg_order += 1
# print "\t{}\t{}\t{}\t{}\t{}".format(next_pt, valueDict[next_pt][0],valueDict[next_pt][1], ln, seg_order)
updateDict[valueDict[next_pt][1]] = (next_pt, valueDict[next_pt][0], ln, seg_order)
pt_next = valueDict[next_pt][0] Additionally, because of some issues with data entry errors, it is possible to not have a dictionary key for some rows. The code below (replacing lines 49-53 above) will print a warning message when a KeyError is encountered. with arcpy.da.UpdateCursor(sourceFC, updateFields) as cursor:
for row in cursor:
try:
row[1] = updateDict[row[0]][2] # line segment (starting point's JOINT___UP value)
row[2] = updateDict[row[0]][3] # segment order
cursor.updateRow(row)
except KeyError:
print "Unable to process row: {}".format(row[0])
row[1] = 'ERROR'
row[2] = -1
cursor.updateRow(row)
... View more
02-14-2019
11:32 PM
|
2
|
4
|
3918
|
|
POST
|
To assist in my understanding your question... I am assuming the number in the up/down fields does not refer in any way to the OID. Could you explain the meaning of data such as L-60 and L-24A? Would these be line start/stop? Also, 630A and 666C? Would these be points used in multiple lines? Or would a line go L-60, 630A, 666C, 635, L-24A? And the next L-24A, 1083 ...etc?
... View more
02-14-2019
12:50 PM
|
0
|
1
|
3918
|
|
POST
|
This thread may give you some ideas: Is it possible to use a field for the filename of an attachment export?
... View more
02-13-2019
02:10 PM
|
0
|
0
|
1448
|
|
POST
|
On occasion, I've used a conversion dictionary as a "hammer": conversion = {
u"\u2019": "'", # apostrophe
u"\u201c": "\"", # double quote
u"\u00a0": " ", # non breaking space
"\n" : "=>" # newline
}
def convert(data):
for k, v in conversion.items():
# https://stackoverflow.com/questions/14156473
data = data.replace(k,v)
return data.encode('ascii')
print convert("hello\nworld" )
# hello=>world
print convert(u"hello \u201cworld\u201c" )
# hello "world"
... View more
02-12-2019
05:01 PM
|
1
|
1
|
6683
|
|
POST
|
Since you are using 10.1, I experimented with SelectLayerByAttributes. I found it easiest to code to work with one geodatabase (the one in your zip file). I first ran a script to get a list of the unique attributes used in the DRAWING_REFERENCE fields of all the features in the gdb. Since the drawing reference is rather long, I paired it with a shorter substring. This is what the gdb looks like in catalog: Each feature is appended with the short substring; in this case, GF is highlighted. Here's the code: import arcpy
import os
gdb = r'C:\Path\to\COBW_Firealarm.gdb'
arcpy.env.workspace = gdb # needed for ListDatasets
fields = ['DRAWING_REFERENCE']
draw_ref = [ # unique values in DRAWING_REFERENCE fields, name append value
[ '111-111-AP','AP' ],
[ 'C0500-GS-0117-04-EL-FA-A0-01-001-001', '01' ],
[ 'C0500-GS-0117-04-EL-FA-A0-02-001-001', '02' ],
[ 'C0500-GS-0117-01-EL-FA-A0-03-001-001', '03' ],
[ 'C0500-GS-0117-04-EL-FA-A0-04-001-001', '04' ],
[ 'C0500-GS-0117-04-EL-FA-A0-05-001-001', '05' ],
[ 'C0500-GS-0117-04-EL-FA-A0-06-001-001', '06' ],
[ 'C0500-GS-0117-01-EL-FA-A0-B1-001-001', 'B1' ],
[ 'C0500-GS-0117-04-EL-FA-A0-B2-001-001', 'B2' ],
[ 'C0500-GS-0117-04-EL-FA-A0-GF-001-001', 'GF' ]
] # name append keeps feature name from becoming too long
for fds in arcpy.ListDatasets('','Feature'):
print "\nProcessing {}".format(fds)
for fc in arcpy.ListFeatureClasses('','',fds):
print "\t{}".format(fc) # use fc for name of target geodatabase
in_fc = os.path.join(gdb,fds,fc)
if arcpy.Exists('temp_layer'):
arcpy.Delete_management('temp_layer')
arcpy.MakeFeatureLayer_management(in_fc,'temp_layer')
ref_num = 0
for dr in draw_ref: # loop through drawing reference list
# dr[0] = DRAWING_REFERENCE field value
# dr[1] = a substring of DRAWING_REFERENCE used in naming new feature class
arcpy.SelectLayerByAttribute_management('temp_layer',
'NEW_SELECTION',
where_clause = "DRAWING_REFERENCE = '{}'".format(dr[0]))
count = int(arcpy.GetCount_management('temp_layer').getOutput(0))
if count > 0:
ref_num += 1
new_fc = os.path.join(fds, "{}_{}".format(fc,dr[1]))
print "\t\t{} -- count: {}".format(new_fc,count)
# write the selected features to a new featureclass
arcpy.CopyFeatures_management('temp_layer', new_fc)
print "\t\t{} total new features".format(ref_num)
arcpy.Delete_management('temp_layer')
print "\nDone." For the next steps, you can use a script to loop through the draw_ref list, making a copy the first gdb, deleting the features that don't match the current value in the draw_ref list, and repeat until each drawing reference has its own gdb. Hope this helps.
... View more
02-08-2019
10:08 PM
|
1
|
1
|
6804
|
|
POST
|
For Desktop 10.3-10.6 versions: Apply Symbology From Layer
... View more
02-08-2019
05:26 PM
|
1
|
1
|
3412
|
|
POST
|
Sounds like you've got reading text files worked out. Since it's for an assignment, this thread Reprojecting tabular data without creating feature class might be of interest. In one of my comments, I shared a bit of code that takes a list of xy coordinates and uses an insert cursor to make a table. It could give you some ideas. And another old thread: geometry help w/ da.InsertCursor.
... View more
02-08-2019
04:45 PM
|
1
|
1
|
3725
|
|
POST
|
My first thought would be bad or missing geometry. When you login to your account and go to the layer via my content, when you click on the data tab, do you see any of the attributes in the table?
... View more
02-06-2019
12:52 PM
|
0
|
0
|
2015
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
07:13 PM
|