1 of 21

URISA Texas Speaker Series

January 25, 2022

Thank you to our Corporate Sponsors!

For questions or comments, contact URISA Texas: info@urisatexas.org

Or visit our website for more information: urisatexas.org

with URISA Texas

Scan Here if you

want to Volunteer

2 of 21

Advanced Enterprise / SQL Server Database Topics

​

​

John May

Esciences

3 of 21

Topics covered today

1. Triggers -

Rules (SDE vs Non-SDE)

Considerations

2. Spatial and non-spatial Views

Creating a spatial view in SQL Server

Creating non-spatial views

Use case examples

3. Integrating your GIS data with SQL Server Reporting Services

Using the Visual Studio shell

Simple report design

Calling a report from your GIS data

4. Measurements in WGS

​

4 of 21

Essential reading

  • SQL Resources

https://www.techonthenet.com/sql/index.php

https://www.w3schools.com/sql/

https://www.codecademy.com/learn/learn-sql

5 of 21

Essential reading

6 of 21

Triggers

Rules

  • One will do in most cases
  • DO NOT create new records in SDE registered tables
  • Pay attention to the order of SQL execution
  • Test results before deploying
  • Think about other triggers that may be fired

7 of 21

Triggers

Template

CREATE TRIGGER [DATABASENAME].[TableName_TR] ON [DATABASENAME].[TableName]

AFTER INSERT,UPDATE,DELETE

AS

BEGIN

SET NOCOUNT ON;

​

-- Insert statements for trigger here

​

/***Update Longitude and Latitude columns***/

UPDATE PointFeatureClass set Latitude= Shape.STY;

UPDATE PointFeatureClass set Longitude = Shape.STX;

​

END

GO

8 of 21

Triggers

​

​

SSMS Demo

Collector Demo

9 of 21

Database Views

Rules

  • Can be spatial AND non-spatial
  • Can be used for web mapping
  • Can be used to show real-time joins on web
  • Can contain more than one geometry
  • Do not have to be registered with SDE
  • Use to transform data

10 of 21

Database Views

Template – Create a View from a Feature Class

CREATE VIEW [DATABASENAME].[ViewName]

AS

SELECT

,[OBJECTID]

,OTHER ATTRIBUTES

,[Shape]

FROM [DATABASENAME].[FeatureClass]

11 of 21

Database Views

Template – Create mappable points from a table

SELECT

CAST(ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS INT) AS OBJECTID,

FC.Attribute(s),

Shape = geometry::STPointFromText('Point('+cast(cast(FC.longitude as float)as varchar)+' '+cast(cast(FC.latitude as float)as varchar)+')', 4326)

FROM TableWithCoordinates FC;

12 of 21

Database Views

Template – Create mappable lines from a table

SELECT

CAST(ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS INT) AS OBJECTID,

FC.Attribute(s),

Shape = geometry::STLineFromText('LINESTRING('+cast(cast(FC.longitude as float)as varchar)+' '+cast(cast(FC.latitude as float)as varchar)+','+cast(cast(FC.Longitude2 as float)as varchar)+' '+cast(cast(FC.Latitude2 as float)as varchar)+')', 4326)

FROM TableWithCoordinates FC;

13 of 21

Database Views

Template – Create mappable points and lines from a table

SELECT

CAST(ROW_NUMBER() OVER(ORDER BY (SELECT NULL)) AS INT) AS OBJECTID,

FC.Attribute(s),

ShapePoint = geometry::STPointFromText('Point('+cast(cast(FC.longitude as float)as varchar)+' '+cast(cast(FC.latitude as float)as varchar)+')', 4326),

ShapeLine = geometry::STLineFromText('LINESTRING('+cast(cast(FC.longitude as float)as varchar)+' '+cast(cast(FC.latitude as float)as varchar)+','+cast(cast(FC.Longitude2 as float)as varchar)+' '+cast(cast(FC.Latitude2 as float)as varchar)+')', 4326)

FROM TableWithCoordinates FC;

14 of 21

Database Views

​

​

SSMS Demo

Web Mapping Demo

15 of 21

Integration with SSRS

Rules

  • Use Visual Studio Integrated Shell
  • Attribute reports require parameterization
  • You need SQL skills
  • Link to reports instantiated with trigger
  • You can map spatial data on the report
  • It’s the Wild West

16 of 21

Integration with SSRS

Handy SQL Hacks for reports

Add linear measurements to a report

​

SELECT geography::STGeomFromText([shape].STAsText(),4326).STLength() * 3.28084 as LengthFeet

FROM LineFeatureClass;

17 of 21

Integration with SSRS

Handy SQL Hacks for reports

Add area measurements to a report

​

SELECT geography::STGeomFromText([shape].STAsText(),4326).STArea() * 0.000247105 as Acres

FROM PolyFeatureClass;

18 of 21

Integration with SSRS

Handy SQL Hacks for reports

Add a URL for a Google Map to show starting point of a line

​

'https://www.google.com/maps/search/?api=1&query=' + SubString(shape.STStartPoint().ToString(),28,8) +'%2C' + SubString(shape.STStartPoint().ToString(),8,8) as GoogleLink

FROM LineFeatureClass

19 of 21

Integrating with SSRS

​

​

SSRS Demo

Web Mapping Demo

20 of 21

Training

21 of 21

URISA Texas Speaker Series

Resources

For questions or comments, contact URISA Texas: info@urisatexas.org

  • URISA Texas Website: https://www.urisatexas.org/

​

  • Recorded Speaker Series Videos: https://goo.gl/VfDLUi