Select to view content in your preferred language

No features returned from SceneLayer query

412
4
07-22-2024 07:55 AM
DominicBowyer2
Occasional Contributor

Hi there, I have the following function that aims to extract meshes from a scene layer passed in as a parameter. However, for reasons unknown to me. The number of features returned is consistently 0. Would appreciate any help understanding what it is that I am doing wrong. I will share the function below as well as an portion of my logs for context:

func extractMeshes(from sceneLayer: ArcGISSceneLayer) async {

      guard let featureTable = sceneLayer.featureTable else {

          print("No feature table found in the scene layer")

          return

      }

 

      print("Feature table found: \(featureTable.tableName)")

 

      // Ensure the layer is loaded

      if sceneLayer.loadStatus != .loaded {

          do {

              try await sceneLayer.load()

              print("Scene layer loaded: \(sceneLayer.name)")

          } catch {

              print("Error loading scene layer: \(error)")

              return

          }

      }

 

      // Print the fields of the feature table

      let fields = featureTable.fields

      print("Feature table fields: \(fields.map { $0.name })")

 

      // Adjust the query parameters

      let query = QueryParameters()

      query.whereClause = "1=1"

      query.returnsGeometry = true

 

      print("Query parameters set: \(query.whereClause)")

 

      do {

          let featureQueryResult = try await featureTable.queryFeatures(using: query)

          let features = featureQueryResult.features()

          let featuresArray = Array(features)

          print("Number of features queried: \(featuresArray.count)")

          

          for feature in featuresArray {

              if let geometry = feature.geometry {

                  print("Extracted geometry from feature: \(geometry)")

                  if let node = createNode(for: geometry) {

                      let point = geometry.extent.center

                    print("Anchoring node at coordinate: (\(point.y), \(point.x)) with altitude \(String(describing: point.z))")

                      anchorNode(node, at: point)

                  }

              }

          }

      } catch {

          print("Error querying features: \(error)")

      }

  }

Logs:

MSPK loaded successfully.

Attempting to load scene: ArcGIS.Scene

Layer name: London GPS test

Layer name: 3D_tests_Multipatch_as_Mesh

Feature table found: SceneLayerFeatures

Feature table fields: ["OBJECTID", "speckle_id"]

Query parameters set: 1=1

Number of features queried: 0

0 Kudos
4 Replies
NimeshJarecha
Esri Regular Contributor

Hi @DominicBowyer2 ,

Thanks for providing your code. I cannot compile it but looks like the feature table loading step is missing. I would suggest altering the steps of the function as,

1. Load scene layer if not loaded

2. Get the feature table from scene layer

3. Load the feature table

4. Query the feature table.

 

    func extractMeshes(from sceneLayer: ArcGISSceneLayer) async {
        // Ensure the layer is loaded
        if sceneLayer.loadStatus != .loaded {
            do {
                try await sceneLayer.load()
                print("Scene layer loaded: \(sceneLayer.name)")
            } catch {
                print("Error loading scene layer: \(error)")
                return
            }
        }
        
        guard let featureTable = sceneLayer.featureTable else {
            print("No feature table found in the scene layer")
            return
        }
        
        print("Feature table found: \(featureTable.tableName)")
        
        // Ensure the table is loaded
        if featureTable.loadStatus != .loaded {
            do {
                try await featureTable.load()
                print("Feature table loaded: \(featureTable.tableName)")
            } catch {
                print("Error loading feature table: \(error)")
                return
            }
        }

        
        // Print the fields of the feature table
        let fields = featureTable.fields
        print("Feature table fields: \(fields.map { $0.name })")
        
        // Adjust the query parameters
        let query = QueryParameters()
        query.whereClause = "1=1"
        query.returnsGeometry = true
        
        print("Query parameters set: \(query.whereClause)")
        
        do {
            let featureQueryResult = try await featureTable.queryFeatures(using: query)
            let features = featureQueryResult.features()
            let featuresArray = Array(features)
            print("Number of features queried: \(featuresArray.count)")
            
            for feature in featuresArray {
                if let geometry = feature.geometry {
                    print("Extracted geometry from feature: \(geometry)")
                    if let node = createNode(for: geometry) {
                        let point = geometry.extent.center
                        print("Anchoring node at coordinate: (\(point.y), \(point.x)) with altitude \(String(describing: point.z))")
                        anchorNode(node, at: point)
                    }
                }
            }
        } catch {
            print("Error querying features: \(error)")
        }
    }

