|
POST
|
You should look into the Get Field Value tool, and then use the returned value in the field calculator. Get Field Value—Help | ArcGIS for Desktop
... View more
02-06-2017
11:52 AM
|
0
|
0
|
3567
|
|
POST
|
So, now that you've got rid of the new line character using strip(), you can access it similar to how you were doing it before, using the [2] index: lstFires[0].strip().split(',')[2]
... View more
02-06-2017
10:33 AM
|
1
|
0
|
922
|
|
POST
|
I assume that since you read all lines into the list, setting conField[2] to the third value in each line will ultimately result in the final value of your file, not the field name from the first line. You can access the first line of the file with f.readline() (reads only one line) or f.readlines()[0]. Also, you may be running into a problem if Python is reading a new line character at the end of your line. Try printing the split list to see the new line character: >>> f = open(r'C:\junk\log.txt', 'r')
... my_list = f.readlines()
... print my_list[0]
... print my_list[0].split(',')
...
field1,field2,field3
['field1', 'field2', 'field3\n']
... View more
02-06-2017
09:33 AM
|
0
|
3
|
3649
|
|
POST
|
Start at the following link, get started on your script, and then post it back here when you need more help. What is ArcPy?—ArcPy Get Started | ArcGIS Desktop Basically, figure out the geoprocessing tools you need, find and use the Python syntax on each tool's help page, and then put it in a for loop to repeat. But, first you need to figure out some Python.
... View more
02-05-2017
05:48 PM
|
1
|
5
|
3022
|
|
POST
|
Yes, you could certainly do this with a Python script, looping through rasters, calculating raster centroid from extent, selecting the grid cell covering the centroid, doing the clip.
... View more
02-03-2017
01:24 PM
|
1
|
7
|
3022
|
|
POST
|
Have you tried select (the grid polygon), then clip?
... View more
02-03-2017
11:19 AM
|
2
|
9
|
3022
|
|
POST
|
That's because you've called 'x' what most examples call 'row' (it would normally be more like "for row in cursor:"). It doesn't matter, it's just a variable name, but if you call it 'x', then you need to reference 'x' (i.e. x[0] is the Holding_Reference_Number). Or, you can't set x[0] to row[0], because row doesn't exist. Also, you've got a new error coming up in the select - there's an extra apostrophe right after x[0].
... View more
02-02-2017
06:28 PM
|
2
|
1
|
1446
|
|
POST
|
What's the error message? As it is now, it looks like the line Poyl_name = row[0] is commented out (although I don't see the '#'), so there is no variable called Poyl_name. If it's not commented out, then it's trying to use row[0], while you've already called it x[0].
... View more
02-02-2017
06:10 PM
|
0
|
3
|
1446
|
|
POST
|
I think you can get to it through the field calculator, Python parser, using an expression like: round(!your_field_name!*2,0)/2.0 So, your examples: 2.66 * 2 = 5.32 round(5.32,0) = 5 5 / 2.0 = 2.5 8.76 * 2 = 17.52 round(17.52,0) = 18 18 / 2.0 = 9.0
... View more
02-02-2017
01:45 PM
|
0
|
0
|
867
|
|
POST
|
You can make this more complicated (e.g. input direction, evaluation threshold/precision), but here's a script that will result in approximately 25% polygons: >>> fc = 'recs' # polygon feature class
... sr = arcpy.Describe(fc).spatialReference # get spatial reference
... outpolys = [] # placeholder
... ratio = 25 # 25% polygons
... step = 1 # evaluate every 1%
... with arcpy.da.SearchCursor(fc,'SHAPE@',spatial_reference=sr) as cursor:
... for row in cursor: # loop through polygons
... extent = row[0].extent # get polygon extent
... height = extent.height # get polygon height
... TL = extent.upperLeft # top left corner
... TR = extent.upperRight # top right corner
... for i in range(0,100-ratio,step): # evaluate every scenario from 25-100%
... BY = extent.YMax-((ratio+i)/100.0*height) # get current bottom Y of evaluation polygon
... BR = arcpy.Point(extent.XMax,BY) # bottom right corner
... BL = arcpy.Point(extent.XMin,BY) # bottom left corner
... poly = arcpy.Polygon(arcpy.Array([TL,TR,BR,BL]),sr).intersect(row[0],4) # intersect evaluation polygon with current polygon
... area_ratio = poly.area/row[0].area # calculate area ratio
... if area_ratio*100 >= ratio: # if ratio is >= to threshold
... outpolys.append(poly) # remember the polygon
... break # stop evaluating larger polygons
... arcpy.CopyFeatures_management(outpolys,r'in_memory\outpoly') # write polygons
... View more
02-02-2017
10:45 AM
|
2
|
0
|
2021
|
|
BLOG
|
Couldn't resist. Here's where I got to with an approximation of the randomized Prim's algorithm for maze generation. It's very slow, and my walls_list never actually gets to zero, so I'm pretty sure I've done something wrong. But, it does create a maze, after all. import random
def check_walls(cur_wall, walls_list, cells):
for k,v in cells.iteritems():
intersect = cur_wall.intersect(v[0],2)
if intersect.length > 0 and v[1]==0:
v[1] = 1
arcpy.SelectLayerByLocation_management('walls',"SHARE_A_LINE_SEGMENT_WITH",cur_wall,selection_type="NEW_SELECTION")
arcpy.DeleteFeatures_management('walls')
arcpy.SelectLayerByLocation_management('walls',"SHARE_A_LINE_SEGMENT_WITH",v[0],selection_type="NEW_SELECTION")
walls_list.extend([i[0] for i in arcpy.da.SearchCursor('walls','SHAPE@',spatial_reference=sr)])
for wall in walls_list:
if wall.equals(cur_wall):
walls_list.remove(wall)
return walls_list
fc = 'hex_grid'
sr = arcpy.Describe(fc).spatialReference
cells = {str(i[1]):[i[0],0] for i in arcpy.da.SearchCursor(fc,['SHAPE@','OID@'],spatial_reference=sr)}
cur_cell = cells.keys()[0]
cells[cur_cell][1] = 1
walls = arcpy.Intersect_analysis("hex_grid",r'in_memory\walls',output_type='LINE')
wc = "mod({},2)=0".format(arcpy.AddFieldDelimiters('walls','FID'))
arcpy.SelectLayerByAttribute_management('walls',"NEW_SELECTION",wc)
arcpy.DeleteFeatures_management('walls')
arcpy.SelectLayerByLocation_management('walls',"SHARE_A_LINE_SEGMENT_WITH",cells[cur_cell][0],selection_type="NEW_SELECTION")
walls_list = [i[0] for i in arcpy.da.SearchCursor('walls','SHAPE@',spatial_reference=sr)]
counter = 0
while len(walls_list)>0 and counter < 2000:
random.shuffle(walls_list)
cur_wall = walls_list[0]
counter += 1
walls_list = check_walls(cur_wall, walls_list, cells)
... View more
02-02-2017
09:46 AM
|
0
|
0
|
1484
|
|
BLOG
|
Yes, I think that's about right. I tried to use Prim's algorithm, but not 100% sure it's right. At each step, you need to find the next nearest non-tree point, which as you noticed, causes the calculations increase exponentially. The nice thing about numpy is that some smart person came up with a much faster way to do these types of huge combinational calculations. I think Dan made his own version (_e_dist function), but you can also look into the scipy pdist function to make your distance matrices.
... View more
02-02-2017
09:40 AM
|
0
|
0
|
1484
|
|
BLOG
|
Thanks for sharing, Dan. It probably doesn't have the performance of numpy, but here's my try at simplifying it in terms of arcpy: def addToTree(F,Q,sr):
min_dist = float("inf") # set to infinity
for fk,fv in F.iteritems(): # loop through tree vertices
for qk,qv in Q.iteritems(): # loop through non-tree vertices
dist = fv['G'].distanceTo(qv['G']) # calculate distance
if dist < min_dist: # if distance is less than current minimum, remember
fk_fv_qk_qv = [fk,fv['G'],qk,qv['G']]
min_dist = dist
F[fk_fv_qk_qv[2]] = {'G': fk_fv_qk_qv[3]} # add to tree vertices
del Q[fk_fv_qk_qv[2]] # delete from non-tree vertices
return arcpy.Polyline(arcpy.Array([fk_fv_qk_qv[1].centroid,fk_fv_qk_qv[3].centroid]),sr) # return new line
fc = 'points' # points feature class
sr = arcpy.Describe(fc).spatialReference # spatial ref
Q = {str(i[0]):{'G':i[1]} for i in arcpy.da.SearchCursor(fc,['OID@','SHAPE@'],spatial_reference=sr)} # non-tree vertices
F = {} # empty tree vertices
lines = [] # placeholder for lines
q_cur = Q.keys()[0] # get first non-tree vertex
F[q_cur] = Q[q_cur] # transfer to tree vertices
del Q[q_cur] # delete from non-tree vertices
while len(Q)>0: # do until all non-tree vertices assigned to tree
output = addToTree(F,Q,sr) # add a vertex via function
lines.append(output) # remember line
arcpy.CopyFeatures_management(lines,r'in_memory\lines') # write lines
... View more
01-31-2017
04:22 PM
|
1
|
0
|
1484
|
|
POST
|
I took it to mean "the feature layer with a selected feature" not "the selected feature layer".
... View more
01-31-2017
03:40 PM
|
0
|
2
|
6117
|
|
POST
|
You can use Zonal Statistics as Table and join it back to the original polygons. If it's an integer type, you could also Build Raster Attribute Table of the result of Zonal Statistics, and join that.
... View more
01-31-2017
01:43 PM
|
2
|
1
|
1821
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-30-2013 02:22 PM | |
| 1 | 04-12-2011 11:19 AM | |
| 1 | 09-17-2021 09:43 AM | |
| 1 | 04-04-2012 12:05 PM | |
| 2 | 07-16-2020 11:31 AM |
| Online Status |
Offline
|
| Date Last Visited |
07-15-2023
12:11 AM
|