|
POST
|
Select By Location, using property polygons as target layer and orchards as source layer, intersect as selection method. These are the properties that do have an orchard. To get those that do not, switch the selection.
... View more
10-20-2014
02:36 PM
|
1
|
0
|
1515
|
|
POST
|
Richard, the units for positionAlongLine are determined by the spatial reference of the Polyline object. For example, the following snippet places a point 1000 feet from the start of the line, because "kentucky_line" uses the Kentucky State Plane US Feet projection:
>>> for row in arcpy.da.SearchCursor("kentucky_line", ["SHAPE@"]):
... point = row[0].positionAlongLine(1000)
>>> arcpy.CopyFeatures_management(point, 'in_memory\point')
... View more
10-20-2014
02:08 PM
|
0
|
2
|
2984
|
|
POST
|
If your boundary polygons are topologically correct (i.e. if the boundaries fall exactly on each other), you can run the Intersect tool with boundaries as the only input and Output Type = Line to get shared edges, then select by location "are within a distance of the source layer feature" to the shared edges.
... View more
10-20-2014
01:33 PM
|
2
|
1
|
2494
|
|
POST
|
Josh, positionAlongLine defaults to using an absolute distance. If you want to use a percentage, you would change the optional second parameter to True (I think). Richard, this is clearly just one method, and for me using Python geometry objects is more flexible than finding the fastest pre-made tool. IMHO, it also directly answers the question, "how do I create points along a polyline based on distance," better than "read the help on Linear Referencing".
... View more
10-20-2014
10:56 AM
|
0
|
1
|
4607
|
|
POST
|
Back to the original question, you can fairly easily place a point along a line at a feature-specific distance using arcpy geometry objects - specifically, the positionAlongLine method in the Polyline object. positionAlongLine (value, {use_percentage}) Returns a point on a line at a specified distance from the beginning of the line.
... View more
10-17-2014
03:22 PM
|
1
|
4
|
4607
|
|
POST
|
Along the lines of Vince's suggestion, here is a python script that goes most of the way there. The script below is a python script tool - change polyFC and outBuffs to file paths of your choice. The algorithm is more coarse than what Vince suggests - it merely shrinks the buffers by the distance specified in the increment variable, until it passes the threshold specified in the testPercent variable. The use of geometry objects allows for buffers on a feature by feature basis.
# import libraries
import arcpy
# set input/output parameters
polyFC = arcpy.GetParameterAsText(0) # input polygons
outBuffs = arcpy.GetParameterAsText(1) # output interior buffers
# percentage of interest
testPercent = 0.35
# increment to shrink buffers
increment = -0.1 # e.g. 10cm
# buffers container
buffs = []
def negBuff(geom, dist, origArea):
# apply negative buffer
buffGeom = geom.buffer(dist)
buffArea = buffGeom.area
# test against percentage of interest
# if less than percentage, add to array
# if not, increase buffer and try again
if buffArea/origArea < testPercent:
buffs.append(buffGeom)
pass
else:
negBuff(geom, dist + increment, origArea)
for row in arcpy.da.SearchCursor(polyFC, ["SHAPE@"]):
# calculate original area
origArea = row[0].area
# run buffers
negBuff(row[0], increment, origArea)
# persist geometry objects
arcpy.CopyFeatures_management(buffs, outBuffs)
... View more
10-17-2014
02:55 PM
|
1
|
0
|
1589
|
|
POST
|
You could make 8 copies of your raster (Copy Raster), position each one to surround your original raster using the Shift tool, mosaic these 9 raster together (Mosaic to New Raster), and run Focal Statistics on this new raster. Finally, clip out the original raster using the method of your choice (Con, perhaps).
... View more
10-17-2014
09:21 AM
|
1
|
0
|
1244
|
|
POST
|
My personal opinion is that if you don't have a reason to use a geodatabase, don't. There are many special reasons to use GDBs (domains, networks, etc.), but the hassles of sharing data with unknown users (with unknown ArcGIS version, or none at all) is prohibitive for me.
... View more
10-16-2014
11:00 AM
|
0
|
0
|
4410
|
|
POST
|
As Owen alludes to, make sure your data is first defined correctly (according to the original data) and then projected properly, if necessary. See this Knowledge Base article: When do I define a projection, and when do I project data?
... View more
10-15-2014
03:27 PM
|
2
|
0
|
2088
|
|
POST
|
You should be able to use Tool Validation for this. Also, see here for a working example, employing an arcpy.da.SearchCursor.
... View more
09-25-2014
11:03 PM
|
2
|
0
|
1048
|
|
POST
|
Thank you! It goes to show that taking a step back can lend some clarity. In the end, I had misdiagnosed my problem, but your example definitely helped. The problem was in how I was re-writing the geometry. The major difference in my working script (below) and yours is that mine takes along all (an unknown number) of fields and writes them to the new geometry. I had been assigning the row[0].centroid coordinates to the SHAPE@XY token, but it was later overwritten by the shape value coming in with all fields ('*'). At least, I think that's what was going on...
# import libraries
import arcpy, os
# set input/output parameters
polyFC = arcpy.GetParameterAsText(0)
outCentroids = arcpy.GetParameterAsText(1)
# set overwrite environment
arcpy.env.overwriteOutput = True
# if the output file does not exist, create it. Add "ORIG_ID" field.
if not arcpy.Exists(outCentroids):
arcpy.CreateFeatureclass_management(os.path.dirname(outCentroids),
os.path.basename(outCentroids),
"POINT",
polyFC,
"",
"",
polyFC)
arcpy.AddField_management(outCentroids,'ORIG_ID', 'LONG')
# create an InsertCursor containing all the fields in ourCentroids, which are all the fields in polyFC plus "ORIG_ID"
cursor = arcpy.da.InsertCursor(outCentroids, ['*'])
# read all features in polyFC
for row in arcpy.da.SearchCursor(polyFC, ["SHAPE@",'*','OID@']):
# create an array to hold a new, modified row
rowArray = []
# read all the fields except "SHAPE@"
for fieldnum in range(1,len(row)):
# if this is the second field [i.e. SHAPE], replace it with the centroid coordinates
if fieldnum == 2:
rowArray.append(row[0].centroid)
else:
rowArray.append(row[fieldnum])
# write the new row to the cursor
cursor.insertRow(rowArray)
del row
... View more
09-17-2014
04:55 PM
|
1
|
0
|
9572
|
|
POST
|
Thanks, Dan, although I'm reading the exact same help files. ...and I get the same result for centroid, trueCentroid, and labelPoint. I'll admit I am not fully comfortable accessing geomtries with tokens - could this be the source of the issue? I've produced the same result (centroid outside of polygons) with both SHAPE@ and SHAPE@XY.
... View more
09-17-2014
02:39 PM
|
0
|
1
|
9572
|
|
POST
|
Thanks for the replies, but still "no." It is my understanding that "centroid" is supposed to return the labelPoint in the event that the first returned point does not fall inside the polygon. Here is the updated, still not working, code:
# import libraries
import arcpy, os
# set input/output parameters
polyFC = arcpy.GetParameterAsText(0)
outCentroids = arcpy.GetParameterAsText(1)
# set overwrite environment
arcpy.env.overwriteOutput = True
# if the output file does not exist, create it. Add "ORIG_ID" field.
if not arcpy.Exists(outCentroids):
arcpy.CreateFeatureclass_management(os.path.dirname(outCentroids),
os.path.basename(outCentroids),
"POINT",
polyFC,
"",
"",
polyFC)
arcpy.AddField_management(outCentroids,'ORIG_ID', 'LONG')
# collect all of the polygon centroids into an array
pointArray = []
for row in arcpy.da.SearchCursor(polyFC, ["SHAPE@",'*','OID@']):
rowArray = []
rowArray.append(row[0].labelPoint)
for field in range(1,len(row)):
rowArray.append(row[field])
pointArray.append(rowArray)
del row
# write the centroids to the output file
cursor = arcpy.da.InsertCursor(outCentroids, ["SHAPE@",'*'])
for point in pointArray:
arcpy.AddMessage(point)
cursor.insertRow(point)
del cursor
... View more
09-17-2014
02:22 PM
|
0
|
6
|
9572
|
|
POST
|
I am attempting to make a script tool that takes polygon input, and outputs centroid point (within the polygon). This knowledge base article seems to be incorrect, in that the SHAPE@XY token returns the center of gravity for the polygon, not the centroid within the polygon. Likewise, the centroid property in the Polygon class, used in the code below, returns the center of gravity rather than centroid within polygon. Any ideas?
# import libraries
import arcpy, os
# set input/output parameters
polyFC = arcpy.GetParameterAsText(0)
outCentroids = arcpy.GetParameterAsText(1)
# set overwrite environment
arcpy.env.overwriteOutput = True
# if the output file does not exist, create it. Add "ORIG_ID" field.
if not arcpy.Exists(outCentroids):
arcpy.CreateFeatureclass_management(os.path.dirname(outCentroids),
os.path.basename(outCentroids),
"POINT",
polyFC,
"",
"",
polyFC)
arcpy.AddField_management(outCentroids,'ORIG_ID', 'LONG')
# collect all of the polygon centroids into an array
pointArray = []
for row in arcpy.da.SearchCursor(polyFC, ["SHAPE@",'*','OID@']):
rowArray = []
rowArray.append(row[0].centroid)
for field in range(1,len(row)):
rowArray.append(row[field])
pointArray.append(rowArray)
del row
# write the centroids to the output file
cursor = arcpy.da.InsertCursor(outCentroids, ["SHAPE@",'*'])
for point in pointArray:
arcpy.AddMessage(point)
cursor.insertRow(point)
del cursor
Example output below:
... View more
09-17-2014
02:00 PM
|
0
|
9
|
20191
|
|
POST
|
The zoom in/out tools are greyed out because those are the layout zoom in/out tools, on the Layout Toolbar. They only work in layout view. Somehow, your Tools Toolbar has been removed (it has the normal zoom in/out tools, as well as the measure tool). To add it again, right click an empty spot in the toolbar area and choose "Tools".
... View more
09-16-2014
02:27 PM
|
1
|
1
|
3989
|
| 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
|