Skip to content

Commit

Permalink
v1.1.2
Browse files Browse the repository at this point in the history
Modification of some plots in the dedicated tool.
Basemaps from the contextily package have been added to the map type plots (i.e. LRR, NSM and SCE).
The numbering of the "Plot Results" tool has been corrected (it used to say 5 and it is actually 4).
  • Loading branch information
AlbertGallegoJimenez committed Jan 29, 2024
1 parent 220b82b commit 437bcca
Show file tree
Hide file tree
Showing 22 changed files with 62 additions and 18 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Check that you have installed all the required libraries used in the toolbox. Al
* ```shapely```
* ```statsmodels``` (from ArcGIS version 3.2 this package is included in the base ArcGIS ```anaconda``` environment)
* ```cartopy```
* ```seaborn```
* ```contextily```

In terms of data, this tool relies on the use of the following two files:
* <ins>**Baseline**</ins> (Vector - Polyline). This is the reference line used to assess the evolution of the coastal stretch. It can be digitized manually by the user with the help of a background orthophoto, it is recommended to place the baseline **inland**. The baseline must capture the general orientation of the coast.
Expand All @@ -51,7 +53,7 @@ In terms of data, this tool relies on the use of the following two files:
### Installation

0. Make sure you have cloned the base ArcGIS ```anaconda``` environment so you can install more packages. More info [here](https://pro.arcgis.com/en/pro-app/latest/arcpy/get-started/clone-an-environment.htm).
1. Install ```shapely```, ```statsmodels``` and ```cartopy``` packages if you do not have it installed yet.
1. Install the required packages listed in the *Prerequisites* section if they are not already installed.
2. Download the content in the [src](https://github.com/AlbertGallegoJimenez/shoreline-evolution-tool/tree/main/src) folder.
3. Open the Catalog Pane in ArcGIS Pro and open the downloaded Toolbox (.pyt) to see the tools.
<div align="center">
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
arcgispro (software) 3.1
arcpy 3.1
cartopy 0.21.1
contextily 1.5.0
matplotlib 3.6.0
numpy 1.20.1
pandas 1.4.4
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xml:lang="es"><Esri><CreaDate>20240129</CreaDate><CreaTime>11531500</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce></Esri></metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xml:lang="es"><Esri><CreaDate>20240129</CreaDate><CreaTime>11582600</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce></Esri></metadata>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xml:lang="es"><Esri><CreaDate>20240129</CreaDate><CreaTime>11530400</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce></Esri></metadata>
2 changes: 2 additions & 0 deletions src/Shoreline Evolution Analysis Toolbox.PlotResults.pyt.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xml:lang="es"><Esri><CreaDate>20240129</CreaDate><CreaTime>09574900</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce></Esri></metadata>
13 changes: 7 additions & 6 deletions src/Shoreline Evolution Analysis Toolbox.pyt
Original file line number Diff line number Diff line change
@@ -1,22 +1,23 @@
import arcpy

# 1. Generate Transects Along Baseline
# 1a. Generate Transects Along Baseline
from tools.generateTransects import GenerateTransects

# 2. Correct Transects
# 1b. Correct Transects
from tools.correctTransects import CorrectTransects

# 3. Compute Intersections
# 2. Compute Intersections
from tools.computeIntersections import ComputeIntersection

# 4. Perform the Shoreline Evolution Analysis
# 3. Perform the Shoreline Evolution Analysis
from tools.performAnalysis import PerformAnalysis

# 5. Plot The Analysis Results
# 4. Plot The Analysis Results
from tools.plotResults import PlotResults

class Toolbox(object):
def __init__(self):

# List of tool classes associated with this toolbox
self.tools = [GenerateTransects, CorrectTransects, ComputeIntersection, PerformAnalysis, PlotResults]
self.tools = [GenerateTransects, CorrectTransects, ComputeIntersection,
PerformAnalysis, PlotResults]
2 changes: 1 addition & 1 deletion src/Shoreline Evolution Analysis Toolbox.pyt.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0" encoding="UTF-8"?>
<metadata xml:lang="es"><Esri><CreaDate>20231121</CreaDate><CreaTime>19152500</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce><ModDate>20231121</ModDate><ModTime>191525</ModTime></Esri><toolbox name="Shoreline Evolution Analysis Toolbox" alias=""><arcToolboxHelpPath>c:\program files\arcgis\pro\Resources\Help\gp</arcToolboxHelpPath><toolsets/></toolbox><dataIdInfo><idCitation><resTitle>Shoreline Evolution Analysis Toolbox</resTitle></idCitation></dataIdInfo><distInfo><distributor><distorFormat><formatName>ArcToolbox Toolbox</formatName></distorFormat></distributor></distInfo></metadata>
<metadata xml:lang="es"><Esri><CreaDate>20231121</CreaDate><CreaTime>19152500</CreaTime><ArcGISFormat>1.0</ArcGISFormat><SyncOnce>TRUE</SyncOnce><ModDate>20240129</ModDate><ModTime>115229</ModTime></Esri><toolbox name="Shoreline Evolution Analysis Toolbox" alias=""><arcToolboxHelpPath>c:\program files\arcgis\pro\Resources\Help\gp</arcToolboxHelpPath><toolsets/></toolbox><dataIdInfo><idCitation><resTitle>Shoreline Evolution Analysis Toolbox</resTitle></idCitation></dataIdInfo><distInfo><distributor><distorFormat><formatName>ArcToolbox Toolbox</formatName></distorFormat></distributor></distInfo></metadata>
Binary file modified src/tools/__pycache__/computeIntersections.cpython-39.pyc
Binary file not shown.
Binary file modified src/tools/__pycache__/correctTransects.cpython-39.pyc
Binary file not shown.
Binary file modified src/tools/__pycache__/generateTransects.cpython-39.pyc
Binary file not shown.
Binary file modified src/tools/__pycache__/performAnalysis.cpython-39.pyc
Binary file not shown.
Binary file added src/tools/__pycache__/plotResults.cpython-39.pyc
Binary file not shown.
2 changes: 1 addition & 1 deletion src/tools/computeIntersections.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def getParameterInfo(self):
shoreline_param.filter.list = ['Polyline']

shore_id_param = arcpy.Parameter(
displayName="Name of ID Shoreline Field",
displayName="Name of Shorelines ID Field",
name="id_shore",
datatype="Field",
parameterType="Required",
Expand Down
2 changes: 1 addition & 1 deletion src/tools/performAnalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class PerformAnalysis(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "3. Perform The Analysis"
self.description = ""
self.description = "Perform the Linear Regression Analysis on each transect."
self.canRunInBackground = False

def getParameterInfo(self):
Expand Down
4 changes: 2 additions & 2 deletions src/tools/plotResults.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
class PlotResults(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "5. Plot The Analysis Results"
self.description = ""
self.label = "4. Plot The Analysis Results"
self.description = "Plot some figures to see the analysis results."
self.canRunInBackground = False

def getParameterInfo(self):
Expand Down
Binary file modified src/tools/utils/__pycache__/intersect_lines.cpython-39.pyc
Binary file not shown.
Binary file modified src/tools/utils/__pycache__/plot_results.cpython-39.pyc
Binary file not shown.
Binary file modified src/tools/utils/__pycache__/shoreline_evolution.cpython-39.pyc
Binary file not shown.
Binary file modified src/tools/utils/__pycache__/transect_processor.cpython-39.pyc
Binary file not shown.
42 changes: 38 additions & 4 deletions src/tools/utils/plot_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd
import os
import re
import contextily as cx
import cartopy.crs as ccrs
from tools.utils.intersect_lines import *
from matplotlib.colors import Normalize, TwoSlopeNorm
Expand Down Expand Up @@ -118,6 +119,32 @@ def _set_map_configuration(self, metric):

return cmap, norm, extend_cbar

def _set_xylim(self, list_shapely):
"""
Private method to set the x and y limits for plotting LRR, SCE and NSM.
Parameters:
list_shapely (dict): Dictionary of transect_id (key) and transects geometry in Shapely format (value).
Returns:
x_lim (list): List with the starting and ending x limits.
y_lim (list): List with the starting and ending y limits.
"""
# Get a list with all longitudes and latitudes values for all vertices of each transect
lons = [x for t in list_shapely.values() for x in t.xy[0]]
lats = [y for t in list_shapely.values() for y in t.xy[1]]

# Calculate the offset for each axis
x_offset = abs(max(lons) - min(lons)) / 10
y_offset = abs(max(lats) - min(lats)) / 10

# Set the x and y limits
x_lim = [min(lons) - x_offset, max(lons) + x_offset]
y_lim = [min(lats) - y_offset, max(lats) + y_offset]

return x_lim, y_lim


# ===== FROM HERE, ALL THE FUNCTIONS TO CREATE THE PLOTS ARE DEFINED =====

def plot_spatial_evolution(self):
Expand Down Expand Up @@ -282,7 +309,8 @@ def plot_map(self, metric):
ls = '--'

# Plot the transect line
ax.plot(*t.xy,
x, y = t.xy
ax.plot(x, y,
color=color,
transform=proj,
lw=3,
Expand All @@ -308,9 +336,15 @@ def plot_map(self, metric):
ax.set_title('Net Shoreline Movement, NSM (m)', y=1.05)

# Set limits, labels, legend, and save the figure
lons = [x for t in self.transects_shapely.values() for x in t.xy[0]] # Extract the longitudes for plotting purposes (Sometimes the plot is centered to the west and a blank space is left to the east of the study area)
ax.set_xlim([ax.get_xlim()[0], max(lons)])
try:
cx.add_basemap(ax, crs=proj, source=cx.providers.Esri.WorldImagery, alpha=.7, attribution_size=6)
except:
arcpy.AddMessage("Basemap could not be added to the {}_transect.png map.".format(metric))

x_lim, y_lim = self._set_xylim(self.transects_shapely)
ax.set_xlim(x_lim)
ax.set_ylim(y_lim)
ax.set_xlabel('Eastings (m)')
ax.set_ylabel('Northings (m)')
ax.legend(handles=[legend_entry], fontsize='small')
ax.legend(handles=[legend_entry], fontsize='small', loc='best')
fig.savefig(os.path.join(self.out_dir, '{0}_transects.png'.format(metric)), dpi=300, bbox_inches='tight')
2 changes: 0 additions & 2 deletions src/tools/utils/transect_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,3 @@ def rotatepoint(point, pivotpoint, angle):
qx = ox + math.cos(angle_rad) * (px - ox) - math.sin(angle_rad) * (py - oy)
qy = oy + math.sin(angle_rad) * (px - ox) + math.cos(angle_rad) * (py - oy)
return arcpy.Point(qx, qy)


0 comments on commit 437bcca

Please sign in to comment.