F# and ArcObjects, Part 2

Posted by Marko Apfel on Geeks with Blogs See other posts from Geeks with Blogs or by Marko Apfel
Published on Thu, 25 Mar 2010 12:49:13 GMT Indexed on 2010/03/25 19:53 UTC
Read the original article Hit count: 683

Filed under:

After accessing one feature now iterating through all features of a feature class:

open System;;

#I "C:\Program Files\ArcGIS\DotNet";;
#r "ESRI.ArcGIS.System.dll";;
#r "ESRI.ArcGIS.DataSourcesGDB.dll";;
#r "ESRI.ArcGIS.Geodatabase.dll";;
open ESRI.ArcGIS.esriSystem;;
open ESRI.ArcGIS.DataSourcesGDB;;
open ESRI.ArcGIS.Geodatabase;;

let aoInitialize = new AoInitializeClass();;

let status = aoInitialize.Initialize(esriLicenseProductCode.esriLicenseProductCodeArcEditor);;

let workspacefactory = new SdeWorkspaceFactoryClass();;

let connection = "SERVER=okul;DATABASE=p;VERSION=sde.default;INSTANCE=sde:sqlserver:okul;USER=s;PASSWORD=g";;

let workspace = workspacefactory.OpenFromString(connection, 0);;

let featureWorkspace = (box workspace) :?> IFeatureWorkspace;;

let featureClass = featureWorkspace.OpenFeatureClass("Praxair.SFG.BP_L_ROHR");;

let queryFilter = new QueryFilterClass();;

let featureCursor = featureClass.Search(queryFilter, true);;

let featureCursorSeq (featureCursor : IFeatureCursor) = 
  let actualFeature = ref (featureCursor.NextFeature())
  seq {
    while (!actualFeature) <> null do
      yield actualFeature
      do actualFeature := featureCursor.NextFeature()
   };;
  
featureCursorSeq featureCursor
|> Seq.iter (fun feature -> Console.WriteLine ((!feature).OID));;

© Geeks with Blogs or respective owner