|
POST
|
James, Curious, but if you find a good method for doing this can you post it here? I have struggled with finding a replacement for the 'os.P_NOWAIT' option of the os.spawnv method. I use os.P_NOWAIT (instead of os.P_WAIT) to launch multiple instances of slave scripts (that run in python.exe) to, in effect, create a pseudo method of parallel processing. Not being a "real" programmer, I simply rely on the child process writing out messages in a .txt file, and then have set up the master script/process to look for and read the message .txt file evry 10 seconds or so. Anyway, I'd love to update my stuff to use the subprocess module, but really haven't ever found any examples - specifically of launching a subprocess (or many subprocesses) and having the master script not "wait" (e.g. sit there like a dummy) until the subprocess finished. I guess my os.spwanv system works pretty well for me, so I was kinda apathetic about putting to much time into finding a newer replacement. I'd imagine that os.spwanv will not be supported in Python 3.x...
... View more
11-10-2010
08:57 AM
|
0
|
0
|
9090
|
|
POST
|
Per the deleted posts (not sure why they were deleted, as they raised a valid concern): eaub490 = Eric A. rnig490 = Rebbecca N. ckel490 = Christina K. BTW: csny490 = me Eric, Rebbecca, and Christina are all very knowledgeable GIS/Python co-workers that I encouraged to participate in the poll. I am not their supervisor (actually, Eric is my supervisor), so no potential voter bias - just a good ole' fashioned get out the vote effort on my part.
... View more
11-08-2010
03:35 PM
|
0
|
0
|
1054
|
|
POST
|
If you want to use FGDB (apparently no supprt for MAX or MIN SQL statments = lame), here's a way to do it via Python using a reverse sorted dictionary: import arcgisscripting
gp = arcgisscripting.create(9.3)
fc = r"\\snarf\am\workspace\csny490\Buildings.gdb\BldgsToCompare"
parcelDict = {}
oidFieldName = gp.describe(fc).oidfieldname
searchRows = gp.searchcursor(fc)
searchRow = searchRows.next()
while searchRow:
taxLotValue = searchRow.MAPLOTUNIT
buildingAreaValue = searchRow.BLDG_AREA
oidValue = searchRow.getvalue(oidFieldName)
if taxLotValue in parcelDict:
parcelDict[taxLotValue].append([buildingAreaValue,oidValue])
else:
parcelDict[taxLotValue] = [[buildingAreaValue,oidValue]]
searchRow = searchRows.next()
del searchRow, searchRows
sqlString = ""
for parcel in parcelDict:
parcelDict[parcel].sort(reverse=True)
sqlString = sqlString + str(parcelDict[parcel][0][1]) + ","
gp.MakeFeatureLayer_management(fc, "fl", oidFieldName + " in (" + sqlString[:-1] + ")", "", "")
... View more
11-08-2010
12:44 PM
|
1
|
0
|
4547
|
|
POST
|
Whoops - I guess I messed this one up in a few ways: 1) Yes, I meant searchRows = gp.searchcursor(fc) 2) Instead of searchcursor, I'm referring to update and/or insertcursors, as these cursors put locks on databases. The ESRI help can explain it better than I can: http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=968&pid=951&topicname=Cursors_and_locking Basically, the idea is to remove the database locks. In the absence of a .close method, del works mighty fine, and accomplishes the same goal. Some historical perspective: The v9.0 - 9.3.1 GP object model diagrams all referenced a never-implemented .reset() cursor method. Back in the old forum, ESRI got quite a bit of flack for not implementing this. It was assumed that .reset() would work the same as .close().
... View more
11-08-2010
08:33 AM
|
0
|
0
|
2700
|
|
POST
|
Rory, Perhaps if you specified that the "shortest distance line" must pass through the polygon's centroid point (center of gravity), it would be a better description of what you are trying to do? Also, you might have better luck getting a vector-based way to do this if you posted it in the Geoprocessing forum: http://forums.arcgis.com/forums/31-Geoprocessing. Contrary to the name, the "Spatial Analyst" forum is dedicated to raster-based data analysis (not vector-based) using the ESRI "Spatial Analyst" application extension software. The Python-based geoprocessing API gives very easy access to a polygon's constituent vertices (ArcObjects API does as well, but is more complicated to program).
... View more
11-05-2010
09:30 AM
|
0
|
0
|
1841
|
|
POST
|
I think it has to do more with deleting/avoiding database locks than actually deleting objects. For example, this results in an error: searchRows = gp.searchRows(myFC) searchRows = gp.searchRows(myOtherFC) This doesn't: searchRows = gp.searchRows(myFC) searchRows2 = gp.searchRows(myOtherFC) Nor does this: searchRows = gp.searchRows(myFC) del searchRows searchRows = gp.searchRows(myOtherFC)
... View more
11-05-2010
08:28 AM
|
0
|
0
|
2700
|
|
POST
|
Is your "shape" field called "shape"? Sometimes it isn't! Does this code populate values: gp.CalculateField_management(edgeDissolveFC, "ACRES", "!SHAPE.AREA!", "PYTHON", ""); showGpMessage() How about this code: gp.CalculateField_management(edgeDissolveFC, "ACRES", "!" + gp.describe(edgeDissolveFC).shapefieldname + ".AREA@ACRES!", "PYTHON", ""); showGpMessage()
... View more
11-04-2010
04:33 PM
|
0
|
0
|
511
|
|
POST
|
Basically all you do then would be to make the point's x,y coordinate the lower-left coordinate of the fishnet. For example: dsc = gp.describe(dnrMgmtAllFC) #this is a polygon FC that the fishnet must cover
xMin = dsc.extent.xmin #THIS WOULD BE THE X COORDINATE OF YOUR POINT
yMin = dsc.extent.ymin #THIS WOULD BE THE Y COORDINATE OF YOUR POINT
xMax = dsc.extent.xmax
yMax = dsc.extent.ymax
bufferWidth = 1 #Buffer width expands the the extent of the fishnet by that many map units (to make sure it extends past DNR lands a bit)
numberOfRows = 6
numberOfColumns = 6
fishnetLine1FC = fgdbPath + "\\fishnet_line1"
gp.CreateFishnet_management(fishnetLine1FC, str(xMin - bufferWidth) + " " + str(yMin - bufferWidth), str(xMin - bufferWidth) + " " + str(yMin), "0", "0", numberOfRows, numberOfColumns, str(xMax + bufferWidth) + " " + str(yMax + bufferWidth), "NO_LABELS", ""); showGpMessage()
fishnet1FC = fgdbPath + "\\fishnet_poly1"
gp.FeatureToPolygon_management(fishnetLine1FC, fishnet1FC, "", "", ""); showGpMessage()
gp.Delete_management(fishnetLine1FC, ""); showGpMessage()
... View more
11-04-2010
04:25 PM
|
0
|
0
|
454
|
|
POST
|
Yes, be absolutely sure that you delete the objects after you use them, otherwise locks will persist. For example, see the del statement on the last line: #v9.3 code BTW
searchRows = gp.searchcursor(remsoftIdPolygonFC)
searchRow = searchRows.next()
while searchRow:
oidValue = searchRow.OBJECTID
remsoftIdValue = searchRow.REMSOFT_ID
if oidValue not in objectIdToRemsoftIdDict:
objectIdToRemsoftIdDict[oidValue] = remsoftIdValue
if remsoftIdValue not in remsoftIdToObjectIdDict:
remsoftIdToObjectIdDict[remsoftIdValue] = oidValue
searchRow = searchRows.next()
del searchRow, searchRows #VERY IMPORTANT!!!
... View more
11-04-2010
08:47 AM
|
0
|
0
|
2700
|
|
POST
|
Cool! I am in a bit of a crux since I want the new functionality of v10, but for current projects need the (relative) stability and consistency of v9.3. Hmmm.... Guess I'll have to make the leap sooner than latter...
... View more
11-03-2010
09:26 AM
|
0
|
0
|
1054
|
|
POST
|
There's a bunch of ways to do this, but I've found that the (new in v9.3) ESRI "unit keywords" are the easiest. For example (see the @ACRES part): gp.AddField_management(edgeDissolveFC, "ACRES", "DOUBLE", "", "", ""); showGpMessage()
gp.CalculateField_management(edgeDissolveFC, "ACRES", "!SHAPE.AREA@ACRES!", "PYTHON", ""); showGpMessage() For a list of all the keywords: http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?id=1812&pid=1808&topicname=Calculate_Field_(Data_Management) Some advice on using complex expressions in the codeblock thing: Don't do it! Instead, use an updatecursor. The syntax is MUCH easier, especially for complicated things. For example: http://forums.esri.com/Thread.asp?c=93&f=1729&t=262236#806786 Per your last question: Use the CalculateField tool in the Toolbox. The "right-click calculate field tool" in the table GUI does not have the "PYTHON" option (at least in v9.3 it didn't.
... View more
11-03-2010
08:31 AM
|
0
|
0
|
2884
|
|
POST
|
How about somthing like: fieldInfoList = [["FIELD1", "LONG"],["FIELD2", "TEXT", "30"],["FIELD3", "DOUBLE"]]
for fieldInfo in fieldInfoList:
if fieldInfo[1] in ("LONG","SHORT","DOUBLE","FLOAT"):
gp.AddField_management (layer, fieldInfo[0], fieldInfo[1])
elif fieldInfo[1] == "TEXT":
gp.AddField_management (layer, fieldInfo[0], fieldInfo[1], "", "", fieldInfo[2])
else:
print "Uh oh!"
... View more
11-02-2010
02:33 PM
|
0
|
0
|
1064
|
|
POST
|
How about: fieldInfoList = [["FIELD1", "LONG"],["FIELD2", "TEXT", "30"],["FIELD3", "DOUBLE"]] for fieldInfo in fieldInfoList: if fieldInfo[1] in ("LONG","SHORT","DOUBLE","FLOAT"): gp.AddField_management (layer, fieldInfo[0], fieldInfo[1]) elif fieldInfo[1] == "TEXT": gp.AddField_management (layer, fieldInfo[0], fieldInfo[1], "", "", fieldInfo[2]) else: print "Uh oh!"
... View more
11-02-2010
02:32 PM
|
0
|
0
|
1064
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 03-25-2014 12:57 PM | |
| 1 | 08-29-2024 08:23 AM | |
| 1 | 08-29-2024 08:21 AM | |
| 1 | 02-13-2012 09:06 AM | |
| 2 | 10-05-2010 07:50 PM |
| Online Status |
Offline
|
| Date Last Visited |
08-30-2024
12:25 AM
|