Hello,
I was wondering if it is possible to populate a FeatureTable from a Feature Service with the centroid only geometry. Looking through the documentation and attempting this does not make it seem possible with the maps SDK. I could do it by pinging the FeatureService directly and using the returnCentroid parameter but that does not seem to be exposed in the SDK.
If this is not possible can I put an enhancement request in for it? Use case is this: Querying polygon features hosted in a service. I do not want to return the entire geometry for performance reasons. I want to sort the features by nearest location to the user. Having access to the centroid would satisfy my sorting and performance needs.
Solved! Go to Solution.
Hi Ting,
So for my intended workflow those will not work for me as I am populating my feature table with null geometries (queryParameters.returnGeometry = false) So will not have any geometry to get either the label point or the envelop center.
At first I had thought that some bare bones spatial data (label point or envelop center) did come through on the query even if the returnGeometry = null. But that does not seem to be the case.
My Hope was that I could get a minimal about of spatial data on my polygon so I can then sort them via distance to my users. This would keep my queries performant as the geometries are quite complex and also avoid errors I had seen on the service alerting me too many queries had been performed querying complex geometries and would need to wait 60 seconds before performing more queries.
Hi Forrest, thanks for posting. You are right, currently our SDK doesn't support the returnCentroid parameter.
Some (SDK-client-side) alternatives that may be worth a try: GeometryEngine.labelPoint(for:), or Envelope.center, for a rough estimate if the polygon is simple.
As they may not be suitable for your use case, please feel free to post in Native SDKs Ideas with your use case.
Hi Ting,
So for my intended workflow those will not work for me as I am populating my feature table with null geometries (queryParameters.returnGeometry = false) So will not have any geometry to get either the label point or the envelop center.
At first I had thought that some bare bones spatial data (label point or envelop center) did come through on the query even if the returnGeometry = null. But that does not seem to be the case.
My Hope was that I could get a minimal about of spatial data on my polygon so I can then sort them via distance to my users. This would keep my queries performant as the geometries are quite complex and also avoid errors I had seen on the service alerting me too many queries had been performed querying complex geometries and would need to wait 60 seconds before performing more queries.
Thanks for explaining your use case. I agree that not to fetch the complex geometry is a big time saver. Unfortunately, we haven't quite matched up with all the parameters that the REST API provides yet.
So if you want this feature, a few options to consider:
let baseURL = URL(string: "https://…/FeatureServer/0/query")!
var components = URLComponents(url: baseURL, resolvingAgainstBaseURL: false)!
components.queryItems = [
URLQueryItem(name: "f", value: "json"),
URLQueryItem(name: "outFields", value: "OBJECTID,STATE_NAME"),
URLQueryItem(name: "where", value: "1=1"),
URLQueryItem(name: "outSR", value: "4326"),
URLQueryItem(name: "returnDistinctValues", value: "false"),
URLQueryItem(name: "returnGeometry", value: "false"),
URLQueryItem(name: "returnM", value: "false"),
URLQueryItem(name: "returnZ", value: "false"),
URLQueryItem(name: "returnCentroid", value: "true"),
URLQueryItem(name: "token", value: "YOUR_API_KEY")
]
guard let finalURL = components.url else {
fatalError("Invalid URL components")
}
var request = URLRequest(url: finalURL)
request.httpMethod = "GET"
Thank you for the detailed and thorough response. I'm not quite sure the route we'll go but I think you pretty much covered all options there. Thank you. I will be putting in a request for that via in the native SDK's Ideas.
Cheers!