|
POST
|
OK all, Here is a tough one. I've written some VBA (because pythons method of spawning sub-processes meant my code was going to take 62 days...) and I've noticed the memory usage just keeps on creeping up. At one point I use the geoprocessor to call the Select Tool to create a new shapefile containing 1 point (Which is then used as a pour point for catchment generation) I create and set the geoprocessor as such:
Set pGP = New GeoProcessor
With pGP
.OverwriteOutput = True
.AddOutputsToMap = False
.LogHistory = False
.TemporaryMapLayers = True
End With I call the tool as such:
query = Chr(34) & "ID" & Chr(34) & " = " & CStr(ID)
With pVA
.RemoveAll
.Add pFeatureLayer_Sites.FeatureClass
.Add "in_memory\tempSP"
.Add query
End With
pStatusbar.Message(0) = "Extracting a single site to in_memory"
Set pGPR = pGP.Execute("Select", pVA, Nothing)
Set pFeatureClass = pGPUtils.OpenFeatureClassFromString(pGPR.GetOutput(0).GetAsText)
Set pGeoDataSetPP = pFeatureClass I release the memory as such:
With pGPUtils
.RemoveInternalLayer "tempSP"
.ClearInMemoryWorkspace
.RemoveInternalData
.ReleaseInternals
End With and I even kill off the geoprocessor within the loop as such:
Set pGP = Nothing
pGPUtils.ReleaseInternals In Arcmap Tools > options: Log geoprocessing is ticked off, results are temporary and results management is set to "Never Save" So at all stages I say NO results, NO logging yet the Select tool still adds an entry in the ArcToolbox results Tab which overtime consumes memory. I need to run this tool a lot of times for a long time but I just can't make ArcMap not Log a result! Any ideas, any undocumented tips or is this a bug? Duncan
... View more
09-01-2010
10:22 AM
|
0
|
2
|
583
|
|
POST
|
Hi Chris, Thanks for the top tip, I will transfer my point layer to a shapefile to see if I can fix this problem. The more I delve into Python the more I find my self begging ESRI not to drop VBA at least that works without quirky problems. I've not been writing the rasters to a Geodatabase, I've never been a fan of that ;). Duncan
... View more
08-09-2010
11:44 AM
|
0
|
0
|
619
|
|
POST
|
All, Below is a python script I developed for extracting out elevation information for a point dataset. Basically it gets a list of ID's from a table (the barrier ID table) then for each ID is selects 2 points from a point Featureclass, it then snaps them to the flow accumulation grid, extracts the values and writes the min and max value to an output table. The code runs fine but eventually crashes after 3 or 4 hours. I then have to compact the personal geodatabase and restart the code from the point it crashed. What I've noticed is that the personal geodatabase just keeps on getting bigger until it hits the 2GB limit (hence the code failing). So my question to all you python gurus is how do I change my code to stop this annoying behaviour? I tried putting a "compact" in every 500th ID but it comes up with an error. '''
Description: Extracts the minimum and maximum DEM values for each barriers
upstream and downstream limit
Constraints: Designed to work only in the 9.3 ArcGIS system.
Author: Duncan Hornby
Email: ddh@geodata.soton.ac.uk
Created: 6/8/2010
'''
# Import system modules
import sys, arcgisscripting
# Create the Geoprocessor object & set any environment settings
gp = arcgisscripting.create(9.3)
gp.SetProduct("ArcView")
gp.CheckOutExtension("Spatial")
gp.Workspace = "c:\\temp\\"
gp.cellSize = "50"
gp.OverWriteOutput = 1
# Set any objects and variables
tempRaster = "snapIntPnt"
tempRaster2 = "ExtDEM"
tempLayer = "tempPointLayer.shp"
pgd = "G:\LiveData\UC1168_Sediment_WQ0128\Vector\pGDB93_UC1168_Output.mdb"
# Get parameters
BarrierIDTable = gp.GetParameterAsText(0)
IntersectionPointLayer = gp.GetParameterAsText(1)
FlowAccum = gp.GetParameterAsText(2)
DEM = gp.GetParameterAsText(3)
Output = gp.GetParameterAsText(4)
gp.SnapRaster = FlowAccum
# Create a cursor over the barrier ID table
rows = gp.SearchCursor(BarrierIDTable,"","","OBSTRUCTID","")
row = rows.next()
# Iterate through the rows in the cursor
while row:
# Get barrier ID
bID = row.GetValue("OBSTRUCTID")
## # Check to see if we should compact the geodatabase at every 500th
## if bID%500 == 0:
## gp.AddWarning("Compacting GeoDatabase...")
## gp.Compact_management(pgd)
gp.AddMessage("Processing Barrier: " + str(bID))
# Select all the intersection points that belong to this barrier
gp.SetProgressorLabel("Selecting intersection points...")
gp.SelectLayerByAttribute_management(IntersectionPointLayer,"NEW_SELECTION","[OBSTRUCTID] = " + str(bID) + " AND [UseAsSlopeLimit] = 'Y'")
# Convert selection to a layer so we can get an extent
gp.SetProgressorLabel("Getting extent of selection...")
gp.CopyFeatures_management(IntersectionPointLayer,tempLayer)
obj = gp.Describe(tempLayer)
gp.Extent = obj.Extent
del obj # Destroy object
# Snap selected points to flow accumulation grid
gp.SetProgressorLabel("Snapping selected points to flow accumulation grid...")
gp.SnapPourPoint_sa(IntersectionPointLayer,FlowAccum,tempRaster,"25","OBSTRUCTID")
# Now extract the DEM values from the pre-prepared raster layer
gp.SetProgressorLabel("Extracting DEM cells...")
gp.ExtractByMask_sa(DEM,tempRaster,tempRaster2)
# Extract the properties from this raster
gp.SetProgressorLabel("Reading raster properties...")
resultObj = gp.GetRasterProperties_management(tempRaster2,"MINIMUM")
zMin = resultObj.GetOutput(0)
resultObj = gp.GetRasterProperties_management(tempRaster2,"MAXIMUM")
zMax = resultObj.GetOutput(0)
gp.AddMessage("Elevation - Min:" + str(zMin) + " , Max: " + str(zMax))
del resultObj # Destroy object
# Write data to output table
gp.SetProgressorLabel("Updating output table...")
InsertRows = gp.InsertCursor(Output) # Create insert cursor for table
aNewRow = InsertRows.NewRow()
aNewRow.SetValue("OBSTRUCTID",bID)
aNewRow.SetValue("MinEle",zMin)
aNewRow.SetValue("MaxEle",zMax)
InsertRows.InsertRow(aNewRow)
InsertRows.Reset()
del aNewRow # Destroy object
del InsertRows # Destroy object
# Get next Barrier ID
row = rows.next()
# Return extension license
gp.CheckInExtension("Spatial")
... View more
08-09-2010
08:26 AM
|
0
|
2
|
1097
|
|
POST
|
Reginald, There are several free tools that will answer your question. Get into the habitat of checking out ArcScripts where other users have put up their tools for free. Goto here: arcscripts.esri.com and type in "nearest point" You'll be amazed whats up on this web site. Duncan
... View more
08-03-2010
08:26 AM
|
0
|
0
|
1088
|
|
POST
|
All, We have just accquired the new ArcGIS 10 and I have been experimenting with model builder. I'm a big fan in documenting such tools as I never remember why, when & how I did things 6 months ago! In 9.3 when you were in model builder you could right-click on a process (the yellow box) and "edit documentation". This does not exist any more in ArcGIS 10, or does it and you have to access it via some other route? In ArcCatalog 10 you can add documentation to a parameter through Item description but I have yet to find a way how to document the process. Has this been dropped? Duncan
... View more
07-19-2010
03:06 AM
|
0
|
19
|
8799
|
|
POST
|
Hello, Sample code can be found in the Developers Help. It is under VBA Samples>Tables>Open a Table window. Duncan
... View more
06-29-2010
03:20 PM
|
0
|
0
|
1165
|