-
Notifications
You must be signed in to change notification settings - Fork 1
Open
Description
ts.insertsite is missing the trigger to insert the lat-long columns. Here is the SQL Server version.
CREATE TRIGGER [NDB].[TR_Sites_BBox] ON [NDB].[Sites]
AFTER INSERT, UPDATE
AS
IF (UPDATE(geog))
BEGIN
-- for points, populate box columns with coords of points
IF EXISTS (SELECT * FROM inserted WHERE geog.STGeometryType() = 'POINT')
BEGIN
UPDATE
NDB.Sites
SET
LatitudeNorth = i.geog.Lat,
LatitudeSouth = i.geog.Lat,
LongitudeEast = i.geog.Long,
LongitudeWest = i.geog.Long
FROM
NDB.Sites s JOIN
INSERTED i ON s.SiteID = i.SiteID
WHERE
i.geog.STGeometryType() = 'POINT'
END
-- for polygons, populate box columns from poly envelopes
IF EXISTS (SELECT * FROM inserted WHERE geog.STGeometryType() = 'POLYGON')
BEGIN
UPDATE
NDB.Sites
SET
LatitudeNorth = geometry::STGeomFromWKB(i.geog.STAsBinary(), 4326).STEnvelope().STPointN(3).STY,
LatitudeSouth = geometry::STGeomFromWKB(i.geog.STAsBinary(), 4326).STEnvelope().STPointN(1).STY,
LongitudeEast = geometry::STGeomFromWKB(i.geog.STAsBinary(), 4326).STEnvelope().STPointN(3).STX,
LongitudeWest = geometry::STGeomFromWKB(i.geog.STAsBinary(), 4326).STEnvelope().STPointN(1).STX
FROM
NDB.Sites s JOIN
INSERTED i ON s.SiteID = i.SiteID
WHERE
i.geog.STGeometryType() = 'POLYGON'
END
END
GO
ALTER TABLE [NDB].[Sites] ENABLE TRIGGER [TR_Sites_BBox]
GO
Metadata
Metadata
Assignees
Labels
No labels