|
|
Aqui |
|
|
\ No newline at end of file |
|
|
<details>
|
|
|
<summary>
|
|
|
|
|
|
# Summary
|
|
|
|
|
|
</summary>
|
|
|
|
|
|
[[_TOC_]]
|
|
|
|
|
|
</details>
|
|
|
|
|
|
The code performs the following steps:
|
|
|
|
|
|
1. Defines an array of baseline coordinates and another set of
|
|
|
coordinates for a different region.
|
|
|
2. Creates a baseline geometry using the baseline coordinates and adds
|
|
|
it as a layer to the map.
|
|
|
3. Generates orthogonal transects based on the baseline coordinates and
|
|
|
adds them as a layer to the map.
|
|
|
4. Filters an image collection based on a geometry and a date range.
|
|
|
5. Retrieves the number of images in the image collection and converts
|
|
|
it to a list.
|
|
|
6. Iterates over each image in the list and performs several
|
|
|
operations:
|
|
|
1. Adds the image as a layer to the map.
|
|
|
2. Retrieves the green and near-infrared bands of the image.
|
|
|
3. Identifies water features in the image using a threshold value.
|
|
|
4. If water features are found, it performs the following steps:
|
|
|
1. Calculates the shoreline by intersecting the water features
|
|
|
with a buffered geometry.
|
|
|
2. Removes noise from the shoreline.
|
|
|
3. Applies a Gaussian filter to smoothen the shoreline.
|
|
|
4. Creates a feature for the shoreline and adds it as a layer
|
|
|
to the map.
|
|
|
5. Appends the shoreline feature to an evaluated array.
|
|
|
7. Calculates the statistics of the evaluated shorelines along the
|
|
|
transects.
|
|
|
8. Generates visualizations of the transects and shoreline statistics.
|
|
|
9. Calculates the intersections between the first transect and each
|
|
|
shoreline feature.
|
|
|
10. Prints the results of the intersections.
|
|
|
11. Centers the map on the baseline geometry.
|
|
|
|
|
|
Overall, the code processes a collection of satellite images to identify
|
|
|
and analyze shorelines using transects and calculates statistics related
|
|
|
to the shorelines.
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **applyScaleFactors**
|
|
|
|
|
|
`Applies scale factors to the input image.`
|
|
|
|
|
|
``` javascript
|
|
|
function applyScaleFactors(image) {
|
|
|
var opticalBands = image.select('SR_B.').multiply(0.0000275).add(-0.2);
|
|
|
var thermalBands = image.select('ST_B.*').multiply(0.00341802).add(149.0);
|
|
|
return image.addBands(opticalBands, null, true).addBands(thermalBands, null, true);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- image: The input image to apply scale factors. Must be an Earth
|
|
|
Engine image.
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- The output image with scale factors applied.
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
\- Call the function as follows:
|
|
|
|
|
|
``` javascript
|
|
|
applyScaleFactors(image);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **centerMapOnGeometry**
|
|
|
|
|
|
Centers the map on a specified geometry.
|
|
|
|
|
|
``` javascript
|
|
|
function centerMapOnGeometry(){
|
|
|
//center in the first point defined in geometry
|
|
|
var list = geometry.coordinates();
|
|
|
var point = list.getInfo();
|
|
|
Map.setCenter(point[0][0][0],point[0][0][1],13);
|
|
|
}
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- No input parameters for this function.
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- No output for this function.
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
\- Call the function as follows:
|
|
|
|
|
|
``` javascript
|
|
|
centerMapOnGeometry();
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **gaussianKernel**
|
|
|
|
|
|
Calculates a Gaussian kernel with a specified size, mean, and sigma.
|
|
|
|
|
|
``` javascript
|
|
|
var gaussianKernel = function (size, mean, sigma) {
|
|
|
var gaussianCurve = function (x, mean, sigma) {
|
|
|
var divider = ee
|
|
|
.Number(sigma)
|
|
|
.multiply(ee.Number(2).multiply(Math.PI).sqrt());
|
|
|
var exponent = ee.Number(-1).multiply(
|
|
|
ee
|
|
|
.Number(x)
|
|
|
.subtract(mean)
|
|
|
.pow(2)
|
|
|
.divide(ee.Number(2).multiply(ee.Number(sigma).pow(2)))
|
|
|
);
|
|
|
return ee.Number(1).divide(divider).multiply(exponent.exp());
|
|
|
};
|
|
|
var half = ee.Number(size).divide(2).floor();
|
|
|
var begin = ee.Number(0).subtract(half),
|
|
|
end = ee.Number(0).add(half);
|
|
|
// Get the normal distribution Y value for each X
|
|
|
// in the interval
|
|
|
var kernel = ee.List.sequence(begin, end).map(function (i) { return gaussianCurve(i, mean, sigma)});
|
|
|
var sum = kernel.reduce(ee.Reducer.sum());
|
|
|
// Normalize each value, so that the sum of the list
|
|
|
// will be equal to one
|
|
|
var normalizedKernel = kernel.map(function (val) { return ee.Number(val).divide(sum)});
|
|
|
return normalizedKernel;
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- size: The size of the kernel. Must be a positive integer. - mean: The
|
|
|
mean of the Gaussian distribution. - sigma: The standard deviation of
|
|
|
the Gaussian distribution.
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- normalizedKernel: A list of values representing the normalized
|
|
|
Gaussian kernel.
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
\- Call the function as follows:
|
|
|
|
|
|
``` javascript
|
|
|
var kernel = gaussianKernel(5, 0, 1);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **linearGaussianFilter**
|
|
|
|
|
|
Calculates a linear Gaussian filter using a given set of coordinates.
|
|
|
|
|
|
``` javascript
|
|
|
var linearGaussianFilter = function (
|
|
|
coordinates
|
|
|
) {
|
|
|
var samples = 3;
|
|
|
var mean = 0;
|
|
|
var sd = 1;
|
|
|
var coordinateList = ee.List(coordinates);
|
|
|
// Setup gauss distribution kernel parameters
|
|
|
var kernelSize = ee.Number(samples);
|
|
|
var kernelMean = ee.Number(mean);
|
|
|
var kernelSd = ee.Number(sd);
|
|
|
var kernel = gaussianKernel(kernelSize, kernelMean, kernelSd);
|
|
|
var first = coordinateList.reduce(ee.Reducer.first()),
|
|
|
last = coordinateList.reduce(ee.Reducer.last());
|
|
|
var sequence = ee.List.sequence(
|
|
|
ee.Number(0),
|
|
|
coordinateList.length().subtract(kernelSize)
|
|
|
);
|
|
|
var path = sequence.map(function (index) {
|
|
|
// Take interval of the kernel size to apply the smoothing
|
|
|
// and zip it to the kernel, so each element in the new list
|
|
|
// will be a pair of a 2d point and its weight
|
|
|
var interval = coordinateList
|
|
|
.slice(ee.Number(index), ee.Number(index).add(kernelSize))
|
|
|
.zip(kernel);
|
|
|
// Map the elements, multiplying their axis values by their weight
|
|
|
var gaussian = interval.map(function (element) {
|
|
|
// Each element contains a 2d point (0) and a kernel weight (1)
|
|
|
var asList = ee.List(element);
|
|
|
var point = ee.List(asList.get(0));
|
|
|
var weight = ee.Number(asList.get(1));
|
|
|
// Now we map the two values (each point dimention), multiplying to the weight
|
|
|
return point.map( function (value) { return ee.Number(value).multiply(weight)});
|
|
|
});
|
|
|
// Sum longitude and latitude separately
|
|
|
var smoothenLong = gaussian
|
|
|
.map(function (point){ return ee.List(point).get(0)})
|
|
|
.reduce(ee.Reducer.sum());
|
|
|
var smoothenLat = gaussian
|
|
|
.map(function (point) { return ee.List(point).get(1)})
|
|
|
.reduce(ee.Reducer.sum());
|
|
|
// Return final smoothen point
|
|
|
return ee.List([smoothenLong, smoothenLat]);
|
|
|
});
|
|
|
var smoothen = ee.List([]).add(first).cat(path).add(last);
|
|
|
// return original coordinates if the kernelSize is less than or equal to the length
|
|
|
// of the given coordinates, otherwise return smoothen coordinates.
|
|
|
return ee.Algorithms.If(
|
|
|
coordinateList.size().lte(kernelSize),
|
|
|
coordinateList,
|
|
|
smoothen
|
|
|
);
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- coordinates: A list of coordinates to be filtered.
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- If the length of the given coordinates is less than or equal to the
|
|
|
kernel size, the function returns the original coordinates. Otherwise,
|
|
|
it returns the smoothened coordinates.
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
\- Call the function as follows:
|
|
|
|
|
|
``` javascript
|
|
|
var filteredCoordinates = linearGaussianFilter(coordinates);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **removeShorelineNoise**
|
|
|
|
|
|
`This function removes noise from shorelines by calculating the intersection between the shorelines and transects, and returning the geometry with the highest weight.`
|
|
|
|
|
|
``` javascript
|
|
|
var removeShorelineNoise = function (shorelines, transects) {
|
|
|
var coordinates = ee.Geometry(shorelines).coordinates();
|
|
|
|
|
|
var guard = ee.List(
|
|
|
ee.Algorithms.If(
|
|
|
ee.Geometry(shorelines).type().compareTo("MultiLineString").eq(0),
|
|
|
coordinates,
|
|
|
[coordinates]
|
|
|
)
|
|
|
);
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- shorelines: a geometry representing the shorelines to remove noise
|
|
|
from. - transects: a geometry representing the transects to calculate
|
|
|
the intersection with the shorelines.
|
|
|
|
|
|
``` javascript
|
|
|
var shorelines = ee.Geometry.LineString([[0, 0], [1, 1], [1, 2]]);
|
|
|
var transects = ee.Geometry.LineString([[0, 1], [1, 1]]);
|
|
|
var noiselessShoreline = removeShorelineNoise(shorelines, transects);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a geometry representing the noiseless shoreline.
|
|
|
|
|
|
``` javascript
|
|
|
var noiselessShoreline = removeShorelineNoise(shorelines, transects);
|
|
|
print(noiselessShoreline);
|
|
|
```
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the shorelines and
|
|
|
transects geometries. - Call the removeShorelineNoise function with the
|
|
|
shorelines and transects geometries as inputs. - The function will
|
|
|
return a geometry representing the noiseless shoreline.
|
|
|
|
|
|
``` javascript
|
|
|
var shorelines = ee.Geometry.LineString([[0, 0], [1, 1], [1, 2]]);
|
|
|
var transects = ee.Geometry.LineString([[0, 1], [1, 1]]);
|
|
|
var noiselessShoreline = removeShorelineNoise(shorelines, transects);
|
|
|
Map.addLayer(shorelines, {}, "Shorelines");
|
|
|
Map.addLayer(transects, {}, "Transects");
|
|
|
Map.addLayer(noiselessShoreline, {}, "Noiseless shoreline");
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **toDegrees**
|
|
|
|
|
|
This function converts longitude and latitude values from radians to
|
|
|
degrees.
|
|
|
|
|
|
``` javascript
|
|
|
var toDegrees = function (lng, lat) {
|
|
|
lat = lat.multiply(180 / Math.PI);
|
|
|
lng = lng.multiply(180 / Math.PI);
|
|
|
return [lng.add(540).mod(360).subtract(180), lat];
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- lng: a number representing the longitude value in radians. - lat: a
|
|
|
number representing the latitude value in radians.
|
|
|
|
|
|
``` javascript
|
|
|
var lng = ee.Number(0.7853981634); // 45 degrees in radians
|
|
|
var lat = ee.Number(0.5235987756); // 30 degrees in radians
|
|
|
var degrees = toDegrees(lng, lat);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- an array containing the converted longitude and latitude values in
|
|
|
degrees.
|
|
|
|
|
|
``` javascript
|
|
|
var degrees = toDegrees(lng, lat);
|
|
|
print(degrees);
|
|
|
```
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the longitude and
|
|
|
latitude values in radians. - Call the toDegrees function with the
|
|
|
longitude and latitude values as inputs. - The function will return an
|
|
|
array containing the converted longitude and latitude values in degrees.
|
|
|
|
|
|
``` javascript
|
|
|
var lng = ee.Number(0.7853981634); // 45 degrees in radians
|
|
|
var lat = ee.Number(0.5235987756); // 30 degrees in radians
|
|
|
var degrees = toDegrees(lng, lat);
|
|
|
print(degrees);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **computeDisplacement**
|
|
|
|
|
|
This function computes the new longitude and latitude coordinates based
|
|
|
on the input longitude, latitude, angle (theta), and distance.
|
|
|
|
|
|
``` javascript
|
|
|
var computeDisplacement = function (lng, lat, theta, distance) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- lng: a number representing the longitude value in degrees. - lat: a
|
|
|
number representing the latitude value in degrees. - theta: a number
|
|
|
representing the angle in degrees. - distance: a number representing the
|
|
|
distance in meters.
|
|
|
|
|
|
``` javascript
|
|
|
var lng = ee.Number(-122.4194); // San Francisco longitude
|
|
|
var lat = ee.Number(37.7749); // San Francisco latitude
|
|
|
var theta = ee.Number(45); // 45 degrees angle
|
|
|
var distance = ee.Number(1000); // 1000 meters distance
|
|
|
var newCoordinates = computeDisplacement(lng, lat, theta, distance);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- an array containing the new longitude and latitude coordinates.
|
|
|
|
|
|
``` javascript
|
|
|
var newCoordinates = computeDisplacement(lng, lat, theta, distance);
|
|
|
print(newCoordinates);
|
|
|
```
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the longitude,
|
|
|
latitude, angle (theta), and distance values. - Call the
|
|
|
computeDisplacement function with the longitude, latitude, angle, and
|
|
|
distance values as inputs. - The function will return an array
|
|
|
containing the new longitude and latitude coordinates.
|
|
|
|
|
|
``` javascript
|
|
|
var lng = ee.Number(-122.4194); // San Francisco longitude
|
|
|
var lat = ee.Number(37.7749); // San Francisco latitude
|
|
|
var theta = ee.Number(45); // 45 degrees angle
|
|
|
var distance = ee.Number(1000); // 1000 meters distance
|
|
|
var newCoordinates = computeDisplacement(lng, lat, theta, distance);
|
|
|
print(newCoordinates);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **offsetMapper**
|
|
|
|
|
|
This function creates a mapping function that takes an offset value and
|
|
|
returns a feature representing a line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var offsetMapper = function (extent, origin, theta) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- extent: a number representing the extent value. - origin: an array
|
|
|
containing the origin coordinates. - theta: a number representing the
|
|
|
angle in degrees.
|
|
|
|
|
|
``` javascript
|
|
|
var extent = ee.Number(1000); // extent value
|
|
|
var origin = [ee.Number(-122.4194), ee.Number(37.7749)]; // origin coordinates
|
|
|
var theta = ee.Number(45); // 45 degrees angle
|
|
|
var mappingFunction = offsetMapper(extent, origin, theta);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a feature representing a line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var mappingFunction = offsetMapper(extent, origin, theta);
|
|
|
print(mappingFunction);
|
|
|
```
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the extent, origin
|
|
|
coordinates, and angle (theta) values. - Call the offsetMapper function
|
|
|
with the extent, origin, and theta values as inputs. - The function will
|
|
|
return a mapping function that takes an offset value and returns a
|
|
|
feature representing a line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var extent = ee.Number(1000); // extent value
|
|
|
var origin = [ee.Number(-122.4194), ee.Number(37.7749)]; // origin coordinates
|
|
|
var theta = ee.Number(45); // 45 degrees angle
|
|
|
var mappingFunction = offsetMapper(extent, origin, theta);
|
|
|
print(mappingFunction);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **toRadians**
|
|
|
|
|
|
This function converts a value from degrees to radians.
|
|
|
|
|
|
``` javascript
|
|
|
var toRadians = function (value) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- value: a number representing the value in degrees.
|
|
|
|
|
|
``` javascript
|
|
|
var value = 45; // 45 degrees
|
|
|
var radians = toRadians(value);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a number representing the value in radians.
|
|
|
|
|
|
``` javascript
|
|
|
var value = 45; // 45 degrees
|
|
|
var radians = toRadians(value);
|
|
|
print(radians);
|
|
|
```
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the value in degrees
|
|
|
that you want to convert to radians. - Call the toRadians function with
|
|
|
the value as an input. - The function will return the value converted to
|
|
|
radians.
|
|
|
|
|
|
``` javascript
|
|
|
var value = 45; // 45 degrees
|
|
|
var radians = toRadians(value);
|
|
|
print(radians);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **computeBearing**
|
|
|
|
|
|
This function calculates the bearing between two points on the Earth's
|
|
|
surface using their longitude and latitude coordinates.
|
|
|
|
|
|
``` javascript
|
|
|
var computeBearing = function (lng1, lat1, lng2, lat2) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- lng1: a number representing the longitude of the first point. - lat1:
|
|
|
a number representing the latitude of the first point. - lng2: a number
|
|
|
representing the longitude of the second point. - lat2: a number
|
|
|
representing the latitude of the second point.
|
|
|
|
|
|
``` javascript
|
|
|
var lng1 = -122.4194; // longitude of the first point
|
|
|
var lat1 = 37.7749; // latitude of the first point
|
|
|
var lng2 = -122.4313; // longitude of the second point
|
|
|
var lat2 = 37.7675; // latitude of the second point
|
|
|
var bearing = computeBearing(lng1, lat1, lng2, lat2);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a number representing the bearing between the two points.
|
|
|
|
|
|
``` javascript
|
|
|
var lng1 = -122.4194; // longitude of the first point
|
|
|
var lat1 = 37.7749; // latitude of the first point
|
|
|
var lng2 = -122.4313; // longitude of the second point
|
|
|
var lat2 = 37.7675; // latitude of the second point
|
|
|
var bearing = computeBearing(lng1, lat1, lng2, lat2);
|
|
|
print(bearing);
|
|
|
```
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the longitude and
|
|
|
latitude coordinates of the two points. - Call the computeBearing
|
|
|
function with the longitude and latitude values as inputs. - The
|
|
|
function will return the bearing between the two points.
|
|
|
|
|
|
``` javascript
|
|
|
var lng1 = -122.4194; // longitude of the first point
|
|
|
var lat1 = 37.7749; // latitude of the first point
|
|
|
var lng2 = -122.4313; // longitude of the second point
|
|
|
var lat2 = 37.7675; // latitude of the second point
|
|
|
var bearing = computeBearing(lng1, lat1, lng2, lat2);
|
|
|
print(bearing);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **transectAccumulator**
|
|
|
|
|
|
This function is a higher-order function that returns another function.
|
|
|
The returned function is used to accumulate and process data for
|
|
|
generating transects along a line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var transectAccumulator = function (step, extent) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- step: a number representing the distance between each transect. -
|
|
|
extent: a number representing the total distance of the line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var step = 10; // distance between each transect
|
|
|
var extent = 100; // total distance of the line segment
|
|
|
var accumulator = transectAccumulator(step, extent);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a function that accumulates and processes data for generating
|
|
|
transects along a line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var step = 10; // distance between each transect
|
|
|
var extent = 100; // total distance of the line segment
|
|
|
var accumulator = transectAccumulator(step, extent);
|
|
|
var result = accumulator(data);
|
|
|
```
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the distance between
|
|
|
each transect and the total distance of the line segment. - Call the
|
|
|
transectAccumulator function with the step and extent values as
|
|
|
inputs. - The function will return another function that can be used to
|
|
|
accumulate and process data for generating transects along a line
|
|
|
segment.
|
|
|
|
|
|
``` javascript
|
|
|
var step = 10; // distance between each transect
|
|
|
var extent = 100; // total distance of the line segment
|
|
|
var accumulator = transectAccumulator(step, extent);
|
|
|
var result = accumulator(data);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **generateOrthogonalTransects**
|
|
|
|
|
|
This function generates orthogonal transects along a line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var generateOrthogonalTransects = function (coordinates, step, extent) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- coordinates: a list of coordinates representing the line segment. -
|
|
|
step: a number representing the distance between each transect. -
|
|
|
extent: a number representing the total distance of the line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var coordinates = [[0,0], [0,10], [10,10], [10,0]]; // list of coordinates representing the line segment
|
|
|
var step = 10; // distance between each transect
|
|
|
var extent = 100; // total distance of the line segment
|
|
|
var transects = generateOrthogonalTransects(coordinates, step, extent);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a list of orthogonal transects along the line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var coordinates = [[0,0], [0,10], [10,10], [10,0]]; // list of coordinates representing the line segment
|
|
|
var step = 10; // distance between each transect
|
|
|
var extent = 100; // total distance of the line segment
|
|
|
var transects = generateOrthogonalTransects(coordinates, step, extent);
|
|
|
print(transects);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a list of coordinates
|
|
|
representing the line segment. - Define the distance between each
|
|
|
transect and the total distance of the line segment. - Call the
|
|
|
generateOrthogonalTransects function with the coordinates, step, and
|
|
|
extent values as inputs. - The function will return a list of orthogonal
|
|
|
transects along the line segment.
|
|
|
|
|
|
``` javascript
|
|
|
var coordinates = [[0,0], [0,10], [10,10], [10,0]]; // list of coordinates representing the line segment
|
|
|
var step = 10; // distance between each transect
|
|
|
var extent = 100; // total distance of the line segment
|
|
|
var transects = generateOrthogonalTransects(coordinates, step, extent);
|
|
|
print(transects);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **thresholdingAlgorithm**
|
|
|
|
|
|
*`This`` ``function`` ``calculates`` ``the`` ``threshold`` ``value`` ``for`` ``image`` ``segmentation`` ``using`` ``the`` ``thresholding`` ``algorithm.`*
|
|
|
|
|
|
``` javascript
|
|
|
var thresholdingAlgorithm = function (histogram, count) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- histogram: a dictionary representing the histogram of pixel values in
|
|
|
an image. - count: the total count of pixels in the image.
|
|
|
|
|
|
``` javascript
|
|
|
var histogram = { "bucketMeans": [0, 1, 2, 3], "histogram": [10, 20, 30, 40] }; // example histogram
|
|
|
var count = 1000; // example count
|
|
|
var threshold = thresholdingAlgorithm(histogram, count);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- the threshold value for image segmentation.
|
|
|
|
|
|
``` javascript
|
|
|
var histogram = { "bucketMeans": [0, 1, 2, 3], "histogram": [10, 20, 30, 40] }; // example histogram
|
|
|
var count = 1000; // example count
|
|
|
var threshold = thresholdingAlgorithm(histogram, count);
|
|
|
print(threshold);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a histogram
|
|
|
dictionary representing the histogram of pixel values in an image. -
|
|
|
Define the total count of pixels in the image. - Call the
|
|
|
thresholdingAlgorithm function with the histogram and count values as
|
|
|
inputs. - The function will return the threshold value for image
|
|
|
segmentation.
|
|
|
|
|
|
``` javascript
|
|
|
var histogram = { "bucketMeans": [0, 1, 2, 3], "histogram": [10, 20, 30, 40] }; // example histogram
|
|
|
var count = 1000; // example count
|
|
|
var threshold = thresholdingAlgorithm(histogram, count);
|
|
|
print(threshold);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **selectThreshold**
|
|
|
|
|
|
*This function selects a threshold value based on the given parameter.*
|
|
|
|
|
|
``` javascript
|
|
|
var selectThreshold = function (threshold) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- threshold: a numeric value representing the threshold to be selected.
|
|
|
|
|
|
``` javascript
|
|
|
var threshold = 0.0; // example threshold
|
|
|
var thresholdFunction = selectThreshold(threshold);
|
|
|
```
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a function that takes image, band, \_, and scale as inputs and
|
|
|
returns a threshold value.
|
|
|
|
|
|
``` javascript
|
|
|
var threshold = 0.0; // example threshold
|
|
|
var thresholdFunction = selectThreshold(threshold);
|
|
|
var image = ee.Image("example_image"); // example image
|
|
|
var band = "example_band"; // example band
|
|
|
var scale = 30; // example scale
|
|
|
var selectedThreshold = thresholdFunction(image, band, _, scale);
|
|
|
print(selectedThreshold);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a threshold value. -
|
|
|
Call the selectThreshold function with the threshold value as input. -
|
|
|
The function will return a threshold function. - Call the threshold
|
|
|
function with image, band, \_, and scale values as inputs. - The
|
|
|
threshold function will return a selected threshold value.
|
|
|
|
|
|
``` javascript
|
|
|
var threshold = 0.0; // example threshold
|
|
|
var thresholdFunction = selectThreshold(threshold);
|
|
|
var image = ee.Image("example_image"); // example image
|
|
|
var band = "example_band"; // example band
|
|
|
var scale = 30; // example scale
|
|
|
var selectedThreshold = thresholdFunction(image, band, _, scale);
|
|
|
print(selectedThreshold);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **identifyWaterFeature**
|
|
|
|
|
|
*This function identifies water features in an image based on a given
|
|
|
threshold and returns the geometry of the water feature.*
|
|
|
|
|
|
``` javascript
|
|
|
var identifyWaterFeature = function (
|
|
|
image,
|
|
|
geometry,
|
|
|
scale,
|
|
|
band,
|
|
|
thresholdFn
|
|
|
){
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- image: an image representing the area of interest. - geometry: a
|
|
|
geometry object representing the region of interest. - scale: a numeric
|
|
|
value representing the scale at which to perform the analysis. - band: a
|
|
|
string representing the band to use for the analysis. - thresholdFn: a
|
|
|
function that calculates the threshold value for identifying water
|
|
|
features.
|
|
|
|
|
|
``` javascript
|
|
|
var image = ee.Image("example_image"); // example image
|
|
|
var geometry = ee.Geometry.Point(0, 0); // example geometry
|
|
|
var scale = 30; // example scale
|
|
|
var band = "example_band"; // example band
|
|
|
var thresholdFn = function (ndwi, band, geometry, scale) {
|
|
|
// example threshold function
|
|
|
var threshold = ee.Number(0.01);
|
|
|
return threshold;
|
|
|
};
|
|
|
var waterGeometry = identifyWaterFeature(image, geometry, scale, band, thresholdFn);
|
|
|
print(waterGeometry);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a geometry object representing the water feature.
|
|
|
|
|
|
``` javascript
|
|
|
var image = ee.Image("example_image"); // example image
|
|
|
var geometry = ee.Geometry.Point(0, 0); // example geometry
|
|
|
var scale = 30; // example scale
|
|
|
var band = "example_band"; // example band
|
|
|
var thresholdFn = function (ndwi, band, geometry, scale) {
|
|
|
// example threshold function
|
|
|
var threshold = ee.Number(0.01);
|
|
|
return threshold;
|
|
|
};
|
|
|
var waterGeometry = identifyWaterFeature(image, geometry, scale, band, thresholdFn);
|
|
|
print(waterGeometry);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define an image, geometry,
|
|
|
scale, band, and threshold function. - Call the identifyWaterFeature
|
|
|
function with the defined inputs. - The function will return the
|
|
|
geometry of the identified water feature. - Print or use the
|
|
|
waterGeometry variable to access the geometry.
|
|
|
|
|
|
``` javascript
|
|
|
var image = ee.Image("example_image"); // example image
|
|
|
var geometry = ee.Geometry.Point(0, 0); // example geometry
|
|
|
var scale = 30; // example scale
|
|
|
var band = "example_band"; // example band
|
|
|
var thresholdFn = function (ndwi, band, geometry, scale) {
|
|
|
// example threshold function
|
|
|
var threshold = ee.Number(0.01);
|
|
|
return threshold;
|
|
|
};
|
|
|
var waterGeometry = identifyWaterFeature(image, geometry, scale, band, thresholdFn);
|
|
|
print(waterGeometry);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **generateTransectsStatistics**
|
|
|
|
|
|
*This function generates statistics for transects based on a given
|
|
|
baseline and shorelines, and returns the modified transects with
|
|
|
additional properties.*
|
|
|
|
|
|
``` javascript
|
|
|
var generateTransectsStatistics = function (
|
|
|
transects,
|
|
|
baseline,
|
|
|
shorelines,
|
|
|
keepProps
|
|
|
) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- transects: a feature collection representing the transects. -
|
|
|
baseline: a feature representing the baseline for distance
|
|
|
calculations. - shorelines: a feature collection representing the
|
|
|
shorelines for distance calculations. - keepProps: an array of property
|
|
|
names to keep from the original transects.
|
|
|
|
|
|
``` javascript
|
|
|
var transects = ee.FeatureCollection("example_transects"); // example transects
|
|
|
var baseline = ee.Feature("example_baseline"); // example baseline
|
|
|
var shorelines = ee.FeatureCollection("example_shorelines"); // example shorelines
|
|
|
var keepProps = ["prop1", "prop2"]; // example property names
|
|
|
var transectsStats = generateTransectsStatistics(transects, baseline, shorelines, keepProps);
|
|
|
print(transectsStats);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a feature collection representing the modified transects with
|
|
|
additional properties.
|
|
|
|
|
|
``` javascript
|
|
|
var transects = ee.FeatureCollection("example_transects"); // example transects
|
|
|
var baseline = ee.Feature("example_baseline"); // example baseline
|
|
|
var shorelines = ee.FeatureCollection("example_shorelines"); // example shorelines
|
|
|
var keepProps = ["prop1", "prop2"]; // example property names
|
|
|
var transectsStats = generateTransectsStatistics(transects, baseline, shorelines, keepProps);
|
|
|
print(transectsStats);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the transects,
|
|
|
baseline, shorelines, and keepProps. - Call the
|
|
|
generateTransectsStatistics function with the defined inputs. - The
|
|
|
function will return the modified transects with additional
|
|
|
properties. - Print or use the transectsStats variable to access the
|
|
|
modified transects.
|
|
|
|
|
|
``` javascript
|
|
|
var transects = ee.FeatureCollection("example_transects"); // example transects
|
|
|
var baseline = ee.Feature("example_baseline"); // example baseline
|
|
|
var shorelines = ee.FeatureCollection("example_shorelines"); // example shorelines
|
|
|
var keepProps = ["prop1", "prop2"]; // example property names
|
|
|
var transectsStats = generateTransectsStatistics(transects, baseline, shorelines, keepProps);
|
|
|
print(transectsStats);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **calculateDistances**
|
|
|
|
|
|
*This function calculates the distances between a transect and a
|
|
|
baseline, as well as the distances between the transect and multiple
|
|
|
shorelines. It returns a dictionary with the calculated distances and
|
|
|
additional metadata.*
|
|
|
|
|
|
``` javascript
|
|
|
var calculateDistances = function (transect, baseline, shorelines) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- transect: a feature representing the transect. - baseline: a feature
|
|
|
representing the baseline. - shorelines: a feature collection
|
|
|
representing the shorelines.
|
|
|
|
|
|
``` javascript
|
|
|
var transect = ee.Feature("example_transect"); // example transect
|
|
|
var baseline = ee.Feature("example_baseline"); // example baseline
|
|
|
var shorelines = ee.FeatureCollection("example_shorelines"); // example shorelines
|
|
|
var distances = calculateDistances(transect, baseline, shorelines);
|
|
|
print(distances);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a dictionary containing the calculated distances and additional
|
|
|
metadata.
|
|
|
|
|
|
``` javascript
|
|
|
var transect = ee.Feature("example_transect"); // example transect
|
|
|
var baseline = ee.Feature("example_baseline"); // example baseline
|
|
|
var shorelines = ee.FeatureCollection("example_shorelines"); // example shorelines
|
|
|
var distances = calculateDistances(transect, baseline, shorelines);
|
|
|
print(distances);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the transect,
|
|
|
baseline, and shorelines. - Call the calculateDistances function with
|
|
|
the defined inputs. - The function will return a dictionary with the
|
|
|
calculated distances and additional metadata. - Print or use the
|
|
|
distances variable to access the calculated distances.
|
|
|
|
|
|
``` javascript
|
|
|
var transect = ee.Feature("example_transect"); // example transect
|
|
|
var baseline = ee.Feature("example_baseline"); // example baseline
|
|
|
var shorelines = ee.FeatureCollection("example_shorelines"); // example shorelines
|
|
|
var distances = calculateDistances(transect, baseline, shorelines);
|
|
|
print(distances);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **withPrefix**
|
|
|
|
|
|
*This function takes a string as input and adds the prefix "cassie:" to
|
|
|
it. It returns the modified string.*
|
|
|
|
|
|
``` javascript
|
|
|
var withPrefix = function (str) { return "cassie:" + str};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- str: a string that needs to be modified.
|
|
|
|
|
|
``` javascript
|
|
|
var str = "example string"; // example input string
|
|
|
var modifiedStr = withPrefix(str);
|
|
|
print(modifiedStr);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- a string with the prefix "cassie:" added to it.
|
|
|
|
|
|
``` javascript
|
|
|
var str = "example string"; // example input string
|
|
|
var modifiedStr = withPrefix(str);
|
|
|
print(modifiedStr);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a string that needs
|
|
|
to be modified. - Call the withPrefix function with the defined string
|
|
|
as the input. - The function will return the modified string. - Print or
|
|
|
use the modifiedStr variable to access the modified string.
|
|
|
|
|
|
``` javascript
|
|
|
var str = "example string"; // example input string
|
|
|
var modifiedStr = withPrefix(str);
|
|
|
print(modifiedStr);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **calculateStatistics**
|
|
|
|
|
|
*`This`` ``JavaScript`` ``function`` ``calculates`` ``various`` ``statistics`` ``from`` ``a`` ``given`` ``measurement.`` ``The`` ``measurement`` ``is`` ``expected`` ``to`` ``be`` ``a`` ``dictionary`` ``with`` ``distance`` ``and`` ``date`` ``values.`` ``The`` ``function`` ``calculates`` ``the`` ``earliest,`` ``latest,`` ``closest,`` ``and`` ``farthest`` ``measurements,`` ``as`` ``well`` ``as`` ``SCE`` ``(Shoreline`` ``Change`` ``Envelope),`` ``NSM`` ``(Net`` ``Shoreline`` ``Movement),`` ``EPR`` ``(End`` ``Point`` ``Rate),`` ``LRR`` ``(Linear`` ``Regression`` ``Rate),`` ``correlation,`` ``and`` ``R-squared`` ``values.`` ``Additionally,`` ``it`` ``labels`` ``the`` ``data`` ``using`` ``the`` ``Esteves`` ``method`` ``and`` ``formats`` ``the`` ``first`` ``and`` ``last`` ``dates`` ``to`` ``ISO`` ``standard`` ``format`` ``in`` ``UTC.`*
|
|
|
|
|
|
``` javascript
|
|
|
var calculateStatistics = function (measurement) {
|
|
|
...
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- measurement: a dictionary containing distance and date values for
|
|
|
each measurement.
|
|
|
|
|
|
``` javascript
|
|
|
var measurement = {distance: 100, date: new Date()}; // example input
|
|
|
var stats = calculateStatistics(measurement);
|
|
|
console.log(stats);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- A dictionary containing the calculated statistics: SCE, NSM, EPR,
|
|
|
LRR, correlation, R-squared values, Esteves label, first and last dates,
|
|
|
and internal data such as count, trend, and regression.
|
|
|
|
|
|
``` javascript
|
|
|
var measurement = {distance: 100, date: new Date()}; // example input
|
|
|
var stats = calculateStatistics(measurement);
|
|
|
console.log(stats);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a measurement
|
|
|
dictionary with distance and date values. - Call the calculateStatistics
|
|
|
function with the defined measurement as the input. - The function will
|
|
|
return a dictionary with the calculated statistics. - Use console.log or
|
|
|
similar to view the returned statistics.
|
|
|
|
|
|
``` javascript
|
|
|
var measurement = {distance: 100, date: new Date()}; // example input
|
|
|
var stats = calculateStatistics(measurement);
|
|
|
console.log(stats);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **estevesLabelling**
|
|
|
|
|
|
`This function is used to classify land cover based on a given Land Ruggedness Index (LRR) value.`
|
|
|
|
|
|
``` javascript
|
|
|
var estevesLabelling = function (lrr) {
|
|
|
var classification = ee.Algorithms.If(
|
|
|
lrr.lt(-1.0),
|
|
|
ESTEVES_LABELS["Critically Eroded"].class,
|
|
|
ee.Algorithms.If(
|
|
|
lrr.lt(-0.5),
|
|
|
ESTEVES_LABELS["Eroded"].class,
|
|
|
ee.Algorithms.If(
|
|
|
lrr.lt(0.5),
|
|
|
ESTEVES_LABELS["Stable"].class,
|
|
|
ESTEVES_LABELS["Accreted"].class
|
|
|
)
|
|
|
)
|
|
|
);
|
|
|
return ee.String(classification);
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- lrr: The Land Ruggedness Index (LRR) value used for classification.
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- Classification: The land cover classification based on the given LRR
|
|
|
value.
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
1\. Define the Land Ruggedness Index (LRR) value. 2. Call the function
|
|
|
"estevesLabelling" with the LRR value as the input. 3. The function will
|
|
|
classify the land cover based on the LRR value and return the
|
|
|
classification.
|
|
|
|
|
|
``` javascript
|
|
|
<Given a code example for the call function>;
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **complementaryProperties**
|
|
|
|
|
|
*This function takes a transect, a measurement, and a list of properties
|
|
|
to keep as input. It generates complementary properties based on the
|
|
|
input and returns a summary with the combined properties.*
|
|
|
|
|
|
``` javascript
|
|
|
var complementaryProperties = function (transect, measurement, keepProps) {
|
|
|
var props = ee.Dictionary(
|
|
|
ee.Algorithms.If(keepProps, transect.toDictionary(keepProps), {})
|
|
|
);
|
|
|
/* Distances properties */
|
|
|
var distanceInfo = measurement.values();
|
|
|
var dates = serializeList(
|
|
|
distanceInfo.map( function (item) {
|
|
|
// Format Data as ISO standart formating and and UTC
|
|
|
return ee.Date(ee.Dictionary(item).get("date")).format(null, 'UTC')
|
|
|
})
|
|
|
);
|
|
|
var distances = serializeList(
|
|
|
distanceInfo.map(function (item) { return ee.Dictionary(item).getNumber("distance")})
|
|
|
);
|
|
|
/* Coordinates properties */
|
|
|
var coordinates = transect.geometry().coordinates();
|
|
|
var start = ee.List(coordinates.get(0)),
|
|
|
end = ee.List(coordinates.get(1));
|
|
|
var longStart = start.getNumber(0),
|
|
|
longEnd = end.getNumber(0);
|
|
|
var latStart = start.getNumber(1),
|
|
|
latEnd = end.getNumber(1);
|
|
|
/* Summary */
|
|
|
var summary = ee.Dictionary({
|
|
|
longStart: longStart,
|
|
|
longEnd: longEnd,
|
|
|
latStart: latStart,
|
|
|
latEnd: latEnd,
|
|
|
dates: dates,
|
|
|
distances: distances,
|
|
|
});
|
|
|
return summary.combine(props);
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- transect: The transect object. - measurement: The measurement
|
|
|
object. - keepProps: A list of properties to keep.
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- summary: A summary object containing the combined properties.
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a transect object. -
|
|
|
Define a measurement object. - Define a list of properties to keep
|
|
|
(optional). - Call the complementaryProperties function with the defined
|
|
|
transect, measurement, and keepProps as inputs. - The function will
|
|
|
generate complementary properties based on the input and return a
|
|
|
summary object with the combined properties.
|
|
|
|
|
|
``` javascript
|
|
|
var transect = ...; // define transect object
|
|
|
var measurement = ...; // define measurement object
|
|
|
var keepProps = ...; // define list of properties to keep (optional)
|
|
|
var summary = complementaryProperties(transect, measurement, keepProps);
|
|
|
print(summary);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **serializeList**
|
|
|
|
|
|
*This function takes a subject as input and serializes it into a string
|
|
|
format. It converts a list into a string representation enclosed in
|
|
|
square brackets.*
|
|
|
|
|
|
``` javascript
|
|
|
var serializeList = function (subject) {
|
|
|
return ee.String('"[').cat(ee.List(subject).join(",")).cat(']"');
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- subject: The list to be serialized.
|
|
|
|
|
|
``` javascript
|
|
|
var myList = [1, 2, 3]; // example input list
|
|
|
var serializedString = serializeList(myList);
|
|
|
print(serializedString);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- serializedString: A string representation of the input list, enclosed
|
|
|
in square brackets.
|
|
|
|
|
|
``` javascript
|
|
|
var myList = [1, 2, 3]; // example input list
|
|
|
var serializedString = serializeList(myList);
|
|
|
print(serializedString);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a list that needs to
|
|
|
be serialized. - Call the serializeList function with the defined list
|
|
|
as the input. - The function will return a string representation of the
|
|
|
input list, enclosed in square brackets. - Print or use the
|
|
|
serializedString variable to access the serialized list.
|
|
|
|
|
|
``` javascript
|
|
|
var myList = [1, 2, 3]; // example input list
|
|
|
var serializedString = serializeList(myList);
|
|
|
print(serializedString);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **combineReducers**
|
|
|
|
|
|
*This function takes two reducers as input and combines them into a
|
|
|
single reducer. It returns the combined reducer.*
|
|
|
|
|
|
``` javascript
|
|
|
var combineReducers = function (reducer01, reducer02) {
|
|
|
return reducer01.combine(reducer02, "", true);
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- reducer01: The first reducer to be combined. - reducer02: The second
|
|
|
reducer to be combined.
|
|
|
|
|
|
``` javascript
|
|
|
var reducer1 = ...; // example input reducer 1
|
|
|
var reducer2 = ...; // example input reducer 2
|
|
|
var combinedReducer = combineReducers(reducer1, reducer2);
|
|
|
print(combinedReducer);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- combinedReducer: The combined reducer.
|
|
|
|
|
|
``` javascript
|
|
|
var reducer1 = ...; // example input reducer 1
|
|
|
var reducer2 = ...; // example input reducer 2
|
|
|
var combinedReducer = combineReducers(reducer1, reducer2);
|
|
|
print(combinedReducer);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define two reducers that
|
|
|
need to be combined. - Call the combineReducers function with the
|
|
|
defined reducers as inputs. - The function will return the combined
|
|
|
reducer. - Print or use the combinedReducer variable to access the
|
|
|
combined reducer.
|
|
|
|
|
|
``` javascript
|
|
|
var reducer1 = ...; // example input reducer 1
|
|
|
var reducer2 = ...; // example input reducer 2
|
|
|
var combinedReducer = combineReducers(reducer1, reducer2);
|
|
|
print(combinedReducer);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **expandHorizontally**
|
|
|
|
|
|
*This function takes a list of transects and an amount as input. It
|
|
|
expands each transect horizontally by the specified amount and returns
|
|
|
the expanded transects.*
|
|
|
|
|
|
``` javascript
|
|
|
var expandHorizontally = function (transects, amount) {
|
|
|
amount = ee.Number(amount).divide(2);
|
|
|
var mapper = function (transect) {
|
|
|
transect = ee.Feature(transect);
|
|
|
var coords = transect.geometry().coordinates();
|
|
|
var a = ee.List(coords.get(0));
|
|
|
var b = ee.List(coords.get(1));
|
|
|
var theta = computeBearing(a.get(0), a.get(1), b.get(0), b.get(1)).add(
|
|
|
Math.PI
|
|
|
);
|
|
|
var alpha = theta.add(Math.PI * 0.5);
|
|
|
var beta = theta.subtract(Math.PI * 0.5);
|
|
|
var a1 = computeDisplacement(a.get(0), a.get(1), alpha, amount);
|
|
|
var a2 = computeDisplacement(a.get(0), a.get(1), beta, amount);
|
|
|
var b1 = computeDisplacement(b.get(0), b.get(1), alpha, amount);
|
|
|
var b2 = computeDisplacement(b.get(0), b.get(1), beta, amount);
|
|
|
var rectangle = ee.Feature(ee.Geometry.Polygon([[a1, a2, b2, b1]]));
|
|
|
return rectangle.copyProperties(transect);
|
|
|
};
|
|
|
return transects.map(mapper);
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- transects: A list of transects to be expanded. - amount: The amount
|
|
|
by which the transects should be expanded horizontally.
|
|
|
|
|
|
``` javascript
|
|
|
var transects = ...; // example input transects
|
|
|
var amount = 100; // example input amount
|
|
|
var expandedTransects = expandHorizontally(transects, amount);
|
|
|
print(expandedTransects);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- expandedTransects: The expanded transects.
|
|
|
|
|
|
``` javascript
|
|
|
var transects = ...; // example input transects
|
|
|
var amount = 100; // example input amount
|
|
|
var expandedTransects = expandHorizontally(transects, amount);
|
|
|
print(expandedTransects);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a list of transects
|
|
|
that need to be expanded. - Specify the amount by which the transects
|
|
|
should be expanded horizontally. - Call the expandHorizontally function
|
|
|
with the defined transects and amount as inputs. - The function will
|
|
|
return the expanded transects. - Print or use the expandedTransects
|
|
|
variable to access the expanded transects.
|
|
|
|
|
|
``` javascript
|
|
|
var transects = ...; // example input transects
|
|
|
var amount = 100; // example input amount
|
|
|
var expandedTransects = expandHorizontally(transects, amount);
|
|
|
print(expandedTransects);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **summaryShorelineStatistics**
|
|
|
|
|
|
`This function calculates summary statistics for shoreline distances.`
|
|
|
|
|
|
``` javascript
|
|
|
var summaryShorelineStatistics = function (transects, shorelines) {
|
|
|
// Code explanation goes here
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- transects: A list of transects. - shorelines: A feature collection of
|
|
|
shorelines.
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- A feature collection with summary statistics for each shoreline.
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
`To use the summaryShorelineStatistics function, follow these steps:`
|
|
|
`1. Call the function and provide the transects and shorelines as inputs.`
|
|
|
|
|
|
2\. Retrieve the output feature collection.
|
|
|
|
|
|
``` javascript
|
|
|
var result = summaryShorelineStatistics(transects, shorelines);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
#### **sequence**
|
|
|
|
|
|
*This function generates a sequence of numbers starting from 0 up to a
|
|
|
given number n-1.*
|
|
|
|
|
|
``` javascript
|
|
|
var sequence = function (n) {
|
|
|
var start = 0;
|
|
|
return Array.from(Array(n).keys()).map(function (val) {return val + start});
|
|
|
};
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- n: a number indicating the length of the sequence.
|
|
|
|
|
|
``` javascript
|
|
|
var n = 5; // example input number
|
|
|
var result = sequence(n);
|
|
|
console.log(result);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- An array of numbers representing the sequence from 0 to n-1.
|
|
|
|
|
|
``` javascript
|
|
|
var n = 5; // example input number
|
|
|
var result = sequence(n);
|
|
|
console.log(result);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define a number n indicating
|
|
|
the length of the desired sequence. - Call the sequence function with n
|
|
|
as the input. - The function will return an array of numbers
|
|
|
representing the sequence. - Print or use the result variable to access
|
|
|
the generated sequence.
|
|
|
|
|
|
``` javascript
|
|
|
var n = 5; // example input number
|
|
|
var result = sequence(n);
|
|
|
console.log(result);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr>
|
|
|
|
|
|
#### **generateColors**
|
|
|
|
|
|
*This function generates a specified number of colors based on the
|
|
|
amount and lightness parameters. It uses the ColorConverter library to
|
|
|
convert the colors from HSL to hexadecimal format.*
|
|
|
|
|
|
``` javascript
|
|
|
var generateColors = function (amount, lightness) {
|
|
|
var slice = amount=== 1 ? 0 : 240.0 / (amount - 1);
|
|
|
return sequence(amount).map(function (i) {
|
|
|
return "#" + ColorConverter.hsl.hex(slice * i, 100, lightness);
|
|
|
});
|
|
|
}
|
|
|
```
|
|
|
|
|
|
##### **Inputs:**
|
|
|
|
|
|
\- amount: a number indicating the desired number of colors to
|
|
|
generate. - lightness: a number indicating the lightness value for the
|
|
|
generated colors.
|
|
|
|
|
|
``` javascript
|
|
|
var amount = 5; // example input number
|
|
|
var lightness = 50; // example input number
|
|
|
var colors = generateColors(amount, lightness);
|
|
|
console.log(colors);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Output:**
|
|
|
|
|
|
\- An array of colors represented in hexadecimal format.
|
|
|
|
|
|
``` javascript
|
|
|
var amount = 5; // example input number
|
|
|
var lightness = 50; // example input number
|
|
|
var colors = generateColors(amount, lightness);
|
|
|
console.log(colors);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
|
|
|
##### **Use**
|
|
|
|
|
|
To use this function, follow these steps: - Define the amount of colors
|
|
|
to generate and the desired lightness value. - Call the generateColors
|
|
|
function with the defined parameters. - The function will return an
|
|
|
array of colors represented in hexadecimal format. - Print or use the
|
|
|
colors variable to access the generated colors.
|
|
|
|
|
|
``` javascript
|
|
|
var amount = 5; // example input number
|
|
|
var lightness = 50; // example input number
|
|
|
var colors = generateColors(amount, lightness);
|
|
|
console.log(colors);
|
|
|
```
|
|
|
|
|
|
<hr>
|
|
|
<hr> |