Monthly Archives: July 2012

InMemory shapefile or featureclass creation

http://forums.esri.com/Thread.asp?c=93&f=993&t=210767&mc=12#652601

Option Explicit
Sub TestInMemory()
Dim pFC As IFeatureClass
Set pFC = OpenFC(“C:\Projects\SAWS\water3.gdb”, _
“Mains”)

Dim pFLayer As IFeatureLayer
Set pFLayer = New FeatureLayer
pFLayer.Name = pFC.AliasName
Set pFLayer.FeatureClass = CacheToMemory(pFC, “Shape_Length 0 Then
Set pQF = New QueryFilter
pQF.WhereClause = sWhere
End If

Dim pInFCur As IFeatureCursor
Set pInFCur = pFC.Search(pQF, False)

Dim pFeat As IFeature
Set pFeat = pInFCur.NextFeature
Do Until pFeat Is Nothing
Dim pOutFeat As IFeature
Set pOutFeat = pInMemFC.CreateFeature

Dim l As Long
For l = 0 To pOutFeat.Fields.FieldCount – 1
‘ todo maybe search by field alias to find match
If pOutFeat.Fields.Field(l).Editable Then
pOutFeat.Value(l) = pFeat.Value(l)
End If
Next l
pOutFeat.Store
Set pFeat = pInFCur.NextFeature
Loop

End Sub

Function Clone(pClone As IClone) As IClone
Set Clone = pClone.Clone
End Function

Function OpenFC(sPath As String, sName As String) As IFeatureClass
Dim pWSF As IWorkspaceFactory
Set pWSF = New FileGDBWorkspaceFactory
Dim pFWS As IFeatureWorkspace
Set pFWS = pWSF.OpenFromFile(sPath, 0)

Set OpenFC = pFWS.OpenFeatureClass(sName)
End Function

Advertisements

IConversionOp RasterDataToLineFeatureData Example

  Dim pConversionOp As IConversionOp
  Set pConversionOp = New RasterConversionOp

  ‘Get the raster
  Dim pRas01 As IRaster
  Set pRas01 = getRasterFromFileFunction(“c:\data\myRaster”)
 
  Dim pFClassOut As IGeoDataset
  Dim pWSF As IWorkspaceFactory
  Set pWSF = New ShapefileWorkspaceFactory
  Dim pWS As IWorkspace
  Set pWS = pWSF.OpenFromFile(“c:\data”, 0)
  Dim sOutFCname As String
  sOutFCname = “myShapeFile.shp”

  Set pFClassOut = pConversionOp.RasterDataToLineFeatureData(pRas01, pWS, sOutFCname, False, False, 1.0)

 

http://edndoc.esri.com/arcobjects/9.2/ComponentHelp/esriGeoAnalyst/IConversionOp_RasterDataToLineFeatureData_Example.htm

Reclass by Remap

'Reclassifies (or changes) the values of the input cells of a raster by ' using a remap that is built programmatically. ' 'Function ReclassByRemap(ByVal GeoDataset As esriGeoDatabase.IGeoDataset, _ ' ByVal Remap As IRemap, ByVal retainMissingValues As Boolean) _ ' As esriGeoDatabase.IGeoDataset ' 'Member of esriGeoAnalyst.IReclassOp 
Dim pReclassOp As IReclassOp
Set pReclassOp = New RasterReclassOp

' Get raster dataset Dim pRas01 As IRaster
Set pRas01 = readRasterFromDisk("c:\data\myRaster")

' Set the Remap Dim pRemap As IRemap
Dim pSRemap As INumberRemap
Set pSRemap = New NumberRemap

pSRemap.MapRange -3, 0, 0
pSRemap.MapRange 0, 2, 20
pSRemap.MapRange 2, 3, 60
Set pRemap = pSRemap

' Create output raster dataset Dim pRasOut As IRaster
Set pRasOut = pReclassOp.ReclassByRemap(pRas01, pRemap, True)
 
http://resources.esri.com/help/9.3/arcgisdesktop/com/gp_toolref/spatial_analyst_tools/reclassbyremap.htm

IDensityOp PointDensity Example

http://resources.esri.com/help/9.3/arcgisengine/ArcObjects/esriSpatialAnalyst/IDensityOp_PointDensity_Example.htm

Reference: http://help.arcgis.com/en/sdk/10.0/arcobjects_net/componenthelp/index.html#/PointDensity_Method/00400000003r000000/

Dim pDensityOp As IDensityOp
Set pDensityOp = New RasterDensityOp

‘Create Raster Analysis Environment and set output cell size
Dim pEnv As IRasterAnalysisEnvironment
Set pEnv = pDensityOp
pEnv.SetCellSize esriRasterEnvValue, 50

Dim pFClass01 As IFeatureClass
Set pFClass01 = FunctionToOpenPointFeatureClass(“C:\data\point01.shp”)

‘ Create Neighborhood using map unit
Dim pNbr As IRasterNeighborhood
Set pNbr = New RasterNeighborhood
pNbr.SetCircle 4, esriUnitsMap

‘ Call the Point Density method using featureclass as input

Dim pRasOut As IRaster
Set pRasOut = pDensityOp.PointDensity(pFClass01, pNbr)

‘ OR

‘ Create FeatureClassDescriptor to specify a field or keyword NONE
Dim pFDescr As IFeatureClassDescriptor
Set pFDescr = New FeatureClassDescriptor
pFDescr.Create pFClass01, Nothing, “Field1”

‘ Call the Point Density method using FeatureClassDescriptor

Dim pRasOut2 As IRaster

Set pRasOut2 = pDensityOp.PointDensity(pFDescr, pNbr)