|
POST
|
Use a Search Cursor to loop through the grid cells (I assume your grid is a grid of polygons...?) to get the cell's value. Then, inside the loop, incorporate the cell value into a path string, then use that string inside os.mkdir().
... View more
02-23-2012
08:47 AM
|
0
|
0
|
1458
|
|
POST
|
import os
os.mkdir("H:/newfolder") # makes folder "newfolder" on H:
... View more
02-23-2012
07:24 AM
|
0
|
0
|
1458
|
|
POST
|
You need to enclose the field (Item_Name) in double quotes, the string value in single quotes (John's Cabin), definately escape the apostrophe with another one (John''s Cabin), and possibly wrap the whole thing in escaped double quotes. See this page (Chicago examples), and try it yourself in the Select Layer By Attribute toolbox tool expression builder. I would try: qry = "Item_Name" = 'John''s Cabin'
and if that doesn't work:
qry = """ "Item_Name" = 'John''s Cabin' """
... View more
02-10-2012
12:24 PM
|
0
|
0
|
3096
|
|
POST
|
Oh, then you want Erase, which (frustratingly) only comes with ArcInfo license. You can do the same thing with Union first, then Select by Attributes for FID of shapes you want to delete, then delete them. edit: ha! Beat you Richard Fairhurst.
... View more
02-10-2012
11:28 AM
|
0
|
0
|
1976
|
|
POST
|
That follows pretty closely to this example, which apparently works. The only difference is they refresh TOC after ActiveView, which I doubt matters. When you print layer_Path, does it give the approriate path (including .shp)?
... View more
02-10-2012
11:23 AM
|
0
|
0
|
4223
|
|
POST
|
I'd look at this help page. Particularly, the visible property: "Controls the display of a layer. This has the same effect as checking the check box next to the layer in the table of contents in ArcMap. If set to True, the layer will draw; if set to False, the layer will not be drawn. Not all layers support the visible property (for example, restricted Web service layers), so it is good practice to test for this ahead of time using the supports method."
... View more
02-10-2012
06:29 AM
|
0
|
0
|
685
|
|
POST
|
Now, what could be the difference between running this in Model Builder and running as a script? The difference is that the Model Builder -> Script translator hardly ever works exactly right...
... View more
02-07-2012
01:00 PM
|
0
|
0
|
2154
|
|
POST
|
Check out this thread, and this thread for ideas. Personally, I don't trust the method of turning the line vertices into points and measuring those distances, because that assumes the vertices are evenly distributed along the line. But, if you don't care about that, it would be the easiest way to estimate the distance between two lines.
... View more
02-07-2012
09:42 AM
|
0
|
0
|
923
|
|
POST
|
I'm surprised that the first example works - in both examples your output coverage is an undefined variable (ie. you haven't said what either 'lines_cov' or linesCopy_cov' are). Also, are you trying to make a coverage or a shapefile as output (they are different things)?
... View more
02-07-2012
07:11 AM
|
0
|
0
|
2154
|
|
POST
|
I don't know off the top of my head how to do it in Python, but in VBScript you should be able to use the example on this help page (and divide by 7).
... View more
02-03-2012
01:07 PM
|
0
|
0
|
830
|
|
POST
|
I don't know if it's possible to ask for two feature types at once. I'd just run through it twice and then append the results. import arcpy
workspace = "H:/GIS_Data/TEMP.gdb"
arcpy.env.workspace = workspace # set workspace
pointfcs = arcpy.ListFeatureClasses('*', 'POINT') # get the points
polyfcs = arcpy.ListFeatureClasses('*', 'POLYGON') # get the polygons
pointfcs.extend(polyfcs) # smash together
... View more
02-03-2012
11:24 AM
|
1
|
0
|
1385
|
|
POST
|
Check out the example on this page called "Setting a Boolean Variable as a Precondition".
... View more
02-03-2012
11:08 AM
|
0
|
0
|
1709
|
|
POST
|
You might be able to adapt this script to your needs. It makes lines perpendicular to roads (culverts) at given points. import arcpy, math, random
#Read parameters
linefc = arcpy.GetParameterAsText(0) #Roads feature class
pointfc = arcpy.GetParameterAsText(1) #Known stream crossings feature class
linefolder = arcpy.GetParameterAsText(2) #Workspace for culverts output
culvertlen = int(arcpy.GetParameterAsText(3))
#Create intermediate and final feature classes
linefc2 = linefolder + "/culverts" #Culverts file path
pointfc2 = "in_memory/temppoints" #Intermediate, artificial crossings
arcpy.CreateFeatureclass_management("in_memory", "temppoints", "POINT", "#", "#", "#", r"Coordinate Systems/Projected Coordinate Systems/Utm/Nad 1983/NAD 1983 UTM Zone 11N.prj")
arcpy.CreateFeatureclass_management(linefolder, "culverts", "POLYLINE", "#", "#", "#", r"Coordinate Systems/Projected Coordinate Systems/Utm/Nad 1983/NAD 1983 UTM Zone 11N.prj")
#Delete any existing features in culverts or artificial crossings
if arcpy.Exists(pointfc2):
arcpy.DeleteFeatures_management(pointfc2)
if arcpy.Exists(linefc2):
arcpy.DeleteFeatures_management(linefc2)
#Find all crossings within 10m of a road
arcpy.Near_analysis(pointfc, linefc, "10 Meters")
#Find shape field in stream crossing feature class
desc = arcpy.Describe(pointfc)
pointshapefield = desc.ShapeFieldName
#Create search and insert cursors
rows = arcpy.SearchCursor(pointfc)
insrow = arcpy.InsertCursor(pointfc2)
#Enter for loop to create artificial crossings offset within 1m2 from actual crossing points
for row in rows:
#Continue if the crossing is <10m from a road
if row.NEAR_DIST != -1:
feat = row.getValue(pointshapefield)
pnt1 = feat.getPart()
pnt1x = pnt1.X
pnt1y = pnt1.Y
#Offset artificial crossing <=1m in X, <=1m in Y
randomX = random.random()
if randomX%2==0:
randomX = randomX * -1
randomY = random.random()
if randomY%2==0:
randomY = randomY * -1
pnt2x = pnt1.X + randomX
pnt2y = pnt1.Y + randomY
#Insert new point into feature class
feat2 = insrow.newRow()
pnt2 = arcpy.CreateObject("Point")
pnt2.X = pnt2x
pnt2.Y = pnt2y
feat2.shape = pnt2
insrow.insertRow(feat2)
del row
del insrow
del rows
#Calculate angle to nearest road
arcpy.Near_analysis(pointfc2, linefc, "11 Meters", "#", "ANGLE")
#Create search and insert cursors
rows2 = arcpy.SearchCursor(pointfc2)
insrow2 = arcpy.InsertCursor(linefc2)
#Find shape field
desc2 = arcpy.Describe(pointfc2)
#Create array to hold new lines
lineArray = arcpy.CreateObject("Array")
#Enter for loop to create culverts
for row2 in rows2:
feat = row2.getValue(desc2.ShapeFieldName)
pnt1 = feat.getPart()
pnt1rad = math.radians(row2.NEAR_ANGLE)
#Create point at far end of culvert
pnt2 = arcpy.CreateObject("Point")
pnt2.X = (math.cos(pnt1rad) * ((culvertlen/2) + row2.NEAR_DIST)) + pnt1.X
pnt2.Y = (math.sin(pnt1rad) * ((culvertlen/2) + row2.NEAR_DIST)) + pnt1.Y
#Create point at close end of culvert
pnt3 = arcpy.CreateObject("Point")
pnt3.X = (-1*(math.cos(pnt1rad) * ((culvertlen/2) - row2.NEAR_DIST))) + pnt1.X
pnt3.Y = (-1*(math.sin(pnt1rad) * ((culvertlen/2) - row2.NEAR_DIST))) + pnt1.Y
#Put points in array
lineArray.add(pnt3)
lineArray.add(pnt2)
feat3 = insrow2.newRow()
#Connect points and insert into feature class
feat3.shape = lineArray
insrow2.insertRow(feat3)
#Erase points from array for next loop
lineArray.removeAll()
del row2
del insrow2
del rows2
... View more
02-02-2012
10:15 AM
|
0
|
0
|
1440
|
| 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
|