|
POST
|
localRaster = r"C:\temp\test.img" sdeRaster = r"\\mynetwork\temp\mysdefile.sde\test" #You can build a .sde file on the fly using arcpy.CreateDatabaseConnection_management() arcpy.CopyRaster_managment(localRaster, sderaster, "MY_SDE_TABLESPACE")
... View more
05-12-2014
01:21 PM
|
0
|
0
|
340
|
|
POST
|
Does the os.environ command set the temp directory for just the current process? It depends on where and how you call it. As soon as you call it in a script, it will change the variables just for that script... I think. I use the subprocess module to do parallel processing stuff, and rely on a parent script and a child script. In my experience, the child script will inherit the system variables of the parent script (whatever they may be) at the time the child script was called. BTW: time.sleep(1.1) #sleep for 1.1 seconds was designed to keep the folder names unique, since the folders are named with YYYYMMDDHHMMSS format.
... View more
05-12-2014
12:32 PM
|
0
|
0
|
2610
|
|
POST
|
There's 3 ways to do it. I think #1 will be the fastest though... #1
rasterPath = r"C:\temp\test.img"
rstObj = arcpy.Raster(rasterPath)
xmin, ymin, xmax, ymax = rstObj.extent.XMin, rstObj.extent.YMin, rstObj.extent.XMax, rstObj.extent.YMax
#2
rasterPath = r"C:\temp\test.img"
dscObj = arcpy.Describe(rasterPath)
xmin, ymin, xmax, ymax = dsc.extent.XMin, dscObj.extent.YMin, dscObj.extent.XMax, dscObj.extent.YMax
#3
rasterPath = r"C:\temp\test.img"
xmin = float(arcpy.GetRasterProperties_management(raster, "LEFT").getOutput(0))
ymin = float(arcpy.GetRasterProperties_management(raster, "BOTTOM").getOutput(0))
xmax = float(arcpy.GetRasterProperties_management(raster, "RIGHT").getOutput(0))
ymax = float(arcpy.GetRasterProperties_management(raster, "TOP").getOutput(0))
... View more
05-12-2014
09:19 AM
|
0
|
0
|
1429
|
|
POST
|
Try adding this code right before the function/child process is called: import time time.sleep(1.1) #insurance newTempDir = r"C:\temp\gptmpenvr_" + time.strftime('%Y%m%d%H%M%S') os.mkdir(newTempDir) os.environ["TEMP"] = newTempDir os.environ["TMP"] = newTempDir http://forums.esri.com/Thread.asp?c=93&f=1729&t=284041#881375 This is the trick I use to get multiple instances of arcpy (or gp) to run in parallel... Without this: Random crashes due to concurrent processes attempting to write to the same TEMP file(s) at the same time. I use the subprocess module, so this might not (???) work with multiprocessing... Execute this code right before the child process is called, or in the child process, before you import arcpy.
... View more
05-12-2014
08:37 AM
|
0
|
0
|
2610
|
|
POST
|
Some things to try: Make sure the .tbx and script files are accessible via a fast network connection or better yet on your local machine Delete the geoprocessing history. Believe me, this can build up to a surprisingly large amount of file space. These .xml files are stored in: C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcToolbox\History This may be the most effective but be aware all your ArcMap/ArcCatalog settings (toolbars, paths, settings, etc) will go away... Try renaming (or deleting) your normal.mxt and normal.gxt files... These are the template files that control the customizations to ArcMap/Catalog. I make a habit of deleting these every so often when start up performance (ArcMap, ArcCatalog, import arcpy, etc.)goes down. Try just renaming these (they will get auto-recreated) and you will have your back ups in case you need to go back to the originals. These files are located at: C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcMap\Templates and C:\Users\<username>\AppData\Roaming\ESRI\Desktop10.1\ArcCatalog
... View more
05-06-2014
09:11 AM
|
0
|
0
|
560
|
|
POST
|
math.hypot... Cool - I'll have to use that from now on!
... View more
05-06-2014
08:48 AM
|
0
|
0
|
4481
|
|
POST
|
Here's some v10.1+ code that calculates an "aspect ratio" in regards to a poly or line FC's hull rectangle (not the same as extent rectangle BTW)... The variables "distance1" and "distance2" are length and width (depending on which one is the longer distance): arcpy.AddField_management(indxTileSinglePartFC, "ASP_RATIO", "DOUBLE")
updateRows = arcpy.da.UpdateCursor(indxTileSinglePartFC, ["SHAPE@","ASP_RATIO"])
for updateRow in updateRows:
shapeObj = updateRow[0]
x1,y1,x2,y2,x3,y3,x4,y4 = [float(coord) for coord in shapeObj.hullRectangle.split(" ")]
distance1 = math.sqrt((x1 - x2)**2 + (y1 - y2)**2)
distance2 = math.sqrt((x2 - x3)**2 + (y2 - y3)**2)
if distance1 <= distance2:
updateRow[1] = distance2 / distance1
else:
updateRow[1] = distance1 / distance2
updateRows.updateRow(updateRow)
del updateRow, updateRows
... View more
05-06-2014
08:23 AM
|
0
|
0
|
4481
|
|
POST
|
is it possible to read that kind of information from a 'true curve' circle using a search cursor As far as I know, you cannot access the "equation" for true curves via Python. Interestingly enough, I noted that (assuming you are using the code from my example above): >>> circleGeom.getPart(0) #will yield <Array [<Point (2000.0, 2100.0, #, #)>, <Point (2000.0, 2100.0, #, #)>]> But... >>> circleGeom.JSON #(or .WKT) will yield all the densified verticies... u'{"rings":[[[2000,2100],[2003.1099862269837,2099.9516282291988],[2006.216963743148,2099.8065597133595],[2009.3179267484072,2099.564934796902],[2012.4098752613259,2099.2269872363277],[2015.4898180214084,2098.7930439740758],[2018.5547753829494,2098.2635248222264],[2021.6017821976484,2097.6389420563605],[2024.6278906832001,2096.9198999199666],[2027.6301732750831,2096.1070940398727],[2030.6057254587888,2095.201310753273]..... A somewhat related topic: http://forums.arcgis.com/threads/49557-True-Curves-True-Evil
... View more
04-29-2014
10:30 AM
|
0
|
0
|
2801
|
|
POST
|
Are you interested in a "true curve" circle or a "densified" circle? The former will have two verticies (the start/end nodes) and a mathematical equation that describes the line that connects the nodes. The densified circle will have a whole bunch of verticies that in sum approximate a circle. Here's some code that might help.... pntGeom = arcpy.PointGeometry(arcpy.Point(2000, 2000)) #substitute your centroid x/y coordinates circleGeom = pntGeom.buffer(100) #substitute the distance from your circles verticies to the centroid arcpy.CopyFeatures_management(circleGeom, r"C:\temp\test.gdb\test) # copying to a GDB will preserve the "true curve" geometry arcpy.CopyFeatures_management(circleGeom, r"C:\temp\test.shp) # copying to a .shp will force densification
... View more
04-29-2014
08:52 AM
|
0
|
0
|
2801
|
|
POST
|
pntGeom = arcpy.PointGeometry(arcpy.Point(2000, 2500)) circleGeom = pntGeom.buffer(100)
... View more
04-29-2014
08:45 AM
|
0
|
0
|
2801
|
|
POST
|
Since "crime type" is probably a string field, you just need single quotes. So instead of this: storeIdSet = set([r[0] for r in arcpy.da.SearchCursor(myFC, ["STORE_ID"])])
for storeId in storeIdSet:
outFC = r"C:\temp\test.gdb\store_" + str(storeId)
arcpy.Select_analysis(myFC, outFC, "STORE_ID = " + str(storeId)) Do this (difference is in the last line): storeIdSet = set([r[0] for r in arcpy.da.SearchCursor(myFC, ["STORE_ID"])])
for storeId in storeIdSet:
outFC = r"C:\temp\test.gdb\store_" + str(storeId)
arcpy.Select_analysis(myFC, outFC, "STORE_ID = '" + str(storeId) +"'") Mzcoyle formatting stuff also will work... Basically I think you just need to edit the SQL expression so it will deal with string values instead of numbers...
... View more
04-23-2014
09:59 AM
|
0
|
0
|
994
|
|
POST
|
Really, the MakeQueryTable tool is geared around doing complex queries with multiple related tables. If you just want to extract some records to a new on-disk table use the Select_analysis tool. If you want to make a in-memory pointer to some particular records in a table (aka 'a view') use the MakeTableView tool. For example: arcpy.Select_analysis(myInputTblPath, myOutputTblPath, "STATION_ID in ('CAP','DDM')")
#or
arcpy.MakeTableView_management(myInputTblPath, "my_table_view", "STATION_ID in ('CAP','DDM')") BTW: Per my undersatnding, a QueryTable and TableView (and a FeatureLayer as well) do not store the actual records of the table in memory (aka the RAM). Rather they store references to the on-disk records. Basically it builds a hash table of the key fields that satisfy a particular SQL query. Only the keys and their relationships are stored in RAM.
... View more
04-16-2014
05:16 PM
|
0
|
0
|
1751
|
|
POST
|
I like your idea, but Richard is correct: the GenerateNearTable tool should be faster than a recursive SelectByLocation. But... If you were to do it as a SelectByLocation it might look something like this (untested code!): storesFC = r"C:\temp\stores.shp"
trackingDict = {}
maxCount = 0
maxCountStoreId = 0
arcpy.MakeFeatureLayer_managment(storesFC, "stores_fl")
searchRows = arcpy.da.SearchCursor(storesFC, ["OID@", "SHAPE@"])
for searchRow in searchRows:
storeOidValue, storeGeomObj = searchRow[0:2]
arcpy.SelectLayerByLocation_management(storeGeomObj, "WITHIN_A_DISTANCE", "stores_fl", "10 MILES", "NEW_SELECTION")
selectedStoresOidList = [r[0] for r in arcpy.da.SearchCursor("stores_fl", ["OID@"])]
trackingDict[storeOidValue] = selectedStoresOidList
if len(trackingDict[storeOidValue]) > maxCount:
maxCount = len(trackingDict[storeOidValue])
maxCountStoreId = storeOidValue
del searchRow, searchRows
print "Store OID with the largest number of other stores close by is: " + str(maxCountStoreId) + " (" + str(maxCount) + " other stores close by)"
... View more
04-15-2014
02:52 PM
|
0
|
0
|
845
|
|
POST
|
How about: listOfFieldValues = [r[0] for r in arcpy.da.SearchCursor(myTbl, ["FieldA"])] numberOfFieldValues = len(listOfFieldValues) lastFieldValue = listOfFieldValues[-1] secondToLastFieldValue = listOfFieldValues[-2]
... View more
03-28-2014
09:25 AM
|
0
|
0
|
1908
|
|
POST
|
Jason - thanks for the explanation. For the smaller record counts, I too noticed the slight overhead (set up/tear down a GP tool) of the GetCount tool, which is why I started using the cursor method (which didn't seem to have the extra overhead that GetCount does). In my case, I had some code that needed to inspect a recursive feature count hundreds/thousands of times in a loop, and I found the cursor method (because the record count was relatively small) was the best performer (BTW: using the .fidSet describe property was the worse). Per the count of the selected set, you can of course do it like: arcpy.MakeFeatureLayer_management(fc, "fl1")
arcpy.SelectLayerByAttribute_management("fl1", "NEW_SELECTION", "LAND_COVER_CD in (41,42)")
result = len([r[0] for r in arcpy.da.SearchCursor("fl1", ["OID@"])])
#Or this if you don't need an actual "selected set"...
result = len([r[0] for r in arcpy.da.SearchCursor(fc, ["OID@"], "LAND_COVER_CD in (41,42)")])
... View more
03-25-2014
12:57 PM
|
0
|
0
|
2219
|
| Title | Kudos | Posted |
|---|---|---|
| 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 | |
| 1 | 02-08-2012 03:09 PM |
| Online Status |
Offline
|
| Date Last Visited |
08-30-2024
12:25 AM
|