Thông báo: Tất cả dự án phi thương mại đã đăng ký sử dụng Earth Engine trước ngày 15 tháng 4 năm 2025 phải xác minh điều kiện sử dụng phi thương mại để duy trì quyền truy cập vào Earth Engine.
Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Lớp dữ liệu Cường độ thay đổi của sự xuất hiện nước cung cấp thông tin đo lường về mức độ thay đổi của nước trên bề mặt giữa 2 giai đoạn: 1984 – 1999 và 2000 – 2015. Lớp này tính trung bình mức thay đổi trên các cặp tháng tương đồng lấy từ hai giai đoạn. Hãy xem
Hướng dẫn sử dụng dữ liệu (phiên bản 2)
để biết thêm thông tin chi tiết về lớp này.
Phần này của hướng dẫn sẽ:
thêm một lớp bản đồ có kiểu để trực quan hoá cường độ thay đổi của sự xuất hiện nước, và
tóm tắt cường độ thay đổi trong một vùng quan tâm cụ thể bằng biểu đồ.
Hình ảnh trực quan
Tương tự như lớp xuất hiện của nước, chúng ta sẽ bắt đầu bằng cách thêm một hình ảnh trực quan cơ bản về cường độ thay đổi xuất hiện vào bản đồ, sau đó cải thiện hình ảnh đó. Cường độ thay đổi tần suất xuất hiện được cung cấp theo 2 cách, cả dưới dạng giá trị tuyệt đối và giá trị được chuẩn hoá. Chúng ta sẽ sử dụng các giá trị tuyệt đối trong hướng dẫn này.
Bắt đầu bằng cách chọn lớp cường độ thay đổi tuyệt đối về số lần xuất hiện trong hình ảnh GSW:
Trong phần Hằng số của mã, hãy thêm một câu lệnh tạo một biến mới xác định cách tạo kiểu cho lớp. Kiểu này cho thấy những khu vực có sự xuất hiện của nước mặt giảm/tăng bằng màu đỏ/xanh lục. Những khu vực có nước trên bề mặt tương đối không thay đổi sẽ có màu đen.
Trong phần này, chúng ta sẽ tóm tắt mức độ thay đổi trong một khu vực quan tâm cụ thể. Để chỉ định một khu vực quan tâm, hãy nhấp vào công cụ vẽ đa giác. Đây là một trong những
Công cụ hình học.
Thao tác này sẽ tạo một lớp Nhập hình học mới, theo mặc định có tên là "geometry" (hình học). Để thay đổi tên, hãy nhấp vào biểu tượng bánh răng ở bên phải tên lớp. (Xin lưu ý rằng bạn có thể cần đặt con trỏ lên tên lớp để tên lớp xuất hiện.)
Đổi tên lớp thành roi (đối với vùng quan tâm hoặc ROI). Sau đó, chúng ta có thể nhấp vào một loạt điểm trên bản đồ để xác định một vùng đa giác mà chúng ta quan tâm.
Hình 7. Ảnh chụp màn hình sông Ucayali gần Pucallpa, Peru, với một vùng quan tâm được tạo bằng công cụ vẽ đa giác.
Giờ đây, khi đã xác định và lưu trữ khu vực quan tâm trong một biến, chúng ta có thể dùng biến đó để tính toán biểu đồ tần suất của cường độ thay đổi cho ROI. Thêm mã sau vào phần Calculations (Tính toán) của tập lệnh.
Câu lệnh đầu tiên tính toán biểu đồ tần suất của các giá trị cường độ thay đổi xuất hiện trong ROI, lấy mẫu ở tỷ lệ 30m. Lệnh thứ hai in đối tượng kết quả vào Thẻ bảng điều khiển của Trình chỉnh sửa mã. Bạn có thể mở rộng cây đối tượng để xem các giá trị của các nhóm biểu đồ.
Dữ liệu dạng số vẫn có, nhưng có những cách trực quan hoá kết quả hiệu quả hơn.
Hình 8. Kết quả của thẻ Bảng điều khiển, cho thấy các giá trị biểu đồ về cường độ thay đổi của nước mặt.
Để cải thiện điều này, chúng ta có thể tạo biểu đồ phân bố thay thế. Thay thế câu lệnh xác định đối tượng biểu đồ bằng các câu lệnh sau:
Các câu lệnh này tạo một đối tượng biểu đồ, thay thế cây đối tượng biểu đồ trong Thẻ điều khiển bằng một biểu đồ. Phương thức biểu đồ chứa một số đối số, bao gồm scale (xác định tỷ lệ không gian, tính bằng mét, mà tại đó vùng quan tâm được lấy mẫu) và minBucketWidth (được dùng để kiểm soát chiều rộng của các nhóm biểu đồ tần suất).
Hình 9. Kết quả trên thẻ Console, cho thấy biểu đồ tần suất về cường độ thay đổi của nước mặt.
Bạn có thể khám phá các giá trị trên biểu đồ một cách tương tác bằng cách đặt con trỏ lên các thanh biểu đồ tần suất.
Tập lệnh cuối cùng
Toàn bộ tập lệnh cho phần này được liệt kê bên dưới. Xin lưu ý rằng tập lệnh này bao gồm các câu lệnh để xác định một hình học đa giác (roi), có thể so sánh với hình học mà bạn đã tạo bằng các công cụ hình học của Trình chỉnh sửa mã.
[null,null,["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[[["\u003cp\u003eThe Water Occurrence Change Intensity data layer shows surface water changes between 1984-1999 and 2000-2015.\u003c/p\u003e\n"],["\u003cp\u003eThis tutorial demonstrates visualizing water occurrence change intensity with a styled map layer, using red for decreased and green for increased surface water.\u003c/p\u003e\n"],["\u003cp\u003eIt also covers summarizing the change intensity within a user-defined region of interest using a histogram chart generated in the Code Editor.\u003c/p\u003e\n"],["\u003cp\u003eUsers can interactively explore the chart to understand the distribution of surface water change intensity values within their chosen region.\u003c/p\u003e\n"],["\u003cp\u003eThe tutorial utilizes the Global Surface Water dataset and provides JavaScript code examples for implementation in Google Earth Engine.\u003c/p\u003e\n"]]],["The core content details analyzing changes in surface water between 1984-1999 and 2000-2015. Key actions include visualizing \"water occurrence change intensity\" using absolute values and a defined color palette (red for decrease, green for increase, black for no change). Users can define a region-of-interest (ROI) and calculate a histogram to summarize the change intensity within that area. The process involves generating and customizing a histogram chart, which is then printed to the console for interactive exploration.\n"],null,["# Water Occurrence Change Intensity\n\nThe Water Occurrence Change Intensity data layer provides a measure of how surface water has\nchanged between two epochs: 1984-1999 and 2000-2015. The layer averages the change across\nhomologous pairs of months taken from the two epochs. See the\n[Data Users Guide (v2)](https://storage.googleapis.com/global-surface-water/downloads_ancillary/DataUsersGuidev2.pdf) for additional details on this layer.\n\nThis section of the tutorial will:\n\n1. add a styled map layer for visualizing water occurrence change intensity, and\n2. summarize the change intensity in a specified region-of-interest using a histogram.\n\nVisualization\n-------------\n\nSimilar to the water occurrence layer, we will start by adding a basic visualization of\noccurrence change intensity to the map and then improve upon it. Occurrence change intensity\nis provided in two ways, both as absolute and normalized values. We will use the absolute\nvalues in this tutorial.\nStart by selecting the absolute occurrence change intensity layer from the GSW image:\n\n### Code Editor (JavaScript)\n\n```javascript\nvar change = gsw.select(\"change_abs\");\n```\n\nIn the Constants section of the code, add a statement that creates a new variable that\ndefines how the layer will be styled. This styling shows areas where the surface water\noccurrence has decreased/increased in red/green. Areas where surface water occurrence\nis relatively unchanged are shown in black.\n\n### Code Editor (JavaScript)\n\n```javascript\nvar VIS_CHANGE = {\n min:-50,\n max:50,\n palette: ['red', 'black', 'limegreen']\n};\n```\n\nAt the end of the Map Layers section of code, add a statement that adds a new layer to\nthe map.\n\n### Code Editor (JavaScript)\n\n```javascript\nMap.setCenter(-74.4557, -8.4289, 11); // Ucayali River, Peru\nMap.addLayer({\n eeObject: change,\n visParams: VIS_CHANGE,\n name: 'occurrence change intensity'\n});\n```\nFigure 6. Screenshot of a surface water change intensity for the Ucayali River near Pucallpa, a city in the Amazonian rainforest of eastern Peru. Red/green indicates a decrease/increase in surface water occurrence between the epochs.\n\nSummarizing Change within a Region of Interest\n----------------------------------------------\n\nIn this section, we will summarize the amount of change within a specified region of\ninterest. To specify a region of interest, click on the polygon drawing tool, which is one of\nthe\n[Geometry tools](/earth-engine/guides/playground#geometry-tools).\nThis will create a new Geometry Imports layer, which is named \"geometry\"\nby default. To change the name, click on the gear icon located to the right of the to the\nlayer name. (Note that you may need to place your cursor on the layer name to make it appear.)\n\nChange the layer name to `roi` (for region-of-interest or ROI). We then can click on a\nseries of points on the map to define a polygon region of interest.\nFigure 7. Screenshot of the Ucayali River near Pucallpa, Peru, with a region-of-interest created by using the polygon drawing tool.\n\nNow that our region-of-interest is defined and stored in a variable, we can use it to\ncalculate a histogram of the change intensity for the ROI. Add the following code to the\nCalculations section of the script.\n\n### Code Editor (JavaScript)\n\n```javascript\n// Calculate a change intensity for the region of interest.\nvar histogram = change.reduceRegion({\n reducer: ee.Reducer.histogram(),\n geometry: roi,\n scale: 30,\n bestEffort: true,\n});\nprint(histogram);\n```\n\nThe first statement calculates a histogram of occurrence change intensity values within the\nROI, sampling at a 30m scale. The second prints the resulting object to the Code Editor\nConsole Tab. You can expand out the object tree to view the values of the histogram buckets.\nThe numeric data is there, but there are better ways to visualize the results.\nFigure 8. Console tab results, showing histogram values of surface water change intensity.\n\nTo improve upon this, we can generate a histogram chart instead. Replace the statement that\ndefines the histogram object with the following statements:\n\n### Code Editor (JavaScript)\n\n```javascript\n// Generate a histogram object and print it to the console tab.\nvar histogram = ui.Chart.image.histogram({\n image: change,\n region: roi,\n scale: 30,\n minBucketWidth: 10\n});\nhistogram.setOptions({\n title: 'Histogram of surface water change intensity.'\n});\n```\n\nThese statements create a histogram chart object, which replaces the histogram object tree\nin the Console Tab with a chart. The chart method contains several arguments, including\n`scale` which defines the spatial scale, in meters, at which the region of interest'\nis sampled, and\n`minBucketWidth` which is used to control the width of the histogram\nbuckets.\nFigure 9. Console tab results, showing a histogram chart of surface water change intensity.\n\nYou can explore the chart values interactively by placing your cursor over the histogram\nbars.\n\nFinal Script\n------------\n\nThe entire script for this section is listed below. Note that the script includes statements\nfor defining a polygon geometry (`roi`), which is comparable to the geometry that\nyou created using the Code Editor's geometry tools.\n\n### Code Editor (JavaScript)\n\n```javascript\n//////////////////////////////////////////////////////////////\n// Asset List\n//////////////////////////////////////////////////////////////\n\nvar gsw = ee.Image('JRC/GSW1_0/GlobalSurfaceWater');\nvar occurrence = gsw.select('occurrence');\nvar change = gsw.select(\"change_abs\");\nvar roi = /* color: 0B4A8B */ee.Geometry.Polygon(\n [[[-74.17213, -8.65569],\n [-74.17419, -8.39222],\n [-74.38362, -8.36980],\n [-74.43031, -8.61293]]]);\n\n//////////////////////////////////////////////////////////////\n// Constants\n//////////////////////////////////////////////////////////////\n\nvar VIS_OCCURRENCE = {\n min:0,\n max:100,\n palette: ['red', 'blue']\n};\nvar VIS_CHANGE = {\n min:-50,\n max:50,\n palette: ['red', 'black', 'limegreen']\n};\nvar VIS_WATER_MASK = {\n palette: ['white', 'black']\n};\n\n//////////////////////////////////////////////////////////////\n// Calculations\n//////////////////////////////////////////////////////////////\n\n// Create a water mask layer, and set the image mask so that non-water areas are transparent.\nvar water_mask = occurrence.gt(90).mask(1);\n\n// Generate a histogram object and print it to the console tab.\nvar histogram = ui.Chart.image.histogram({\n image: change,\n region: roi,\n scale: 30,\n minBucketWidth: 10\n});\nhistogram.setOptions({\n title: 'Histogram of surface water change intensity.'\n});\nprint(histogram);\n\n//////////////////////////////////////////////////////////////\n// Initialize Map Location\n//////////////////////////////////////////////////////////////\n\n// Uncomment one of the following statements to center the map on\n// a particular location.\n// Map.setCenter(-90.162, 29.8597, 10); // New Orleans, USA\n// Map.setCenter(-114.9774, 31.9254, 10); // Mouth of the Colorado River, Mexico\n// Map.setCenter(-111.1871, 37.0963, 11); // Lake Powell, USA\n// Map.setCenter(149.412, -35.0789, 11); // Lake George, Australia\n// Map.setCenter(105.26, 11.2134, 9); // Mekong River Basin, SouthEast Asia\n// Map.setCenter(90.6743, 22.7382, 10); // Meghna River, Bangladesh\n// Map.setCenter(81.2714, 16.5079, 11); // Godavari River Basin Irrigation Project, India\n// Map.setCenter(14.7035, 52.0985, 12); // River Oder, Germany & Poland\n// Map.setCenter(-59.1696, -33.8111, 9); // Buenos Aires, Argentina\\\nMap.setCenter(-74.4557, -8.4289, 11); // Ucayali River, Peru\n\n//////////////////////////////////////////////////////////////\n// Map Layers\n//////////////////////////////////////////////////////////////\n\nMap.addLayer({\n eeObject: water_mask,\n visParams: VIS_WATER_MASK,\n name: '90% occurrence water mask',\n shown: false\n});\nMap.addLayer({\n eeObject: occurrence.updateMask(occurrence.divide(100)),\n name: \"Water Occurrence (1984-2015)\",\n visParams: VIS_OCCURRENCE,\n shown: false\n});\nMap.addLayer({\n eeObject: change,\n visParams: VIS_CHANGE,\n name: 'occurrence change intensity'\n});\n```\n\nIn the [next section](/earth-engine/tutorials/tutorial_global_surface_water_04), you will further\nexplore how water changed over time, by working with the water class **transition** layer."]]