Top Banner
Making Use of Query Layers & Spatial Views Michael Olkin Town of Amherst, MA www.amherstma.gov/maps
20

Making Use of Query Layers & Spatial Views

Jun 20, 2015

Download

Technology

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.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Making Use of Query Layers & Spatial Views

Making Use of Query Layers & Spatial Views

Michael OlkinTown of Amherst, MA

www.amherstma.gov/maps

Page 2: Making Use of Query Layers & Spatial Views

Technical Talk in Lightning Format

Will this work?

Page 3: Making Use of Query Layers & Spatial Views

Query Layers & Spatial Views

• Data is Direct from your Databases• Data Represented via SQL • Work with ArcGIS for Desktop & Server*

Page 4: Making Use of Query Layers & Spatial Views

What Are They?

Query Layer

•SQL Query in ArcGIS Desktop

Spatial View

•SQL Query in your relational database

Page 5: Making Use of Query Layers & Spatial Views

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

Page 6: Making Use of Query Layers & Spatial Views

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

Page 7: Making Use of Query Layers & Spatial Views

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

Page 8: Making Use of Query Layers & Spatial Views

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

Page 9: Making Use of Query Layers & Spatial Views

Create a Query Layer in ArcMap

Page 10: Making Use of Query Layers & Spatial Views

Make a Query Layer with ArcToolbox

Data Management Tools -> Layers & Query Views -> Make Query Layer

Page 11: Making Use of Query Layers & Spatial Views

Resulting Query Layer

Page 12: Making Use of Query Layers & Spatial Views

Query Layer in Action

• Amherst Work Orders ArcGIS Online Map

Work Order Software geocodes & stores X/Y coordinates in a table

Page 13: Making Use of Query Layers & Spatial Views

Yay! Query Layer Goodness!

Because every presentation needs a smiling cat

Page 14: Making Use of Query Layers & Spatial Views

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)

Page 15: Making Use of Query Layers & Spatial Views

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>

Page 16: Making Use of Query Layers & Spatial Views

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

Page 17: Making Use of Query Layers & Spatial Views

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,

Page 18: Making Use of Query Layers & Spatial Views

Stacked Parcels with a Spatial View

Page 19: Making Use of Query Layers & Spatial Views

Yay! Spatial View Goodness!

Because every presentation needs a smiling cat

Page 20: Making Use of Query Layers & Spatial Views

Making Use of Query Layers & Spatial Views

Michael OlkinTown of Amherst, MA

www.amherstma.gov/maps