Query last or distinct record
I'm trying to figure out how to query the last record in one of my layers, i.e., the maximum OBJECTID, and store it in a feature set. I'll then use that feature set as a template to add a new row to a related table.
In ArcMap, the Select by Attributes query would be OBJECTID in (SELECT max(OBJECTID) FROM <layername>). Is there a way to do something similar in GE?
I've been trying to do it with Query Task, but it doesn't appear to support the same where clause syntax as ArcMap.
Functionally, I don't necessarily need the last record. I just need to get a single feature from and existing dataset into a feature set, create a new feature set based on it, and then use that to add a row to a non spatial table.
0
-
Additional snafu while testing. I'm querying a spatial layer and want to use the resulting feature set to add a new row to a table. But even when the scheme between the spatial layer and the table are identical, it's not working.
I'm using the Add Features activity to do the add to the table, and I can confirm that it does when when adding features from a feature set that was generated by a table.0 -
Hi John,
If you are looking for the max objectID from a layer for example, then what I would suggest is in the Query Task, specify the "Order By Fields" . Once the features in the feature set are sorted, you can easily grab the first or last item from the feature set using this notation: featureset.Features.First() or featureset.Features.Last()
Once you find the feature you want to add to a data table, you can use the AddDataTableRow activity to insert a new row into the non-spatial table.
_img_ alt="User-added image" src="https://latitudegeo--c.na53.content.force.com/servlet/rtaImage?eid=90760000000TUJN&feoid=Body&refid=0EM60000000Lzs5"_/_img_
The dataTable would be the non-spatial table. The Values parameter is a list of values you want to add to the table. If the column in the feature set is in the same order as your data table, then you can use this notation to add the values:
featureSet.Features.First().Attributes.Values
Otherwise, you would need to manually assign the right column value to the correponding table column using a series of Assign activities like this:
dataTable.Rows(10)("Parcel") = featureSet.Features.First().Attributes("ParcelName")
(https://support.geocortex.com/essentialsGSCCodeGallery?sub-nav=codegall&main-nav=essentials&#!/feedtype=SINGLE_ARTICLE_DETAIL&criteria=BESTANSWERS&id=kA460000000bljhCAA) This article here might help as well if you have a larger feature set to add/merge.
I hope this helps.
Regards,
Carmen0 -
To use Order By Fields in a query task your ArcGIS Server version has to be 10.1 or higher. 0 -
That .First() .Last() syntax is a great tip, thanks! 0 -
_img_ alt="WorkflowExample" src="https://latitudegeo--c.na53.content.force.com/servlet/rtaImage?eid=907f2000000kAKN&feoid=Body&refid=0EMf2000000fyn5"_/_img_
Here is how I did this sort of idea but was concerned with Distinct. The "Value" for the dictionary was: string.Join(",", stringList.Distinct)0
Please sign in to leave a comment.
Comments
5 comments