Getting feature layer for AGSGraphic

2293
7
Jump to solution
04-07-2013 07:58 AM
alexandergolubev
New Contributor
I have an array of AGSGraphic I got via AGSRelationshipQuery and I'm wondering how can I find AGSFeatureLayer those AGSGraphics belongs to. I need this layer since I want to edit those graphics, download attachments for them, etc (using AGSFeatureLayer' methods such as updateFeatures, addFeatures and so on).

Is there any way to do this? Please advice.
0 Kudos
1 Solution

Accepted Solutions
NimeshJarecha
Esri Regular Contributor
Are you executing relationship query from AGSFeatureLayer? If yes, the URL for the related graphics are going to be AGSFeatureLayer's URL. Just replace the layer id (i.e. /0) with related table/layer id. On the AGSFeatureLayer from which you are sending query has relationship property and you'll get  related table/layer id from there.

Hope this help!

Regards,
Nimesh

View solution in original post

0 Kudos
7 Replies
ChristopherBarger
New Contributor
If you are using an AGSQueryTask to get back a feature set, you will need to provide a URL for the query task to query, as well as set up the spatial relationship query. If you use the delegate method*queryTask:operation:didExecuteWithFeatureSetResult:, you will have access to the feature set that is returned as well as the queryTask that was run. One of the properties of the QueryTask you get back is URL, so you could use that URL to do any operations you want to do from there like updateFeatures. Below is a partial implementation of what i mean.  Even if you run two query tasks, you will still always be able to grab the correct URL.



-(void)QueryTask
{
  AGSSpatialReference *spatialRef = [AGSSpatialReference spatialReferenceWithWKID:4326];
  AGSPoint *point = [[AGSPoint alloc] initWithX:longitude y:latitude spatialReference:spatialRef];
  self.queryTask=[AGSQueryTask queryTaskWithURL:[NSURL URLWithString:@"YOUR_URL"];
  self.queryTask.delegate = self; //make sure you have your class set as a Query Task Delegate
 
  self.query = [AGSQuery query];
  self.query.geometry = point;
  self.query.spatialRelationship = AGSSpatialRelationshipWithin;
   
  [self.queryTask executeWithQuery:self.query];
}

//results are returned
- (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation *)op didExecuteWithFeatureSetResult:(AGSFeatureSet *)retrievedFeatureSet {
    NSURL *URL = queryTask.URL;
    AGSFeatureLayer *layerToModify = [[AGSFeatureLayer alloc] initWithURL: URL mode: AGSFeatureLayerModeOnDemand];
}
0 Kudos
alexandergolubev
New Contributor
Chris, thanks for response.
But in delegate callback I get related features, from another layer or table, so I need an URL for that related layer/table.
Here's my code:

// layer.URL = /rest/services/signs/FeatureServer/0
self.queryTask = [[AGSQueryTask alloc] initWithURL:layer.URL];
self.queryTask.delegate = self;
 
self.query = [AGSRelationshipQuery relationshipQuery];
self.query.outFields = [NSArray arrayWithObject:@"*"];
self.query.objectIds = [NSArray arrayWithObject:[NSNumber numberWithInt:68]];
self.query.relationshipId = 0;
self.query.returnGeometry = YES;
 
[self.queryTask executeWithRelationshipQuery:self.query];

...

// delegate method
- (void)queryTask:(AGSQueryTask *)queryTask operation:(NSOperation*)op didExecuteWithRelatedFeatures:(NSDictionary *)relatedFeatures
{
  // queryTask.URL = /rest/services/signs/FeatureServer/0
  // but should be: /rest/services/signs/FeatureServer/1
  // since related features we got here belongs to table /1, not /0

  NSLog(@"url: %@", queryTask.URL);
}
0 Kudos
NimeshJarecha
Esri Regular Contributor
Did you look at Related Record Editing Sample?

Regards,
Nimesh
0 Kudos
alexandergolubev
New Contributor
Nimesh, of course.
But in this sample URL of related layer is hardcoded. I'm wondering is it possible to programmatically get this URL somehow?
0 Kudos
NimeshJarecha
Esri Regular Contributor
Are you executing relationship query from AGSFeatureLayer? If yes, the URL for the related graphics are going to be AGSFeatureLayer's URL. Just replace the layer id (i.e. /0) with related table/layer id. On the AGSFeatureLayer from which you are sending query has relationship property and you'll get  related table/layer id from there.

Hope this help!

Regards,
Nimesh
0 Kudos
alexandergolubev
New Contributor
Yes, this is most obvious and tricky solution.
I'm wondering whether it's possible to have two related layer on two different servers (they will have different URLs), because this approach won't work in this case.
I still guess what URL for related layer exists somewhere deep in API, but it pretty hard to find 🙂
Anyway, thank you very much.
0 Kudos
NimeshJarecha
Esri Regular Contributor

I'm wondering whether it's possible to have two related layer on two different servers (they will have different URLs)


It is NOT possible to have two related layers will have different URLs. 🙂

Regards,
Nimesh
0 Kudos