|
POST
|
This post has been on my mind for a while, and here's what I came up with. I suspect it's quite similar to Wes' previously posted solution, but works for all license levels: >>> import os
... fc = "myLines"
... sr = arcpy.Describe(fc).spatialReference
... radius = 50
... out_fc = r'in_memory\points'
... int_pt = r'in_memory\int_pt'
... arcpy.Intersect_analysis(fc,int_pt,output_type='POINT')
... diss_int_pt = r'in_memory\diss_int_pt'
... arcpy.Dissolve_management(int_pt,diss_int_pt,'#',[["FID","MIN"]],"SINGLE_PART")
... buff = r'in_memory\buff'
... arcpy.Buffer_analysis(diss_int_pt,buff,str(radius) + ' METERS')
... buff_line_int = r'in_memory\buff_line_int'
... arcpy.Intersect_analysis([buff,fc],buff_line_int,output_type='POINT')
... sing_buff_line_int = r'in_memory\sing_buff_line_int'
... arcpy.MultipartToSinglepart_management(buff_line_int,sing_buff_line_int)
... new_points = {}
... with arcpy.da.SearchCursor(diss_int_pt,['OID@','SHAPE@'],spatial_reference=sr) as cursor1:
... for row1 in cursor1:
... cent_pt = row1[1].centroid
... angs = []
... with arcpy.da.SearchCursor(sing_buff_line_int,'SHAPE@','\"FID_buff\" = ' + str(row1[0]),spatial_reference=sr) as cursor2:
... for row2 in cursor2:
... buff_pt = row2[0].centroid
... dx = cent_pt.X - buff_pt.X
... dy = cent_pt.Y - buff_pt.Y
... if dx < 0 and dy <= 0:
... ang = math.degrees(math.atan(abs(dy/dx)))
... if dx <= 0 and dy > 0:
... ang = math.degrees(math.atan(abs(dx/dy))) + 270
... if dx > 0 and dy >= 0:
... ang = math.degrees(math.atan(abs(dy/dx))) + 180
... if dx >= 0 and dy < 0:
... ang = math.degrees(math.atan(abs(dx/dy))) + 90
... angs.append(ang)
... angs.sort()
... for i in range(1,len(angs)):
... mid_ang = ((angs + angs[i-1])/2)
... ang_diff = angs - angs[i-1]
... new_x = cent_pt.X + (radius * math.cos(math.radians(mid_ang)))
... new_y = cent_pt.Y + (radius * math.sin(math.radians(mid_ang)))
... new_point = arcpy.PointGeometry(arcpy.Point(new_x, new_y),sr)
... new_points[str(row1[0]) + '_' + str(i)] = [ang_diff,new_point]
... mid_ang = (((360-angs[-1]) + angs[0])/2) - (360-angs[-1])
... ang_diff = (360-angs[-1]) + angs[0]
... new_x = cent_pt.X + (radius * math.cos(math.radians(mid_ang)))
... new_y = cent_pt.Y + (radius * math.sin(math.radians(mid_ang)))
... new_point = arcpy.PointGeometry(arcpy.Point(new_x, new_y),sr)
... new_points[str(row1[0]) + '_0'] = [ang_diff,new_point]
... arcpy.CreateFeatureclass_management(os.path.dirname(out_fc),os.path.basename(out_fc),'POINT',spatial_reference=sr)
... arcpy.AddField_management(out_fc,'FID_buff',"LONG")
... arcpy.AddField_management(out_fc,'ANGLE',"DOUBLE")
... iCursor = arcpy.da.InsertCursor(out_fc,['SHAPE@','FID_buff','ANGLE'])
... for k,v in new_points.iteritems():
... row = [v[1],k.split('_')[0],v[0]]
... iCursor.insertRow(row)
... View more
02-11-2016
03:07 PM
|
2
|
17
|
5501
|
|
POST
|
If you want the user to specify a single dwg file, do something like the following. GetParameterAsText(0) returns your first parameter in the tool dialog. The return value will be the path to a feature class or layer name of a feature layer. >>> import arcpy, os # import libraries
...
... dwg = arcpy.GetParameterAsText(0) # a dwg file. e.g. 'C:\junk\blahblah.dwg'
...
... gdb_location = r'C:\junk\FILE_GDB.gdb' # path to GDB
... arcpy.env.workspace = gdb_location
... gdb_fcs = arcpy.ListFeatureClasses(feature_type='Polyline') # list of polyline feature classes in GDB
...
... for fc in gdb_fcs: # loop through feature classes
... if dwg[:-4] == fc: # compare the dwg name (minus '.dwg') to the feature class name
... arcpy.Append_management(os.path.join(dwg,'Polyline'),fc,"NO_TEST") # append polyline layer inside dwg to matching feature class
... View more
02-11-2016
01:01 PM
|
0
|
2
|
4125
|
|
POST
|
This would be done in ArcGIS Desktop using the Intersect tool, but I assume you're talking about the JS API, in which case I think you'd use something like the intersect method of a GeometryService (although I don't really use the JS API, so take that with a grain of salt).
... View more
02-11-2016
11:04 AM
|
1
|
1
|
841
|
|
POST
|
If you're only interested in the straight-line 3d distance between points, you can use good-old math to figure it out without 3D Analyst: >>> sr = arcpy.Describe("valley_pt_elev").spatialReference # spatial ref
... with arcpy.da.SearchCursor("valley_pt_elev","SHAPE@",spatial_reference=sr) as sCursor: # get original point geometry
... for sRow in sCursor:
... orig_point = sRow[0].centroid
... with arcpy.da.UpdateCursor("mtn_pnts_elev",["SHAPE@","dist_3d"],spatial_reference=sr) as uCursor: # loop through other points
... for uRow in uCursor:
... point = uRow[0].centroid
... dx = point.X - orig_point.X
... dy = point.Y - orig_point.Y
... dz = point.Z - orig_point.Z
... hor_dist = math.sqrt(math.pow(dx,2) + math.pow(dy,2)) # calculate horizontal distance
... dist_3d = math.sqrt(math.pow(dz,2) + math.pow(hor_dist,2)) # calculate 3d distance
... print(dx,dy,dz,dist_3d,hor_dist,uRow[0].distanceTo(orig_point) )
... uRow[1] = dist_3d
... uCursor.updateRow(uRow) # update 3d distance field
... View more
02-11-2016
10:27 AM
|
0
|
0
|
1548
|
|
POST
|
I'm not sure how to do this in ModelBuilder, but here's a Python script which should do what you're after. >>> import arcpy, os # import libraries
...
... dwg_folder = r'C:\junk' # folder containing dwgs
... arcpy.env.workspace = dwg_folder
... dwg_files = arcpy.ListFiles('*.dwg') # list of dwgs in folder
...
... gdb_location = r'C:\junk\FILE_GDB.gdb' # path to GDB
... arcpy.env.workspace = gdb_location
... gdb_fcs = arcpy.ListFeatureClasses(feature_type='Polyline') # list of polyline feature classes in GDB
...
... for file in dwg_files: # loop through dwgs
... for fc in gdb_fcs: # loop through feature classes
... if file[:-4] == fc: # compare the dwg name (minus '.dwg') to the feature class name
... arcpy.Append_management(os.path.join(file,'Polyline'),fc,"NO_TEST") # append polyline layer inside dwg to matching feature class General equivalences are: - Iterate Files to arcpy.ListFiles() - Iterate Feature Classes to arcpy.ListFeatureClasses - you'll also need inline variable substitution and submodels
... View more
02-10-2016
03:15 PM
|
2
|
6
|
4125
|
|
POST
|
Jeff, you've pretty well described the exact process I linked to... ... perpLines = []
... fc = "line"
... sr = arcpy.Describe(fc).spatialReference
... perpLineSpacing = 1000
... perpLineLength = 1000
... with arcpy.da.SearchCursor(fc,"SHAPE@",spatial_reference=sr) as cursor:
... for row in cursor:
... for part in row[0]: # part = a line array
... for i in range(len(part)):
... if i==0: # first vertex
... perpLineCounter = 0
... else:
... dy = part.Y - part[i-1].Y
... dx = part.X - part[i-1].X
... segmentAngle = math.degrees(math.atan2(dy,dx))
... segmentLength = math.sqrt(math.pow(dy,2)+math.pow(dx,2))
... linesOnSegment = int(segmentLength/perpLineSpacing)
... for line in range(linesOnSegment+1):
... point = row[0].positionAlongLine(perpLineCounter * perpLineSpacing)
... left = arcpy.Point(point.centroid.X - (math.cos(math.radians(segmentAngle-90))*perpLineLength), point.centroid.Y - (math.sin(math.radians(segmentAngle-90))*perpLineLength))
... right = arcpy.Point(point.centroid.X + (math.cos(math.radians(segmentAngle-90))*perpLineLength), point.centroid.Y + (math.sin(math.radians(segmentAngle-90))*perpLineLength))
... perpLines.append(arcpy.Polyline(arcpy.Array([left,right]),sr))
... perpLineCounter += 1
... arcpy.CopyFeatures_management(perpLines ,r'in_memory\lines')
... View more
02-10-2016
11:13 AM
|
1
|
1
|
3079
|
|
POST
|
See this thread for an example. You can ignore the part about constructing perpendicular lines and simply place points.
... View more
02-10-2016
08:44 AM
|
1
|
0
|
3079
|
|
POST
|
Yes, either of those would work, although the OP says he only has geometry for Texas. Either way, the take-home message is: don't bother with Extract by Polygon if Extract by Mask will work.
... View more
02-09-2016
03:38 PM
|
2
|
0
|
3358
|
|
POST
|
I don't see any mention of Extract by Mask, which seems to me the tool to use, to create an output that you can feed into Set Null (or Con) to remove the unwanted parts of the original raster.
... View more
02-09-2016
02:48 PM
|
2
|
4
|
2642
|
|
POST
|
See this help page. Start at Identifying Clusters with Region Group. Basically, Region Group, Extract By Attributes (or Con), Nibble.
... View more
02-09-2016
12:15 PM
|
1
|
0
|
1442
|
|
POST
|
A quick scan of the helps (9.3 vs. 10.3) look like they use the same algorithm, but you should do a thorough look-through, if you haven't.
... View more
02-09-2016
10:59 AM
|
0
|
6
|
2795
|
|
POST
|
Can you provide an image showing the discrepancy? I'm just curious if it's totally different, or some subtle change in the algorithm.
... View more
02-09-2016
10:48 AM
|
0
|
3
|
4727
|
|
BLOG
|
Oh, that's not how interpreted it, but I see how it is. For my two cents, I'd prefer a single answer to require three helpfuls to encourage really solid answers rather than diluting points across three potentially lower quality answers that just happen to get marked as helpful (quality vs. quantity).
... View more
02-09-2016
10:23 AM
|
1
|
0
|
1283
|
|
BLOG
|
Just a note that I don't believe the actual settings have been changed for Helper. For example, the award: And the post:
... View more
02-09-2016
09:44 AM
|
0
|
0
|
1283
|
|
POST
|
I would guess you need a Workspaces Iterator and Feature Classes Iterator (in a submodel), all collected with Collect Values. If you're interested in a Python solution, it can be done in about 5 lines.
... View more
02-09-2016
09:24 AM
|
1
|
0
|
647
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 11-25-2015 01:51 PM | |
| 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 |
| Online Status |
Offline
|
| Date Last Visited |
07-15-2023
12:11 AM
|