POST
|
Chris, Below is a VBA script I knocked up to test the whole in_memory workspace thing. I know it's not .Net but this should pretty much port into your code and gives you an idea of what worked for me? Duncan Public Sub InMemoryExample()
' Description: Sample code showing how an in memory table can be created
' Create Workspacefactory
Dim pWorkSpaceFactory As IWorkspaceFactory2
Set pWorkSpaceFactory = New InMemoryWorkspaceFactory
' Create Workspace
Dim pWorkspaceName As IWorkspaceName2
Set pWorkspaceName = pWorkSpaceFactory.Create("", "MyInMemoryWorkspace", Nothing, 0)
' Get a handle on Name
Dim pName As IName
Set pName = pWorkspaceName
' Get a handle on FeatureWorkspace
Dim pFeatureWorkspace As IFeatureWorkspace
Set pFeatureWorkspace = pName.Open
' Now create a fields object and add some fields to it
' Create Fields object and set the number of fields
Dim pFields As IFields
Set pFields = New Fields
Dim pFieldsEdit As IFieldsEdit
Set pFieldsEdit = pFields
pFieldsEdit.FieldCount = 2
' Create objectID field
Dim pField As IField
Set pField = New Field
Dim pFieldEdit As IFieldEdit
Set pFieldEdit = pField
With pFieldEdit
.Name = "OBJECTID"
.Type = esriFieldTypeOID
End With
Set pFieldsEdit.Field(0) = pField
' Create Type field
Set pField = New Field
Set pFieldEdit = pField
With pFieldEdit
.Editable = True
.Name = "VegType"
.Type = esriFieldTypeString
.Length = 4
.AliasName = "Vegetation Type Code"
End With
Set pFieldsEdit.Field(1) = pField
' Create Table
Dim pTable As ITable
Set pTable = pFeatureWorkspace.CreateTable("MyInMemTable", pFields, Nothing, Nothing, "")
' Create a sample row and add data
Dim pRow As IRow
Set pRow = pTable.CreateRow
With pRow
.Value(1) = "WOOD"
.Store
End With
' Add table to map document
Dim pMXD As IMxDocument
Set pMXD = ThisDocument
Dim pMap As IMap
Set pMap = pMXD.FocusMap
Dim pStandAloneTableCollection As IStandaloneTableCollection
Set pStandAloneTableCollection = pMap
Dim pStandAloneTable As IStandaloneTable
Set pStandAloneTable = New StandaloneTable
Set pStandAloneTable.Table = pTable
pStandAloneTableCollection.AddStandaloneTable pStandAloneTable
pMXD.UpdateContents
End Sub
... View more
11-10-2010
12:56 PM
|
0
|
0
|
764
|
POST
|
All, I poked around the Help file a bit more and although it seems there is no attribute in the APL file that you can set to say a control is invisible you can do it through code. So I have this code executed in the on initialise event of the form. Hey presto the control is invisible! Dim aForm, aControl
Set aForm = LAYER.Forms.Item("EDITFORM")
Set aControl = aForm.Pages.Item("PAGE1").Controls.Item("ebx_ID")
aControl.Visible = false Duncan
... View more
10-23-2010
06:17 AM
|
0
|
0
|
219
|
POST
|
All, A client has asked to me resurrect from the past an old ArcPad 6 project. I had created custom forms with vb code for a bunch of shapefiles. When I load the forms in I notice what were invisible edit boxes are now visible in ArcPad 10. Looking at the APL file it looks like I made them invisible by deleting the font attributes from the XML schema (the APL file). Well this obviously does not work in Arcpad 10, so how does one make the control invisible? There appears to be no attribute one can set to say invisible (well not from I've seen from the Help file anyway)? I want them invisible as they are holding a value which affects the value of another edit box. Whats the official way esri would do it? Duncan
... View more
10-22-2010
09:48 AM
|
0
|
2
|
789
|
POST
|
Here is an alternate but very similar approach to Ken's code: Public Sub Test()
' Create dialog
Dim pGxDialog As IGxDialog
Set pGxDialog = New GxDialog
' Define filter
Dim pGxObjectFilter As IGxObjectFilter
Set pGxObjectFilter = New GxFilterPolygonFeatureClasses
' Set dialog properties and open
Dim pEnumGxObject As IEnumGxObject
With pGxDialog
.Title = "Select Catchments Feature Class"
.ButtonCaption = "Select"
.AllowMultiSelect = False
.StartingLocation = "Catalog"
Set .ObjectFilter = pGxObjectFilter
.DoModalOpen 0, pEnumGxObject
End With
Dim pGXObject As IGxObject
Set pGXObject = pEnumGxObject.Next
Dim pGXdataset As IGxDataset
Set pGXdataset = pGXObject
Dim pDataset As IDataset
Set pDataset = pGXdataset.Dataset
Dim pFeatureClass As IFeatureClass
Set pFeatureClass = pDataset
' Get fields a cycle through them
Dim pFields As IFields
Set pFields = pFeatureClass.Fields
Dim i As Byte
Dim pField As IField
For i = 0 To pFields.FieldCount - 1
Set pField = pFields.Field(i)
MsgBox pField.Name
Next i
End Sub Duncan
... View more
10-21-2010
08:29 AM
|
0
|
0
|
546
|
POST
|
Hi Sanja, This is just a random idea that popped into my head, so may not be any better? Explode your polygons into individual points (if you are familiar with ArcObjects I'm think of the IPointCollection Interface) into a new featureclass, extract their XY coordinates as attributes and concatenate that into a single string field then do some sort of group by query? Just an idea... Duncan
... View more
10-06-2010
04:15 AM
|
0
|
0
|
178
|
POST
|
Hi Jerry, If you want to do what the geo processing tool does why not simply use it? In VBA you access it via the IGeoprocessor interface. The following link takes you to a thread where IGeoProcessor is calling the SelectByLocation tool. You would simply re-jig the parameters array with your layers and selection criteria. http://forums.esri.com/Thread.asp?c=93&f=983&t=249267&mc=4#msgid762216 Duncan
... View more
10-01-2010
01:45 PM
|
0
|
0
|
440
|
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
|
397
|
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
|
366
|
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
|
844
|
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
|
628
|
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
|
6510
|
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
|
763
|