How to Automate Lat/Long Coordinates when new a feature is created?

5328
6
01-13-2016 08:40 PM
KelseyNovacek1
New Contributor

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

0 Kudos
6 Replies
JayantaPoddar
MVP Esteemed Contributor

Hi Kelsey,

I found this link on populating XY fields in SQL Server 2008 R2 using SQL trigger.

arcgis server - Populate X and Y fields in SDE Point Data Using SQL trigger - Geographic Information...

N.B.: This will populate XY fields only when a new record is added, not for modification of existing point location.

Hope it helps!



Think Location
KelseyNovacek1
New Contributor

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

0 Kudos
JoeBorgione
MVP Esteemed Contributor

The triggers I've used for years in SDE/SQL are pulled on the A table of a given feature class.

That should just about do it....
0 Kudos
KelseyNovacek1
New Contributor

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?

0 Kudos
JoeBorgione
MVP Esteemed Contributor

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.

That should just about do it....
0 Kudos
ThomasColson
MVP Frequent Contributor
0 Kudos