Select to view content in your preferred language

Displaying query results

3504
2
Jump to solution
09-03-2014 12:21 PM
AaronHarmon
Deactivated User

Howdy,

I have been trying (quite unsuccessfully) to turn the results of a feature layer query (polygons) into graphics to be added to a graphics layer. I have checked several times that the returned FeatureSet contains the correct amount of features per the WHERE clause of the query. Yet every time I iterate through the FeatureSet, create graphics, and add said graphics to the GraphicsLayer, nothing appears.  Here is what I have so far.

Layer I am querying

NSURL* fenceUrl = [NSURL URLWithString: fenceAddress];

self.fenceLayer = [AGSFeatureLayer featureServiceLayerWithURL: fenceUrl mode:AGSFeatureLayerModeSelection];

The query

    AGSQuery *pQuery = [AGSQuery query];

    pQuery.where = @"USEREMAIL LIKE 'madeUpEmail@gmail.com'";

    pQuery.outFields = [NSArray arrayWithObjects:@"*", nil];

    pQuery.returnGeometry = YES;

    [self.fenceLayer selectFeaturesWithQuery:pQuery selectionMethod:AGSFeatureLayerSelectionMethodAdd];

This is the result of NSLog-ing the graphics I am trying to add to the layer

geometry: AGSPolygon: [envelope: AGSEnvelope: xmin = -96.650200, ymin = 29.600216, xmax = -96.029897, ymax = 30.117631, spatial reference: [AGSSpatialReference: wkid = 4326, wkt = null]], symbol: <AGSSimpleFillSymbol: 0xde7f030>, attributes: {

    OBJECTID = 801;

    USEREMAIL = "madeUpEmail@gmail.com";

    USERID = "1";

    channelID = "<null>";

}, visible: 1

My only thought is this could be a incorrect SpatialReference problem. I have already defined the spatial reference for the graphics to both webMercatorSpatialReference (same as the base map) and wgs84SpatialReference (same as the FeatureLayer) to no success. I tried to add the polygon Nimesh made here https://community.esri.com/thread/28467 but even that failed to show up on my map. Any thoughts or ideas would be greatly appreciated.

Thanks,

Aaron.

0 Kudos
1 Solution

Accepted Solutions
AaronHarmon
Deactivated User

I figured out my issue. I was initializing my AGSGraphicLayer with [AGSGraphicLayer graphicslayer] instead of [initWithSpatialReference].  Once I had that I was about to see my polygons as a single red pixel off the coast of Africa.  Then I created the graphic using [AGSGraphic graphicWithGeometry:symbol:attributes:] while using [AGSGeometryGeographicToWebMercator().  This combination finally created the graphics right where I needed.

Thanks anyway Gagan!

View solution in original post

0 Kudos
2 Replies
GagandeepSingh
Frequent Contributor

Hi Aaron Harmon‌,

Did you try setting the 'outSpatialReference' to the mapView's spatialReference, once the mapView has loaded? It might be the case that the two spatial references are different.

Let me know if this helps.


Gagan

0 Kudos
AaronHarmon
Deactivated User

I figured out my issue. I was initializing my AGSGraphicLayer with [AGSGraphicLayer graphicslayer] instead of [initWithSpatialReference].  Once I had that I was about to see my polygons as a single red pixel off the coast of Africa.  Then I created the graphic using [AGSGraphic graphicWithGeometry:symbol:attributes:] while using [AGSGeometryGeographicToWebMercator().  This combination finally created the graphics right where I needed.

Thanks anyway Gagan!

0 Kudos