Michael Olkin
Town of Amherst, MA
Do you ever have the need to directly connect to a “non-spatial” database and display this data in a spatial format? Are you tired of copying and converting data in order to show it on a map? Query Layers and Spatial Views provide some powerful ways to directly display enterprise data in a spatial format. The purpose of this presentation is to demonstrate how to make use of these methods for spatially empowering your data.
3. Query Layers & Spatial Views
• Data is Direct from your Databases
• Data Represented via SQL
• Work with ArcGIS for Desktop & Server*
4. What Are They?
Query Layer
•SQL Query
in ArcGIS
Desktop
Spatial View
•SQL Query
in your
relational
database
5. What Do They Do?
Query Layer
•Spatial Data
from tabular
sources
•Supports
ST_Geometry
Spatial View
•A View within
a Geodatabase
•Represents
existing spatial
data
6. Query Layer Use Case
• Scenario
– MassGIS Parcel
Standard unique
centroid-based
“LOC_ID”
– When I split a parcel, I
want to know whether
I need to change the
LOC_ID of the original
parcel
7. Show the LOC_ID Points via ST_Geometry
SELECT MAP_PAR_ID, LOC_ID,
CAST('POINT (' + CAST(CAST(substring(LOC_ID,3,6) as int) AS varchar) + ' ' +
CAST(CAST(substring(LOC_ID,10,7) as int) AS varchar) + ')' AS geometry) AS SHAPE,
'POINT (' + CAST(CAST(substring(LOC_ID,3,6) as int) AS varchar) + ' ' +
CAST(CAST(substring(LOC_ID,10,7) as int) AS varchar) + ')' as [ReadTheGeometry],
FROM <MyParcelFeatureClass>
X Y
8. Show the LOC_ID Points via ST_Geometry
SELECT MAP_PAR_ID, LOC_ID,
CAST('POINT (' + CAST(CAST(substring(LOC_ID,3,6) as int) AS varchar) + ' ' +
CAST(CAST(substring(LOC_ID,10,7) as int) AS varchar) + ')' AS geometry) AS SHAPE,
'POINT (' + CAST(CAST(substring(LOC_ID,3,6) as int) AS varchar) + ' ' +
CAST(CAST(substring(LOC_ID,10,7) as int) AS varchar) + ')' as [ReadTheGeometry],
FROM <MyParcelFeatureClass>
X Y
12. Query Layer in Action
• Amherst Work Orders ArcGIS Online Map
Work Order Software
geocodes & stores X/Y
coordinates in a table
13. Yay! Query Layer Goodness!
Because every presentation needs a smiling cat
14. Spatial Views
• Warning! Legacy Solution for GDBs stored in a
RDBMS (ie., ArcSDE)
• More robust than an ArcGIS Desktop Join
• Requires ArcSDE Command Line Tools
(to be installed on the client)
15. Setting Up a Spatial View
• Command Line (ugh…ok, not so bad)
• Keep it simple on the setup; edit later
• GDB table registry references source feature class
sdetable -o create_view
-T <NewViewName>
-t <TheSpatialTable>,<TheJoinedTable>
-c SHAPE,<TheJoinedTable>.<Field1>,TheSpatialTable.<Field1>
-w "<TheJoinedTable>.<Field1> = TheSpatialTable.<Field1>"
-i sde:sqlserver:<InstanceName>
-D <DatabaseName>
-u <AdminUserName> -p <AdminPassword>
16. Spatial View: a regular database view
• Edit it in your database, like any other view
SELECT P.SHAPE,
ROW_NUMBER() OVER(ORDER BY c.PID) as OBJECTID,
C.PID,
P.Map_Lot,
C.PIN as MapBlockLot,
C.Location,
C.Number_Char as AddressNum,
C.Street,
C.Owner_Name
FROM <TheSpatialTable> AS P
LEFT OUTER JOIN <TheJoinedTable> AS C
ON P.Map_Lot = C.Map_Lot
SQL Server tsql example: ROW_NUMBER is used here to create a unique OBJECTID
17. Spatial View: One to Many Join!
• “Fake Out” ArcGIS with a clever query
– ArcGIS draws stacked features for duplicates if each one
has a unique OBJECTID
SELECT P.SHAPE,
ROW_NUMBER() OVER(ORDER BY c.PID) as OBJECTID,
C.PID,
P.Map_Lot,
C.PIN as MapBlockLot,
C.Location,
C.Number_Char as AddressNum,
C.Street,
C.Owner_Name
FROM <TheSpatialTable> AS P
LEFT OUTER JOIN <TheJoinedTable> AS C
ON P.Map_Lot = C.Map_Lot
SQL Server tsql example: ROW_NUMBER is used here to create a unique OBJECTID
ROW_NUMBER() OVER(ORDER BY c.PID) as OBJECTID,
19. Yay! Spatial View Goodness!
Because every presentation needs a smiling cat
20. Making Use of
Query Layers & Spatial Views
Michael Olkin
Town of Amherst, MA
www.amherstma.gov/maps
Hinweis der Redaktion
This will work with the MassGIS Parcel Standard:SELECTMAP_PAR_ID,LOC_ID,CAST('POINT ('+CAST(CAST(substring(LOC_ID,3,6)asint)ASvarchar)+' '+CAST(CAST(substring(LOC_ID,10,7)asint)ASvarchar)+')'ASgeometry)ASSHAPE,'POINT ('+CAST(CAST(substring(LOC_ID,3,6)asint)ASvarchar)+' '+CAST(CAST(substring(LOC_ID,10,7)asint)ASvarchar)+')'as[ReadTheGeometry],FROM<MyParcelFeatureClass>The “ReadTheGeometry” field is just there in order to illustrate the ST_Geometry syntax for points.
Make sure that you check the “Show advanced options” box & set the proper coordinate system & transformation. The transformation does matter: http://gisobsessed.blogspot.com/2014/04/be-transformative.html
Geometry comes from only one table; cannot create a view that combines multiple geometry sources