X, Y Coordinates shown but can't be grabbed

336
6
Jump to solution
3 weeks ago
Labels (2)
KTT_Mercury
New Contributor II

Howdy,

I'm trying to query a feature layer that I got added succesfully into a map.
My program is very much like that of the sample program on ESRI tutorial page, query a map feature layer: https://developers.arcgis.com/net/query/tutorials/query-a-feature-layer-sql/

I'm not using the sample's provided parcel endpoint, I've supplied my own feature service REST API endpoint.

The query went through and returned about some hundred of points. The issue is I can't seem to grab the X and Y even though they are shown clearly in the debug window under Geometry. Only a handful of properties such as HasM, HasZ, HasCurves shown up in the context menu/visual-studio IntelliSense. 

I couldn't help but am thinking this may be a known bug ? [as it happened to a software vendor our company had before and it didn't get fixed until later version] or am I missing something? Can you please help me straighten this up?

Such a torture I can't extract the coordinates - using a simple foreach loop - knowing they're there.

// Query the table and get the list of features in the result.
var queryResult = await featureTableToQuery.QueryFeaturesAsync(queryParams);

// Loop over each feature from the query result.
foreach (Feature feature in queryResult)
{
      double tempX = feature.Geometry.X // error
      bool tempChecked = feature.Geometry.HasZ // okay
      // Select each feature.
      // featureLayerToQuery!.SelectFeature(feature);

}

  

XYCoordNotShowUp.png

Thank you.

0 Kudos
3 Solutions

Accepted Solutions
dotMorten_esri
Esri Notable Contributor

The feature query returns "Geometry" which is the baseclass of "MapPoint", since it could have been a polygon or polyline. So you first need to cast it to MapPoint:

double tempX = ((MapPoint)feature.Geometry).X;

View solution in original post

dotMorten_esri
Esri Notable Contributor

By default you're getting coordinates in the projection of your map - which is probably WebMercator.

In the query you can set the output spatial reference, by setting the OutSpatialReference on your QueryParameters: https://developers.arcgis.com/net/api-reference/api/net/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Data.Q...

You can also use the GeometryEngine to project coordinates. For instance:


var newGeometry = GeometryEngine.Project(feature.Geometry, SpatialReference.Create(4269));

View solution in original post

KTT_Mercury
New Contributor II

Hello -  I tried to appy the SpatialReference.Create(4269) a to queryExtent.Geometry b, although it shows X, Y got affected by the GeometryEngine.Project (a, b) statement, it does nothing when being passed in the QueryParameters constructor to build the query param. Looks like queryExtend.Geometry got ignored.

It looks like I will have to issue a GeometryEngine.Project (a, b); for every feature per ilteration in the for loop. Thank you though.

View solution in original post

0 Kudos
6 Replies
dotMorten_esri
Esri Notable Contributor

The feature query returns "Geometry" which is the baseclass of "MapPoint", since it could have been a polygon or polyline. So you first need to cast it to MapPoint:

double tempX = ((MapPoint)feature.Geometry).X;

KTT_Mercury
New Contributor II

I have a follow-up question regarding this Geometry entity. How can I change the SpatialReference Wkid to a different 4-digit value like 4269, so X, Y will be represented more like longigute and latitude measure rather than huge measures shown. The SpatialReference Under Geometry observed here is readonly I think (I don't have Visual Studio with me now) 
I've read the documentation and so far I've only seen JSON based definition/discussion up and down, I'm looking for when can I set a spatial ref value on the fly, in the query building context like this:

QueryParameters queryParams = new QueryParameters {
      Geometry = queryExtent,
      ReturnGeometry = true,
      WhereClause = whereExpression,
      // possible do spatial ref assignment here 
      // to override whichever the default ref is:

};


Thanks.

0 Kudos
dotMorten_esri
Esri Notable Contributor

By default you're getting coordinates in the projection of your map - which is probably WebMercator.

In the query you can set the output spatial reference, by setting the OutSpatialReference on your QueryParameters: https://developers.arcgis.com/net/api-reference/api/net/Esri.ArcGISRuntime/Esri.ArcGISRuntime.Data.Q...

You can also use the GeometryEngine to project coordinates. For instance:


var newGeometry = GeometryEngine.Project(feature.Geometry, SpatialReference.Create(4269));

KTT_Mercury
New Contributor II

Hello -  I tried to appy the SpatialReference.Create(4269) a to queryExtent.Geometry b, although it shows X, Y got affected by the GeometryEngine.Project (a, b) statement, it does nothing when being passed in the QueryParameters constructor to build the query param. Looks like queryExtend.Geometry got ignored.

It looks like I will have to issue a GeometryEngine.Project (a, b); for every feature per ilteration in the for loop. Thank you though.

0 Kudos
dotMorten_esri
Esri Notable Contributor

Did you try setting the OutSpatialReference property as I suggested?

0 Kudos
KTT_Mercury
New Contributor II

Hello - The OutSpatialReference wouln't take any direct value assignment, would it. I remember  before I got here, I did an equal sign for it, but it was red underlined. I think I will try t to see if it has somthing like a a built in method Add or something like that to pass in the value.
For now as stated, I invoke the Geometry Engine every time I want to get the X and Y with the target ref 4269  

0 Kudos