making use of query layers & spatial views
DESCRIPTION
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.TRANSCRIPT
Making Use of Query Layers & Spatial Views
Michael OlkinTown of Amherst, MA
www.amherstma.gov/maps
Technical Talk in Lightning Format
Will this work?
Query Layers & Spatial Views
• Data is Direct from your Databases• Data Represented via SQL • Work with ArcGIS for Desktop & Server*
What Are They?
Query Layer
•SQL Query in ArcGIS Desktop
Spatial View
•SQL Query in your relational database
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
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
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
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
Create a Query Layer in ArcMap
Make a Query Layer with ArcToolbox
Data Management Tools -> Layers & Query Views -> Make Query Layer
Resulting Query Layer
Query Layer in Action
• Amherst Work Orders ArcGIS Online Map
Work Order Software geocodes & stores X/Y coordinates in a table
Yay! Query Layer Goodness!
Because every presentation needs a smiling cat
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)
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>
Spatial View: a regular database view
• Edit it in your database, like any other viewSELECT 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
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 OBJECTIDSELECT 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,
Stacked Parcels with a Spatial View
Yay! Spatial View Goodness!
Because every presentation needs a smiling cat
Making Use of Query Layers & Spatial Views
Michael OlkinTown of Amherst, MA
www.amherstma.gov/maps