Querying layers in VertiGIS Studio Workflow is a useful tool for retrieving the information you need from your mapping applications. This VertiGIS Studio Tech Tip provides an overview of how to query layers in VertiGIS Studio Workflow and guides viewers through the process of customizing a query to access the specific information they’re looking for. The many ways that a query can be customized make it easy for your end-users to make the most of your mapping applications, regardless of their GIS skill level!
Hey everybody, my name is Patrick. In this Tech Tip video, we’re going to take a look at querying layers using VertiGIS Studio Workflow. Let’s check it out!
All right, so we’re going to kick things off here in ArcGIS Online. Here I have a web map which contains a few different layers. If I were to go ahead and click on these layers, it will take me to another item here. Then if I click on one of these layers again, we’re going to see there’s now this “URL”.
This URL is pointing to the what’s called as the rest endpoint for the layer. If we were to go back up a level, this would be the rest endpoint for the underlying feature service containing your published GIS map services and feature services.
Let’s select this “Water Lines” layer. If we scroll down, you’ll see there’s this “Query” operation. If you’re not familiar with this, it’s a really useful tool that the ArcGIS server provides. This is where you can quickly test out some queries against your different data sets to return some results.
The most common type of query is what’s called a “1 = 1”, which is basically going to return all of the records within your database. There are also other options here. So, you could maybe say which attributes you want to be returned. So, if you want to return everything, you can use “*”, or you can enter in the specific attribute field name, whether you want to “Return Geometry”, and a number of other input parameters.
If you go ahead and click “Query” here, this is going to issue a request to your ArcGIS server with those inputs. We can see that we’ve capped out and we’ve hit the max number of results. But here we can see that we’re returning all the different fields.
You can adjust this. So, maybe we only want to return the “MATERIAL”. I can go ahead and copy that and set that as my “Out Field”. Then if I go ahead and click “Query”, we’re going to get a list of the different materials.
We can see that “Cast Iron” is one of the material options. I could then adjust my “Where” clause to show me all of the water lines where the “MATERIAL = ‘Cast Iron’”. For string values or text, we have to include these single quotes, that’s just ArcGIS server syntax. If it’s a number, then you don’t need any quotes. If I click “Query”, we’re going to see now we’ve got “1224” water lines that are cast iron. We could continue to go on and on and on.
The relevance of this to Workflow is that there’s a query layer activity that includes these different inputs that we’re seeing here. We’ll jump over to the Workflow Designer. If you search for the “Query Layer” activity and drag it onto the design surface, there’s going to be some “Inputs” available.
To get started you either need to provide a “URL” to the map service or feature service for that layer. Or you can also retrieve the layer using an activity within Workflow called Get Layer and supply that as input. Those are two options. And then the rest of these parameters mimic that rest endpoint. So, this would be your “Where” clause, whether you want to “Return Geometry”, what “Output Fields” you want to include, whether you want to “Return Distinct Values”, and so on.
Let’s go ahead and test this out. I’ll jump back to our query here. I’ll go back up one level so that here we have this “FeatureService” URL down to the layer level meaning here there’s this ID. I’m going to go ahead and copy this URL and jump over here and paste it in here. You can see here that it’s included.
And then this is where we can adjust our “Where” clause. So, if I wanted to do the same “Where” clause, I could say where the “MATERIAL = Cast Iron”. Let’s set the “Return Geometry” to “true” and let’s set the “Output Fields” to “*”.
There are a number of ways to test how this works. You can look at the network tab, you can use the console within your application to further debug and see the results. I’ll be touching on that in a separate video. For now, we’re just going to do a log to see the count of the features returned.
I’m going to add an “Alert” here and I’m going to do “=$query1”.
For the output there are three options. You can get the first “feature”, you can get all of the “features”, or you can get the “result” which is going to be an Esri feature set with the entire results. I’m going to go into the “features” here, add a period, and then there’s this “length” property which will just give me the number of records returned from the query.
Let’s expand this. So, it’s telling us that there’s this number that’s not a valid input. You can see that the length is a number, but it needs to be text. So, we need to convert this to a string or a text value. I’ll use “toString” to do that.
We’ll get another error. We need to add these parentheses to make sure that we are calling this function to convert the number to text. So, for this to work it need to be “toString()”.
I’m going go ahead and click “OK” and let’s run this in our “Workflow Sandbox”. Here you can see we’re getting “1224” as the number of features that have been performed from our query. If we look at the “Network” tab we can see that there’s this web “Request” that gets sent. And if we look at the “Payload”, this is our “where” clause where the “MATERIAL = Cast Iron”.
Then if we “Preview” this, this is the response showing all of those “features” that get returned. We can drill in and look at the “attributes” of each individual feature, “geometry”.
We can also modify this query, for example, maybe we want to say, “AND DIAMETER <= 150” meters.
Let’s go ahead and rerun that. I’ll click “OK”, clear this, and run this. You can see we’re getting “551” results now, so a lot smaller.
If we look at our query and look at the “Payload”, we can see that my “where” clause is getting passed through. And then we can look at this “Preview” and see that there’s 551 results.
Let’s jump back to our workflow. I’m going to delete this connector here and use a “Get Map Extent” activity. This will allow us to get the current map extent and filter our query based on the map extent.
We want to find “Water Lines” that are of type “Cast Iron” with a diameter that is “<= 150” within the current map extent. So, I’m going to pass that map extent using this “extent” property to our “Geometry” input here. I’ll go ahead and rerun this.
And now we can see that we’re only getting “7” features within the current map extent that are cast iron and less than or equal to 150. So, we’re starting to interact with the map to perform these number of operations.
Now in this scenario here I used a “URL” as input. The other option available is to use a layer.
I’m going to search for the “Get Layer” activity and drag this in. This is an activity that requires a “Layer id” as input. For the most part, this is going to be the name of the layer in your Web Map that you are using. So, in my case, that layer name is called “Water Lines”. We can confirm that if we go to my web map. Here is my web map and here you can see my “Layer” name is called “Water Lines”.
So, I’ve supplied that as “Input”, it’s called “Water Lines”. It gives me an “Output” “Layer” and I can go into here and type “=$layer1.layer”.
Now if I rerun this you can see there’s this “GetLayer” operation that fires. And then here we can see we’ve got “7” features. If we look at our query it doesn’t look any different, but we can now confirm that we’re actually using the layer from the web map as input rather than a hard coded URL.
Hopefully that gave you an overview on how you can use the Query Layer activity within Workflow to return different features and results. Bye for now!
Want to learn more about the capabilities of VertiGIS Studio Workflow? Click the button below for more information on what is possible with VertiGIS Studio Workflow.