Select to view content in your preferred language

Accessing a field from a Map Server and populating UITableView

332
2
Jump to solution
07-24-2024 10:45 PM
AfrozAlam
Occasional Contributor

I am developing an application on Xcode 15.4 & Swift 5.4 using ArcGIS SDK for iOS. I am trying to access the below URL;

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

Extracting the ENAME field and populating a UITableView. This service contains only 8 Records but it takes more than 20 seconds to populate the table. I think, I should take maximum 2-3 seconds. 

It would be very much appreciated if someone explain to me why it takes too much time or some thing wrong in my code. The Code is attached herewith for ready reference.

Thanks & regards,

Afroz Alam

 

Afroz Alam
0 Kudos
1 Solution

Accepted Solutions
Ting
by Esri Contributor
Esri Contributor

Hi Afroz,

After examining this feature service, I found that a large amount of time was consumed by loading the geometry of each feature. If you don't need the geometry in the UITableView, consider the following

queryParams.returnGeometry = false

By setting the query parameter's returnGeometry to false, it will not load the geometry for the feature, which saves big amount of time. Per my test, with this line added, the query takes about 1 second. While it normally takes 5 seconds to fully load.

The full code looks like below. Note that I added a clock to measure the time elapsed for the query.

private func queryMunicipality() {
    let begin = clock()
    print("clock begins")
    
    let queryParams = AGSQueryParameters()
    queryParams.whereClause = "1=1"
    queryParams.returnGeometry = false
    featureTable.populateFromService(
        with: queryParams,
        clearCache: true,
        outFields: ["*"]
    ) { [weak self] (queryResult: AGSFeatureQueryResult?, error: Error?) in
        guard let self else { return }
        
        // For measuring time
        let diff = Double(clock() - begin) / Double(CLOCKS_PER_SEC)
        print("Time elapsed", diff)
        
        if let error {
            print(error.localizedDescription)
        } else if let features = queryResult?.featureEnumerator().allObjects,
                  !features.isEmpty {
            for feature in features {
                let featureDict = [
                    "CODE": feature.attributes.value(forKey: "CODE") as! String,
                    "ENAME": feature.attributes.value(forKey: "ENAME") as! String,
                    "ANAME": feature.attributes.value(forKey: "ANAME") as! String
                ]
                print("Attr: \(featureDict)")
            }
        }
    }

  

View solution in original post

0 Kudos
2 Replies
Ting
by Esri Contributor
Esri Contributor

Hi Afroz,

After examining this feature service, I found that a large amount of time was consumed by loading the geometry of each feature. If you don't need the geometry in the UITableView, consider the following

queryParams.returnGeometry = false

By setting the query parameter's returnGeometry to false, it will not load the geometry for the feature, which saves big amount of time. Per my test, with this line added, the query takes about 1 second. While it normally takes 5 seconds to fully load.

The full code looks like below. Note that I added a clock to measure the time elapsed for the query.

private func queryMunicipality() {
    let begin = clock()
    print("clock begins")
    
    let queryParams = AGSQueryParameters()
    queryParams.whereClause = "1=1"
    queryParams.returnGeometry = false
    featureTable.populateFromService(
        with: queryParams,
        clearCache: true,
        outFields: ["*"]
    ) { [weak self] (queryResult: AGSFeatureQueryResult?, error: Error?) in
        guard let self else { return }
        
        // For measuring time
        let diff = Double(clock() - begin) / Double(CLOCKS_PER_SEC)
        print("Time elapsed", diff)
        
        if let error {
            print(error.localizedDescription)
        } else if let features = queryResult?.featureEnumerator().allObjects,
                  !features.isEmpty {
            for feature in features {
                let featureDict = [
                    "CODE": feature.attributes.value(forKey: "CODE") as! String,
                    "ENAME": feature.attributes.value(forKey: "ENAME") as! String,
                    "ANAME": feature.attributes.value(forKey: "ANAME") as! String
                ]
                print("Attr: \(featureDict)")
            }
        }
    }

  

0 Kudos
AfrozAlam
Occasional Contributor

Hi Ting,

Thank you very much. The problem is solved.

So kind of you.

Warm regards,

Afroz Alam