You are here: > ESRI Forums > arcgis desktop discussion forums > Thread Replies

ArcGIS Desktop Discussion Forums

ArcGIS Desktop - ArcObjects General forum

OpenFeatureQuery returns FeatureClass with...   Jamie Tran Jul 07, 2003
Re: OpenFeatureQuery returns FeatureClass w...   Olivier Damanet Jul 07, 2003
Re: OpenFeatureQuery returns FeatureClass w...   Jamie Tran Jul 10, 2003
Re: OpenFeatureQuery returns FeatureClass w...   Matt Heller Oct 01, 2003
Re: OpenFeatureQuery returns FeatureClass w...   Eric Paitz Jun 23, 2004
Re: OpenFeatureQuery returns FeatureClass w...   Matt Heller Jun 25, 2004
Re: OpenFeatureQuery returns FeatureClass w...   Tim Howerton Jun 30, 2004
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject OpenFeatureQuery returns FeatureClass with HasOID = false 
Author Jamie Tran 
Date Jul 07, 2003 
Message Hi everyone,

I am trying to use the OpenFeatureQuery to filter a FeatureClass to be used in a SpatialJoin operation.

The SpatialJoin requires the Source table to contain an ObjectID.

When I use the OpenFeatureQuery to return a FeatureClass, I lose the ObjectID (The FeatureClass HasOID = false and OIDFieldName = "")

On the other hand, using OpenFeatureClass works fine.

The dataset is very large, so I'm trying to do a Spatial Join on only a small set of data. I don't know any other way to filter a data for the Join By Location operation except using OpenFeatureQuery.

Someone please help...

JT 
 