Regards,

Nimesh

0 Kudos
DominicBowyer2
Occasional Contributor

Thanks for the reply @NimeshJarecha I updated my code based on your answer but unfortunately, no features are being returned still. Perhaps I should give more context to what i'm trying to achieve.

I am trying to extract the 3D geometry / meshes from my scene layer such that I can anchor them to their geographic coordinates in AR world space. Im starting to suspect that this might not be possible via querying the feature table though. Is there an alternative approach to achieve this perhaps? Or maybe it is possible via querying and I'm just going about it wrong? I

did notice that my feature table geometry type is nil during testing. Not sure if that is relevant. I don't imagine my scene layer is corrupted or anything as I am able to render the entire scene in AR with WordlScaleSceneView (however the scene is overlaid). Any advice would be greatly welcomed. 

Here are some logs from my latest test:

MSPK loaded successfully.

Attempting to load scene: ArcGIS.Scene

Layer name: London GPS test, Layer type: FeatureLayer

Layer name: 3D_tests_Multipatch_as_Mesh, Layer type: ArcGISSceneLayer

Processing ArcGISSceneLayer: 3D_tests_Multipatch_as_Mesh

Scene layer load status: loaded

Feature table found: SceneLayerFeatures

Feature table load status: loaded

Feature table geometry type: nil

Feature table fields: ["OBJECTID", "speckle_id"]

Query parameters set: 1=1

Number of features queried: 0

0 Kudos
KoushikHajra
Esri Contributor

Hello @DominicBowyer2 

Thank you for reaching out to us. I have a few questions for you and I can explain in details as to why your query is not working. 

1. What is it that you are trying to achieve? Add your 3D layer in AR mode without any of the other layers from your scene? You seem to be using an mspk, which is one or more scenes packaged together to create an offline dataset. So, it might contain as many layers as each scene had during packaging. If you're only looking to add your scene layer, then you should add an .slpk dataset which is just the scene layer packaged. This is just a guess on my part. I'd like to get a bit more information on this.

2. What type of scene layer are you using? Again it's a guess (by seeing the name of the layer) but I am guessing it is a 3DObject scene layer since the name seems to be multipatch? 

3. Query works a bit differently in case of scene layer. If the layer is backed by a buddy feature service, then it would work the way you have it. However, since you are using offline data, and we do not fully support editing workflows yet, it only works after you've identified and selected a feature. We do not add the features to the table until this happens only in case of offline data. So, if you just try to identify and select a feature and then try to run the query, it should return you feature(s).

4. You are trying to extract the geometries from the features. We do not expose the mesh geometry type. So, at this time, you won't be able to do it. We plan to support it in a future release when we fully support 3D editing workflows.

Hope this helps. 

-Koushik

0 Kudos
DominicBowyer2
Occasional Contributor

Hey @KoushikHajra I must have missed this reply some weeks ago but thanks for taking the time to explain things to me. You were correct in saying that I was working with an offline 3DObjectSceceLayer and my goal was indeed related to extracting the geometries from the fetures. My ultimate aim was to be able to extract the mesh geometry and add it to an AR scene. This was so i might have more control over the workflow. I realised soon after posting this that querying the geometry wasn't yet a supported feature. I have since, decided on just adding the entire mspk scene via WorldScaleSceneView in the toolkit for now. Although i look forward to hearing more about the 3D editing worfklows in the future.

0 Kudos