Tutorial 2: Creating new maps
This is the second of a series of three tutorials that show you how to analyze geospatial data with Db2® and Esri ArcGIS:
- If you want to learn how to work with base maps first, view the first tutorial of this series: Tutorial 1: Working with base maps.
- The third tutorial of this series, Tutorial 3: Using your own geospatial data, shows you how to upload and use your own geospatial data.
This tutorial shows you how to carry out the following tasks:
- Create a new map.
- Obtain information about an area on the map.
Time required
10 minutesScenario
Difficulty
Beginner
Audience
Data scientists
System requirements
- Windows 7 Ultimate, Professional and Enterprise (32 bit and 64 bit [EM64T])
- Windows 8 Pro and Enterprise (32 bit and 64 bit [EM64T])
- Windows 8.1 Pro and Enterprise (32 bit and 64 bit [EM64T])
Prerequisites
This scenario uses an Esri ArcGIS for Desktop installation that is connected to Db2 to visualize and analyze geospatial data (see Connecting Esri ArcGIS for Desktop). The data for this scenario is already loaded into your Db2 database. This scenario assumes that you already know how to work with base maps.
Creating a new map that shows tornado density
Our first query will be used to create a map of tornadoes that occurred in the year 2009 or later. The corresponding SQL query will be transferred to Db2 and run there as an in-database query, which lets you benefit from the performance and scalability of Db2.
Procedure
SELECT COUNTY.OBJECTID, COUNTY.NAMELSAD, COUNTY.SHAPE,
COALESCE(tornadoes_PER_COUNTY.TORNADO_COUNT,0)
/ ((COUNTY.ALAND + COUNTY.AWATER)
* DECIMAL('3.86102159E-7', 20, 15)) AS COUNTY_TORNADO_DENSITY
FROM SAMPLES.GEO_COUNTY AS COUNTY
LEFT OUTER JOIN (
SELECT COUNTY.OBJECTID, COUNT(COUNTY.OBJECTID) AS TORNADO_COUNT
FROM SAMPLES.GEO_COUNTY AS COUNTY, SAMPLES.GEO_TORNADO AS TORNADO
WHERE INT(TORNADO.YR) >= 2009
AND DB2GSE.ST_INTERSECTS(TORNADO.SHAPE, COUNTY.SHAPE) = 1 SELECTIVITY 0.00001
GROUP BY COUNTY.OBJECTID) AS tornadoes_PER_COUNTY
ON COUNTY.OBJECTID = tornadoes_PER_COUNTY.OBJECTID
Creating a new map that indicates high risk areas
It might also be interesting for an insurance company to identify high risk counties, that is, counties that have both a high tornado density, and therefore a high risk of tornado damage, and a high total value of insured property. To do this, we can create a new query layer that joins data from the customer, tornado, and county tables, and uses that data to calculate a risk factor. In this scenario, we will calculate a simple risk factor based on the tornado density and the total value of all policies.
Procedure
SELECT COUNTY.OBJECTID, COUNTY.SHAPE, COUNTY.NAMELSAD, COALESCE(CUSTOMERS,0) CUSTOMERS,
COALESCE(tornadoes_PER_COUNTY.TORNADO_COUNT,0)
/ ((COUNTY.ALAND + COUNTY.AWATER)
* DECIMAL('3.86102159E-7', 20, 15))
* COALESCE(CUSTOMERS,1) AS COUNTY_TORNADO_RISK
FROM SAMPLES.GEO_COUNTY COUNTY
LEFT OUTER JOIN (
SELECT COUNTY.OBJECTID, COUNT(COUNTY.OBJECTID) AS TORNADO_COUNT
FROM SAMPLES.GEO_COUNTY AS COUNTY, SAMPLES.GEO_TORNADO AS TORNADO
WHERE INT(TORNADO.YR) >= 2009
AND DB2GSE.ST_INTERSECTS(TORNADO.SHAPE, COUNTY.SHAPE) = 1 SELECTIVITY 0.00001
GROUP BY COUNTY.OBJECTID) AS tornadoes_PER_COUNTY
ON COUNTY.OBJECTID = tornadoes_PER_COUNTY.OBJECTID
LEFT OUTER JOIN (
SELECT COUNTY.OBJECTID, COUNT(CUSTOMER.OBJECTID) AS CUSTOMERS
FROM SAMPLES.GEO_COUNTY AS COUNTY, SAMPLES.GEO_CUSTOMER AS CUSTOMER
WHERE CUSTOMER.INSURANCE_VALUE > 2000000
AND DB2GSE.ST_INTERSECTS(CUSTOMER.SHAPE, COUNTY.SHAPE) = 1 SELECTIVITY 0.00001
GROUP BY COUNTY.OBJECTID) AS CUSTOMERS_PER_COUNTY
ON COUNTY.OBJECTID = CUSTOMERS_PER_COUNTY.OBJECTID
Getting detailed information on counties
Procedure
- If you open the attribute table for the new query layer, you can see, in the CUSTOMERS column, how many customers there are in each county.
- You can use the ArcMap identify tool to view information about an area on the map. First, let's zoom in on an area of the map, then select the identify tool in the menu bar.
- Note the small icon with the letter "i" beside the pointer when it hovers over the map. Use the identify tool the same way you use the zoom-function: Press and hold the Shift-key and the left-mouse-key, and drag the pointer to create a rectangle frame on the map. Then, release the left-mouse-key.
- A window appears that displays information about each county in the selected area, such as its ID, name, the number of customers, and the tornado density. Each time you select a county from the list, the values in the table are updated and the county flashes green on the map. When you've finished exploring the data for individual counties, close the table and set the map scale back to 1:25000000. Close the identify table and clear all check boxes except the base map.