I am attempting to have the latitude & longitude fields be automatically populated when a user adds a new point feature via my web application. I am using a SDE point feature service with ArcGIS Server 10.2.2 with SQL Server 2012. I have come across some comments that it might be able to employ a SQL Server trigger in the table but I have no experience with triggers or how to code it. Basically if anyone has any information they can point me to would be much appreciative.
-Thanks
Hi Kelsey,
I found this link on populating XY fields in SQL Server 2008 R2 using SQL trigger.
N.B.: This will populate XY fields only when a new record is added, not for modification of existing point location.
Hope it helps!
Thank you for the link. Can you please confirm this would be the correct syntax if my feature service is named “EVENT_POINTS” with “latitude” & “longitude” named fields. And do I add just add this to the trigger folder under the feature service in SQL Server?
Thank you.
CREATE TRIGGER [XY_calc] ON dbo.EVENT_FEATURES
AFTER INSERT AS
UPDATE dbo.EVENT_FEATURES
SET latitude = Shape.STX, longitude = Shape.STY
WHERE latitude is null or longitude is null
The triggers I've used for years in SDE/SQL are pulled on the A table of a given feature class.
I have included the code from the link into my trigger folder in SQL Server. The Latitude and Longitude data is only added after I manually execute the code and refresh my edits. Do you know how to get the trigger to execute automatically as soon as a point is created?
Here's another link you should consider: SQL Trigger in Versioned SDE
This is basically what I've been doing with two fields since version 8.3 and SQL 2005. My write ups on sql triggers were on the old forum, and they don't seem to be available to a google search.