'VB.NET Code...

            'Open up Point FeatureClass with Query Definition
            Dim pQueryDef As IQueryDef
            pQueryDef = pFeatureWorkspace.CreateQueryDef

            Dim pFeatureClassContainer As IFeatureClassContainer

            'Defining the QueryDef
            With pQueryDef
                .Tables = "BPA_SPATIAL.FAP_CREST_POINT"
                .SubFields = "*"
                .WhereClause = pointWhereClause 
            End With

            'Open up FeatureQuery
            pFeatureClassContainer = pFeatureWorkspace.OpenFeatureQuery("pointFC", pQueryDef)


            'Open up Source shape featureclass
            Dim fcPoint As IFeatureClass
            fcPoint = pFeatureClassContainer.Class(0)
	    'if using fcPoint = pFeatureWorkspace.OpenFeatureClass("BPA_SPATIAL.FAP_CREST_POINT"), it works fine!

            fcPoly = pFeatureWorkspace.OpenFeatureClass("BPA_SPATIAL.FAP_FETCH_POLY")



            'Begin doing SpatialJoin
            'Create Temporary Area for Join Output
            Dim pWFTemp As IWorkspaceFactory
            pWFTemp = New AccessWorkspaceFactory()

            Dim pWSTemp As IWorkspace
            Dim pFWTemp As IFeatureWorkspace
            Dim pAccessWorkspaceName As IName
            Try

                pAccessWorkspaceName = pWFTemp.Create("C:\Temp\", "fnLocatePolygonWithPointFC", Nothing, 0)
                pWSTemp = pAccessWorkspaceName.Open


            Catch 'Workspace already exist, so just use it. 
                Dim pPropertySet As IPropertySet
                pPropertySet = New PropertySet()
                pPropertySet.SetProperty("DATABASE", "c:\temp\fnLocatePolygonWithPointFC.mdb")
                pWSTemp = pWFTemp.Open(pPropertySet, 0)

                Dim pFeatureClass As IFeatureClass

                pFWTemp = pWSTemp

                'If a featureclass already exist, delete it. 
                'The RasterConversion will create a new featureclass
                Try
                    pFeatureClass = pFWTemp.OpenFeatureClass("JoinResult")
                    Dim pDataset As IDataset
                    pDataset = pFeatureClass
                    pDataset.Delete()
                Catch
                    'IGNORE exception! Exception thrown indicates that the dataset does not exist, which is fine. 
                End Try
            End Try

            'Create Temporary FeatureClass for Join operation 
            Dim strOutName As String
            Dim fcJoin As IFeatureClassName
            Dim pOutDSName As IDatasetName
            Dim pName As IName

            fcJoin = New FeatureClassName()
            With fcJoin
                .FeatureType = esriFeatureType.esriFTSimple
                .ShapeFieldName = "Shape"
                .ShapeType = esriGeometryType.esriGeometryMultipoint
            End With

            pOutDSName = fcJoin
            With pOutDSName
                .Name = strOutName
                .WorkspaceName = pAccessWorkspaceName
            End With

            pName = pOutDSName

            'Do Join Operation 
            Dim pSpJoin As ISpatialJoin
            Dim pFCNew As IFeatureClass
            pSpJoin = New SpatialJoin()
            With pSpJoin
                .JoinTable = fcPoly
                .SourceTable = fcPoint
                .LeftOuterJoin = True
            End With

            'Join Within Operation Used
            pFCNew = pSpJoin.JoinWithin(pName)

            'It errors out saying "The Source Table must contain an ObjectID field to perform Join By Location"
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: OpenFeatureQuery returns FeatureClass with HasOID = false 
Author Olivier Damanet 
Date Jul 07, 2003 
Message .OpenFeatureQuery opens a virtual feature class, which can hence not have ObjectID's.
There are other mechanisms to filter features (QueryFilter, IFeatureLayerDefinition), but I don't find any way to combine those with a SpatialJoin.
I think you should consider to export the filtered features to a temporary feature class/shapefile, and then perform the Spatial Join on it. 
  Olivier. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: OpenFeatureQuery returns FeatureClass with HasOID = false 
Author Jamie Tran 
Date Jul 10, 2003 
Message I realize that the problem is because the FeatureClass I'm opening up is an Oracle View. OpenFeatureClass() on the Oracle View does recognize the ObjectID, but .OpenFeatureQuery() on the Oracle View does *not*. I don't know why...

.OpenFeatureQuery on a normal featureclass (not an Oracle View) works just fine with a recognized ObjectID.

Looks like several other threads have their own unique problems with Oracle Views, so I've given up on doing much with Oracle Views.

JT
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: OpenFeatureQuery returns FeatureClass with HasOID = false 
Author Matt Heller 
Date Oct 01, 2003 
Message I have a related question. I am having success opening a feature class with the OpenFeatureQuery method from a personal geodatabase if only the spatial table is specified in the query definition. However, if I perform a join in the query definition, I lose the ObjectID (The FeatureClass HasOID = false). If performing a join, the attribute table show’s the ObjectID field with a prefix of the spatial table’s name; I guess it doesn’t actually recognize it. Also I can symbolize and label the new theme that is loaded but I cannot select features.
Is it possible to use OpenFeatureQuery method, specify a join in the query definition, and keep the ObjectID (The FeatureClass HasOID = true) using a personal geodatabase? If it is possible, I could use some clues.

Thanks,
M.
 
 
Public Function LoadLaunchTheme(pMxDoc As IMxDocument, intProject_code As Integer, _
                                strLaunch_Site As String, str_MDBLocation As String) As IFeatureLayer

    Dim pMap As IMap
    Set pMap = pMxDoc.ActiveView
    Dim pPropset As IPropertySet
    Set pPropset = New PropertySet
    Dim pFact As IWorkspaceFactory
    Dim pWorkspace As IWorkspace
    pPropset.SetProperty "DATABASE", str_MDBLocation
    Set pFact = New AccessWorkspaceFactory
    Set pWorkspace = pFact.Open(pPropset, 0)
    Dim pFeatureWorkspace As IFeatureWorkspace
    Set pFeatureWorkspace = pWorkspace
    'create query def
    Dim pQueryDef As IQueryDef
    Set pQueryDef = pFeatureWorkspace.CreateQueryDef
    
    'provide list of tables to join
    pQueryDef.Tables = "Launch_Areas,Project_Codes"
'    pQueryDef.Tables = "Launch_Areas"  '**** HasOID = True if uncommented
    'Retrieve the fields from all tables
    pQueryDef.SubFields = "*"
    
    'set up join and where
    pQueryDef.WhereClause = "Launch_Areas.project_Code = " & intProject_code & _
           " And Launch_Areas.LaunchID =" & strLaunch_Site & " and" & _
           " Launch_Areas.project_Code = Project_Codes.Project_Code"
'    'set up where
'    pQueryDef.WhereClause = "Launch_Areas.project_Code = " & intProject_code & _
'           " And Launch_Areas.LaunchID = " & strLaunch_Site     '**** HasOID = True if uncommented
      
    ' Get the feature class
    Dim pFeatureClass As IFeatureClass
    Dim pFeatureClassContainer As IFeatureClassContainer
    Set pFeatureClassContainer = pFeatureWorkspace.OpenFeatureQuery("NewQuery", pQueryDef)
    If (pFeatureClassContainer.ClassCount <> 1) Then
      MsgBox "Failed to create feature class by query"
    Else
      Set pFeatureClass = pFeatureClassContainer.Class(0)
    End If
    
    ' Add feature class as layer to the map
    Dim pFeatureLayer As IFeatureLayer
    Set pFeatureLayer = New FeatureLayer
    Set pFeatureLayer.FeatureClass = pFeatureClass
    pFeatureLayer.Name = pFeatureClass.AliasName

    pMap.AddLayer pFeatureLayer
    
    Debug.Print "HasOID = " & pFeatureClass.HasOID
    
    Set LoadLaunchTheme = pFeatureLayer
End Function
 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: OpenFeatureQuery returns FeatureClass with HasOID = false 
Author Eric Paitz 
Date Jun 23, 2004 
Message Matt,

I am trying to do the same thing, did you find a solution? I am trying to join one
FeatureClass to one SDE Table (non-spatial). Both "tables" have an ObjectID field,
so if they were going which ObjectID field would be used in the resulting query? I
was gonig to try and create an SDE View. Maybe this will retain one of the ObjectID
fields and allow select operations to work on this FeatureLayer. 
  Eric Paitz 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: OpenFeatureQuery returns FeatureClass with HasOID = false 
Author Matt Heller 
Date Jun 25, 2004 
Message I never found a solution. I tried all different methods of defining subfields. I am still using the techniques above, but I obviously cannot select features, export data, etc. I haven’t tried this with version 9 yet, maybe it handles this issue better. 
   
Report Inappropriate Content • Top • Print • This Forum is closed for replies.    
Subject Re: OpenFeatureQuery returns FeatureClass with HasOID = false 
Author Tim Howerton 
Date Jun 30, 2004 
Message Take a look at the IQueryName2 interface. This object was incorporated into the user interface in Arc 9 as the Make Query Table tool in the new toolbox, but the interface was available in 8.3. The developer help has a sample that shows how to use it. It will allow you to define fields from a querydef, and which of those fields should be your OID. It will also allow you to have ArcMap create an OID for tables that do not have one, but I will caution you that it is very slow for big tables, as it builds a table in your temp directory every time it refreshes. 
  Tim Howerton
GIS Specialist
Missouri Department of Transportation