Skip to content

Commit

Permalink
Merge pull request #378 from Teradata/flood_proximity
Browse files Browse the repository at this point in the history
incorporated review comments for flood proximity
  • Loading branch information
DougEbel authored Aug 30, 2023
2 parents 8ece122 + 3900c80 commit 298906e
Showing 1 changed file with 48 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
"<ol style = 'font-size:16px;font-family:Arial'>\n",
" <li><b style = 'color:#00b2b1'>Inspect Geospatial data</b> using client-side tools and visualization</li>\n",
" <li><b style = 'color:#00b2b1'>Analyze Proximity at Scale</b> using ClearScape Analytic functions to calculate flood location centroids and risk boundaries, and then apply the analysis at scale to analyze every New Zealand address and asses high, medium, and low risk based on proximity to the flood zones</li>\n",
" </ol>"
" </ol>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial'>For the demo we have taken approximately 60k address sample from 1.6million addresses of North Island."
]
},
{
Expand Down Expand Up @@ -107,9 +109,9 @@
},
"outputs": [],
"source": [
"#%run -i ../run_procedure.py \"call get_data('DEMO_NZFloods_cloud');\"\n",
"%run -i ../run_procedure.py \"call get_data('DEMO_NZFloods_cloud');\"\n",
" # takes about 30 seconds, estimated space: 0 MB\n",
"%run -i ../run_procedure.py \"call get_data('DEMO_NZFloods_local');\" \n",
"#%run -i ../run_procedure.py \"call get_data('DEMO_NZFloods_local');\" \n",
"# takes about 30 seconds, estimated space: 3 MB"
]
},
Expand Down Expand Up @@ -182,7 +184,7 @@
"source": [
"print('NZ Street Addresses with Lat, Lon, and POINT object:')\n",
"ipydisplay(tdf_addrs)\n",
"print('Sample 10k Addresses:')\n",
"print('Sample 60k Addresses:')\n",
"ipydisplay(tdf_addrs.shape)"
]
},
Expand Down Expand Up @@ -225,7 +227,7 @@
"source": [
"<h2 style = 'font-size:20px;font-family:Arial;color:#E37C4D'>2.3 Putting the Flood Zones on a Map</h2>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial'>This demonstration uses the <a href = 'https://python-visualization.github.io/folium/'>folium</a> package along with <a href = 'https://geopandas.org/en/stable/'>geopandas</a> to overlay the flood zone data on an interactive map</p>"
"<p style = 'font-size:16px;font-family:Arial'>This demonstration uses the <a href = 'https://python-visualization.github.io/folium/'>folium</a> package along with <a href = 'https://geopandas.org/en/stable/'>geopandas</a> to overlay the flood zone data on an interactive map. We will start by showing the basic map (named \"m\").</p>"
]
},
{
Expand All @@ -251,7 +253,7 @@
"source": [
"<h2 style = 'font-size:20px;font-family:Arial;color:#E37C4D'>2.4 Draw the Flood Regions</h2>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial'>Use Pandas, GeoPandas, and Folium to paint the flood zones</p>"
"<p style = 'font-size:16px;font-family:Arial'>Use Pandas, GeoPandas, and Folium to paint the flood zones on top of the basic map (named \"m\")</p>"
]
},
{
Expand Down Expand Up @@ -288,8 +290,7 @@
"source": [
"<h2 style = 'font-size:h2px;font-family:Arial;color:#E37C4D'>2.5 Calculate Centroids</h2>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial'>In order to properly compute geometric properties, in this case centroids, of the geometries, we need to project the data to a projected coordinate system.</p>\n",
"\n"
"<p style = 'font-size:16px;font-family:Arial'>A centroid is the geometric centre of the object or shape. In order to properly compute geometric properties, in this case centroids, of the geometries, we need to project the data to a projected coordinate system.</p>\n"
]
},
{
Expand Down Expand Up @@ -348,6 +349,13 @@
"m"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<p style = 'font-size:16px;font-family:Arial'>In the map above, the blue markers are the centroid of each of the flood zones (1-7)."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand All @@ -357,7 +365,7 @@
" <ul style = 'font-size:16px;font-family:Arial'>\n",
" <li><b>Calculate Centroids and Buffer Zones</b> around the Flood Zone shapes</li>\n",
" <li><b>Map the Buffer Zones</b> Using client-side tools</li>\n",
" <li><b>Calculate Address Proximity</b> Analyze all 1.6 Million Records in-Database in seconds</li>\n",
" <li><b>Calculate Address Proximity</b> Analyze all 60k Records in-Database in seconds</li>\n",
" <li><b>Map Degree of Risk</b> Based on Proximity calculations</li>\n",
" </ul>"
]
Expand All @@ -368,7 +376,8 @@
"source": [
"<h2 style = 'font-size:20px;font-family:Arial;color:#E37C4D'>3.1 Calculate Centroids and Buffer Zones in-Database</h2>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial'>Use the <a href = ''>centroid</a> property as well as the <a href = 'https://docs.teradata.com/r/Lake/Teradata-Package-for-Python-Function-Reference-on-VantageCloud-Lake/Geospatial/teradataml-GeoDataFrame/Methods/Geospatial-Specific-Methods/Methods-for-All-Types-of-Geometries/buffer'>buffer</a> method of the teradataml DataFrame to inspect and calculate this data in-database. Note this python syntax is automaticaly translated to SQL to run in the Vantage system. The <a href = 'https://docs.teradata.com/r/Teradata-VantageTM-Geospatial-Data-Types/July-2021/ST_Geometry-Constructors-and-Methods/ST_Centroid-Method'>ST_Centroid</a> and <a href = 'https://docs.teradata.com/r/Teradata-VantageTM-Geospatial-Data-Types/July-2021/ST_Geometry-Constructors-and-Methods/ST_Buffer-Method'>ST_Buffer</a> SQL functions can be run directly as well to perform the same calculations.</p>"
"<p style = 'font-size:16px;font-family:Arial'>Use the <a href = ''>centroid</a> property as well as the <a href = 'https://docs.teradata.com/r/Lake/Teradata-Package-for-Python-Function-Reference-on-VantageCloud-Lake/Geospatial/teradataml-GeoDataFrame/Methods/Geospatial-Specific-Methods/Methods-for-All-Types-of-Geometries/buffer'>buffer</a> method of the teradataml DataFrame to inspect and calculate this data in-database. Note this python syntax is automaticaly translated to SQL to run in the Vantage system. The <a href = 'https://docs.teradata.com/r/Teradata-VantageTM-Geospatial-Data-Types/July-2021/ST_Geometry-Constructors-and-Methods/ST_Centroid-Method'>ST_Centroid</a> and <a href = 'https://docs.teradata.com/r/Teradata-VantageTM-Geospatial-Data-Types/July-2021/ST_Geometry-Constructors-and-Methods/ST_Buffer-Method'>ST_Buffer</a> SQL functions can be run directly as well to perform the same calculations.</p>\n",
"<p style = 'font-size:16px;font-family:Arial'>For the following steps, we will focus on Zone 7 located in the southeast side of North Island around Hastings.</p>"
]
},
{
Expand All @@ -395,7 +404,7 @@
"source": [
"<h2 style = 'font-size:20px;font-family:Arial;color:#E37C4D'>3.2 Map the Buffer</h2>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial'>Retrieve the buffer shape to the client, and use GeoPandas methods to simplify the shape so it can be easily drawn on the map.</p>"
"<p style = 'font-size:16px;font-family:Arial'>Retrieve the buffer shape to the client, and use GeoPandas methods to simplify the shape so zone 7 can be easily drawn on the map.</p>"
]
},
{
Expand Down Expand Up @@ -545,7 +554,6 @@
" <li><b style = 'color:#8B8000'>Yellow</b> for addresses 0 to 5 KM away</li>\n",
" <li><b style = 'color:green'>Green</b> for addresses 5 to 10 KM away</li>\n",
" </ul>\n",
"\n",
"<p style = 'font-size:16px;font-family:Arial'>Note there are about 400 addresses inside the 10 KM boundary to Flood Zone 7.</p>"
]
},
Expand Down Expand Up @@ -655,7 +663,7 @@
},
"outputs": [],
"source": [
"fig = Figure(width=600, height=400)\n",
"fig = Figure(width=850, height=500)\n",
"hm = folium.Map(location=[-39.646172303816414, 176.775454544966948], zoom_start=8)\n",
"\n",
"\n",
Expand All @@ -678,6 +686,13 @@
"fig.add_child(hm)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<p style = 'font-size:16px;font-family:Arial'>The above map shows are the total count of the addresses. You can zoom the map to individual address location, click on the aggregated count and the map will zoom in or you can click the '+' button."
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -713,6 +728,18 @@
"hm"
]
},
{
"cell_type": "markdown",
"metadata": {
"ExecuteTime": {
"end_time": "2023-03-20T17:01:08.775855Z",
"start_time": "2023-03-20T17:00:17.595009Z"
}
},
"source": [
"<p style = 'font-size:16px;font-family:Arial'>The heat map shows the number of properties at risk within an area. As you move your mouse over the circles and zoom in and out, you will see the shape of the area marked with the circle and the basis of the color. Hundreds of properties would be red, less than 10 might be green. </p>"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down Expand Up @@ -753,7 +780,7 @@
" lon=gdf_st_dist['lon'],\n",
" z=gdf_st_dist['RISK'],\n",
" radius=3,\n",
" colorscale=[[0.0, 'blue',],[0.3,'lime'],[0.5,'yellow'],[0.7,'orange'],[1.0, 'red']],\n",
" colorscale=[[0.0, 'blue',],[0.3,'green'],[0.5,'yellow'],[0.7,'orange'],[1.0, 'red']],\n",
" zmin=0.0,\n",
" zmax=1.0,\n",
" opacity=0.5 \n",
Expand All @@ -768,6 +795,13 @@
"fig.show()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"<p style = 'font-size:16px;font-family:Arial'>On this representation the density of properties at a given zoom level changes by color alone. As you zoom in, the dots will go from red to yellow to orange to green.</p>"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down

0 comments on commit 298906e

Please sign in to comment.