Select to view content in your preferred language

Accessing a table through a hyperlink

327
5
Jump to solution
07-13-2024 11:55 PM
AfrozAlam
Occasional Contributor

I am developing an iOS app on Xcode 14.2 using Swift 5.7 and ArcGIS Runtime SDK for iOS 100.15. I am using a map service table as below

https://services.gisqatar.org.qa/server/rest/services/Vector/QARS_Search/MapServer/6

I want to access the above table and read the value from fields "BUILDING_NO_SUBTYPE" and "SUBTYPE_COUNT". I am trying to access through "AGSServiceFeatureTable". The code I am using is attached herewith for ready reference.

I would be very grateful if anyone can help me in this regards.

Thanks & regards,

Afroz Alam
0 Kudos
1 Solution

Accepted Solutions
AfrozAlam
Occasional Contributor

Hi Ting,

Thank you very much brother, my problem is solved.

So nice of you.

Warm regards,

Afroz Alam

View solution in original post

5 Replies
Ting
by Esri Contributor
Esri Contributor

Hi Afroz, thanks for asking. The table you provided is a bit unusual because it doesn't contain the object ID or global ID we used to have in the service feature tables, so maybe our SDK isn't handling them correctly, in contrast to the REST endpoint where you can query the entries successfully. Will let you know once I have more details.

For some reason, using the SDK I can only access the BUILDING_NO_SUBTYPE of an entry, but not the subtype count.

0 Kudos
AfrozAlam
Occasional Contributor

Hi Ting,

Thanks a lot for your reply. I would like to ask you, is there any way to access the data from this table out of ESRI SDK. Accessing data from main Map Service or Feature Service (as below), having around 200K records, take lots of time.

https://services.gisqatar.org.qa/server/rest/services/Vector/QARS_Search/MapServer/0

https://services.gisqatar.org.qa/server/rest/services/Vector/QARS_Search/FeatureServer/0

I want to count only the number of records from above links. Is there is any way to get total records from either of these table in max 15 seconds using ESRI SDK.

It would be very much appreciated if you can help me in this regard.

Thanks & regards,

Afroz Alam

 

Afroz Alam
0 Kudos
Ting
by Esri Contributor
Esri Contributor

Yes, by specifying returnCountOnly = true, you can get the records much quicker than loading all the features then count them. 

With the REST API call, it looks like this: https://services.gisqatar.org.qa/server/rest/services/Vector/QARS_Search/MapServer/0/query?where=1%3...

With the SDK, it looks like below:

 

 

featureTable.queryFeatureCount(with: queryParams) { count, error in
    if let error {
        print(error.localizedDescription)
    } else {
        print("Total count is: \(count)")
    }
}

 

 

 

0 Kudos
Ting
by Esri Contributor
Esri Contributor

For the original question, below is a code snippet to get BUILDING_NO_SUBTYPE and SUBTYPE_COUNT from the service feature table: https://services.gisqatar.org.qa/server/rest/services/Vector/QARS_Search/MapServer/6 . Note that in order to access all the attributes, you'll need to specify loadAll for the queryFeatureFields parameter.

import UIKit
import ArcGIS

class ViewController: UIViewController {
    @IBOutlet private var mapView: AGSMapView! {
        didSet {
            mapView.map = AGSMap(basemapStyle: .arcGISLightGray)
        }
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        queryQARS_Total()
    }
    
    let featureTable = AGSServiceFeatureTable(
        url: URL(string: "https://services.gisqatar.org.qa/server/rest/services/Vector/QARS_Search/MapServer/6")!
    )
    
    private func showSubtypeCount(for feature: AGSFeature) {
        let subType = feature.attributes.value(forKey: "BUILDING_NO_SUBTYPE") as! Int
        let count = feature.attributes.value(forKey: "SUBTYPE_COUNT") as! Int
        let objectID = feature.attributes["ObjectID"] as! Int
        print("SUBTYPE_COUNT = \(count) for feature of \(subType), ObjectID \(objectID)")
    }
    
    private func queryQARS_Total() {
        let queryParams = AGSQueryParameters()
        queryParams.whereClause = "1=1"
        featureTable.queryFeatures(
            with: queryParams,
            queryFeatureFields: .loadAll
        ) { [weak self] (queryResult: AGSFeatureQueryResult?, error: Error?) in
            guard let self else { return }
            if let error {
                print(error.localizedDescription)
            } else if let features = queryResult?.featureEnumerator().allObjects,
                      !features.isEmpty {
                for feature in features {
                    self.showSubtypeCount(for: feature)
                }
            }
        }
    }
}

 

0 Kudos
AfrozAlam
Occasional Contributor

Hi Ting,

Thank you very much brother, my problem is solved.

So nice of you.

Warm regards,

Afroz Alam