|
POST
|
I see this thread is quite old and I don't know that the da module existed at the time, but here's how you can currently tackle this problem with Python, if you're so inclined: >>> lines = 'lines_dw'
... sr = arcpy.Describe(lines).spatialReference
... points = {}
... PID = 0
... with arcpy.da.SearchCursor(lines,'SHAPE@',spatial_reference=sr) as cursor:
... for row in cursor:
... for part in row[0]:
... for i in range(len(part)):
... if not part.equals(row[0].lastPoint):
... PID += 1
... dx = part.X - part[i+1].X
... dy = part.Y - part[i+1].Y
... if dx > 0 and dy >= 0:
... angle = math.fabs(math.degrees(math.atan(dx/dy))) + 180
... if dx <= 0 and dy > 0:
... angle = math.fabs(math.degrees(math.atan(dy/dx))) + 90
... if dx >= 0 and dy < 0:
... angle = math.fabs(math.degrees(math.atan(dy/dx))) + 270
... if dx < 0 and dy <= 0:
... angle = math.degrees(math.atan(dx/dy))
... points[PID] = [part,angle]
... points_list = [arcpy.PointGeometry(v[0]) for k,v in points.iteritems()]
... arcpy.CopyFeatures_management(points_list,r'in_memory\points')
... arcpy.AddField_management('points','ANGLE',"DOUBLE")
... with arcpy.da.UpdateCursor("points",['OID@','ANGLE']) as cursor:
... for row in cursor:
... row[1] = points[row[0]][1]
... cursor.updateRow(row)
... View more
03-17-2016
04:15 PM
|
0
|
0
|
1291
|
|
POST
|
Here's a quick Python script that will export the DDP page extents. Just copy and paste into the Python window within the mxd. It will create a temporary layer called 'polys', which you could export to disk and use directly as the index layer.: >>> polys = []
... mxd = arcpy.mapping.MapDocument("CURRENT")
... df = arcpy.mapping.ListDataFrames(mxd)[0]
... for pageNum in range(1, mxd.dataDrivenPages.pageCount + 1):
... mxd.dataDrivenPages.currentPageID = pageNum
... extent = df.extent
... polys.append(arcpy.Polygon(arcpy.Array([
... arcpy.Point(extent.XMax,extent.YMax),
... arcpy.Point(extent.XMax,extent.YMin),
... arcpy.Point(extent.XMin,extent.YMin),
... arcpy.Point(extent.XMin,extent.YMax),
... arcpy.Point(extent.XMax,extent.YMax)
... ])))
... arcpy.CopyFeatures_management(polys,r'in_memory\polys') note: this will only work if the DDP pages are not rotated.
... View more
03-17-2016
02:04 PM
|
1
|
1
|
5748
|
|
POST
|
I'll play along. If you're determined to use split to test a string beginning... >>> a = "university of"
... b = "university of pythonia"
... c = "pythonia university of"
... print b.split(a)[0] == '' # if b is split by a, is the first item in the returned list blank?
... print c.split(a)[0] == '' # if c is split by a, is the first item in the returned list blank?
...
True
False
... View more
03-17-2016
01:31 PM
|
0
|
1
|
2530
|
|
POST
|
For your purposes, 'in' should work, however it doesn't guarantee that the string starts with those characters. I'll just point out that there is 'startswith()' that tests string beginnings: >>> a = "university of"
... b = "university of pythonia"
... c = "pythonia university of"
... print b.startswith(a) # does b start with a?
... print c.startswith(a) # does c start with a?
...
True
False or, an alternative using slice notation: >>> a = "university of"
... b = "university of pythonia"
... c = "pythonia university of"
... print b[:len(a)] == a # do the first few items (letters) in b equal a?
... print c[:len(a)] == a # do the first few items (letters) in c equal a?
...
True
False
... View more
03-17-2016
01:12 PM
|
1
|
1
|
2529
|
|
POST
|
If everything uses the same coordinate system, it doesn't matter (like in my example above), but if they use different CRS or you need to make measurements in some way (e.g. distance along line), then you must specify. Here are some ways you can get and set CRS for geometry objects: >>> polys = arcpy.CopyFeatures_management("camps",arcpy.Geometry())
... polyGeom = polys[0]
... poly_sr = polyGeom.spatialReference # get CRS from a geometry
... print poly_sr.name
... points = "proj_point"
... points_sr = arcpy.Describe(points).spatialReference # get CRS from a feature layer
... print points_sr.name
... with arcpy.da.SearchCursor(points,'SHAPE@',spatial_reference=points_sr) as cursor: # set CRS for cursor geometries
... for row in cursor:
... print row[0].within(polyGeom.projectAs(points_sr)) # project geometry to match cursor CRS
...
NAD_1983_UTM_Zone_10N
NAD_1983_BC_Environment_Albers
True
False
... View more
03-16-2016
03:45 PM
|
1
|
1
|
3119
|
|
POST
|
Untested, but it looks like polyGeom is a list of polygons, not a single polygon geometry. Try: ptGeom.within(polyGeom[0]) edit: now tested with two points, one inside, one outside a single polygon >>> polyGeom = arcpy.CopyFeatures_management("camps",arcpy.Geometry())
... print polyGeom
... print type(polyGeom)
... with arcpy.da.SearchCursor("new_point",'SHAPE@') as cursor:
... for row in cursor:
... print row[0].within(polyGeom[0])
...
[<Polygon object at 0x6ee1090[0x6ee1380]>]
<type 'list'>
True
False
... View more
03-16-2016
03:32 PM
|
1
|
3
|
3119
|
|
POST
|
Once this is done I need to update 2 blank fields in one node. One involves copying the item number from one node to the other. And the other update involves inserting a number into a blank field to indicate the node has been paired. Since you're doing this after you've completed your editing, I'm not sure why Spatial Join, which will transfer all the attributes from the old nodes to the intersecting/nearest (?) new nodes, wouldn't take care of this for you.
... View more
03-16-2016
03:09 PM
|
0
|
1
|
2504
|
|
POST
|
If that's a plain old text element, you can control it through the margin setting, which is buried in: Properties -> Change Symbol... -> Edit Symbol... -> Advanced Text tab -> Text Background -> Properties -> Margins
... View more
03-16-2016
02:33 PM
|
1
|
0
|
1625
|
|
POST
|
Ah, I assumed ListFields returned a list of field names, but it returns field objects. See Joshua's answer or the final example here for creating a list of field names from ListFields.
... View more
03-16-2016
02:02 PM
|
1
|
1
|
3511
|
|
POST
|
Are those points outside the polygon from the same feature class? Should the polygon be filled with 25,000+ points? Have you confirmed that the 25,000 selected points aren't and shouldn't be coincident?
... View more
03-16-2016
01:24 PM
|
0
|
0
|
2033
|
|
POST
|
I'll just say that if the makers of FUSION (specifically a forestry toolset) and LASTools (made by a man who can see the matrix) haven't come up with a solution, then I highly doubt any of us are going to just whip one off in Arcpy...
... View more
03-16-2016
01:12 PM
|
0
|
1
|
1291
|
|
POST
|
Right, I believe creating cursors is an expensive operation, so the fewer the better. for dataset in datasetList:
env.workspace = inputgdb + "\\" + dataset
dataset = dataset + "\\"
fcList = arcpy.ListFeatureClasses()
for fc in fcList:
fc = fc +"\\"
fieldList = arcpy.ListFields(fc,["String"])
with arcpy.da.UpdateCursor (fc, fieldList) as cursor:
for row in cursor: # for each row in the feature class
for i in len(row): # for each value in row (i.e. field values)
if row == None:
row = 'TBD'
cursor.updateRow(row)
... View more
03-16-2016
12:42 PM
|
0
|
3
|
3511
|
|
POST
|
You create a list called fieldList, but then try to call a single field (string) called 'fieldList'. Remove the quotes to access the variable fieldList, rather than the string 'fieldList'. edit: actually, if you mean to loop through individual fields in fieldList, then you should direct the cursor to look for field (no quotes). edit 2: rather than cursoring through your feature classes for each string field, you should cursor through each feature class once and inspect the values in row.
... View more
03-16-2016
10:58 AM
|
2
|
7
|
3511
|
|
POST
|
"I feel as though I am doing the job that ESRI QA should be doing, and not being paid." Actually, you (or someone) is paying a good deal of money for that privilege.
... View more
03-15-2016
09:43 PM
|
0
|
0
|
3171
|
|
POST
|
Here's kind of a simple/complex way to do it: dict = {} # make a dictionary
def myFunc(myClass): # this is the function
global dict # specify global
dict[myClass] = dict.get(myClass, 0) + 1 # if the dictionary key for the value exists, add 1 to it. If not, make it 0.
return dict[myClass] # return the value for that key expression: myFunc(!Field_1!) edit: I had a variable named 'class', which may be a reserved word.
... View more
03-15-2016
03:19 PM
|
1
|
0
|
2473
|
| 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
|