Using my location on a geoprocessingTask in iOS SDK version 100.0.0

02-10-2017 12:31 PM
New Contributor

I'm trying to upgrade to the newest version of the SDK in one of my apps and I can't figure out how to make an AGSGeoProcessingFeatures paramter with a feature that I created locally. it says it can be initialized with an AGSFeatureSet but that's just a Protocol and can't be initialized itself. I used to be able to do it like this: 

let agsGraphic = AGSGraphic(geometry: mapPoint, symbol: markerSymbol, attributes: nil)

let features = AGSFeatureSet(features: [agsGraphic])

let locationParam = AGSGPParameterValue(name: "Input_Feature", type:    AGSGPParameterType.FeatureRecordSetLayer, value: features)

Did AGSFeatureSet intentionally become less functional? is this going to be implemented in a release soon? should I make my own class that extends it? What do I do? 

I realize that version 100.0.0 is not 100% where they want it to be, should I just hold off until there are a few more updates out?



0 Kudos
1 Reply
Occasional Contributor II

AGSFeatureCollectionTable implements the AGSFeatureSet protocol, so you can create AGSGeoProcessingFeatures from it. We have the Analyze viewshed sample you can refer. I will also include the code you need here.

    private func calculateViewshed(at point: AGSPoint) {
        //the service requires input of rest data type GPFeatureRecordSetLayer
        //which is AGSGeoprocessingFeatures in runtime
        //in order to create an object of AGSGeoprocessingFeatures we need a featureSet
        //for which we will create a featureCollectionTable (since feature collection table
        //is a feature set) and add the geometry as a feature to that table.
        //create feature collection table for point geometry
        let featureCollectionTable = AGSFeatureCollectionTable(fields: [AGSField](), geometryType: .point, spatialReference: point.spatialReference)
        //create a new feature and assign the geometry
        let newFeature = featureCollectionTable.createFeature()
        newFeature.geometry = point
        //add the new feature to the feature collection table
        featureCollectionTable.add(newFeature) { [weak self] (error: Error?) in
            if let error = error {
                //show error
                SVProgressHUD.showError(withStatus: error.localizedDescription, maskType: .gradient)
            else {
    private func performGeoprocessing(_ featureCollectionTable: AGSFeatureCollectionTable) {
        //geoprocessing parameters
        let params = AGSGeoprocessingParameters(executionType: .synchronousExecute)
        params.processSpatialReference = featureCollectionTable.spatialReference
        params.outputSpatialReference = featureCollectionTable.spatialReference
        //use the feature collection table to create the required AGSGeoprocessingFeatures input
        params.inputs["Input_Observation_Point"] = AGSGeoprocessingFeatures(featureSet: featureCollectionTable)
        //initialize job from geoprocessing task
        self.geoprocessingJob = self.geoprocessingTask.geoprocessingJob(with: params)

I hope that helps.

Gagandeep Singh

0 Kudos