GEE错误——image.reduceRegion is not a function

简介

image.reduceRegion is not a function

这里的主要问题是我们进行地统计分析的时候,我们的作用对象必须是单景影像,而不是影像集合

错误"image.reduceRegion is not a function" 表示你正在尝试使用reduceRegion()函数来处理图像数据,但是该函数在所使用的图像对象上并不存在。这通常发生在以下几种情况下:

  1. 你使用的图像对象并不是由Earth Engine提供的图像数据类型。只有Earth Engine提供的图像数据类型,如Image、ImageCollection等,才包含reduceRegion()函数。确保你使用的图像对象是Earth Engine提供的类型。

  2. 你使用的图像对象是一个空对象或没有加载任何数据。如果图像对象为空,那么该对象上是没有reduceRegion()函数的。请确保你加载了正确的图像数据,或者使用其他方法创建图像对象。

  3. 你使用了错误的函数名称。请检查你的代码,确保你使用的是reduceRegion()而不是其他名称类似的函数。

请根据具体情况查看你的代码,并根据上述解释进行适当的修改。

代码

var landsat = ee.ImageCollection("LANDSAT/LC08/C02/T1_L2"),
    imageVisParam = {"opacity":1,"bands":["B7","B6","B4"],"min":11451.624047549685,"max":13348.162011801593,"gamma":1},
    blore = 
    /* color: #0b4a8b */
    /* shown: false */
    /* displayProperties: [
      {
        "type": "rectangle"
      }
    ] */
    ee.Geometry.Polygon(
        [[[77.1829215561055, 13.595511689413932],
          [77.1829215561055, 12.530677550689433],
          [78.1167594467305, 12.530677550689433],
          [78.1167594467305, 13.595511689413932]]], null, false),
    pol_CO = ee.ImageCollection("COPERNICUS/S5P/OFFL/L3_CO"),
    pol_NO2 = ee.ImageCollection("COPERNICUS/S5P/OFFL/L3_NO2"),
    pol_CH4 = ee.ImageCollection("COPERNICUS/S5P/OFFL/L3_CH4"),
    pol_SO2 = ee.ImageCollection("COPERNICUS/S5P/OFFL/L3_SO2"),
    pol_O3 = ee.ImageCollection("COPERNICUS/S5P/OFFL/L3_O3");
var parks = ee.FeatureCollection('projects/ee-koushikyash/assets/Ban_parks_10ha');

var i = 1;
var bufferDis = 50

// create new buffer
var newBuffer = function(feature) {
  var geometry = feature.geometry();
  var buffer = geometry.buffer(bufferDis * i);
  // print(i)
  buffer = buffer.difference(geometry)
  var newFeature = ee.Feature(buffer, feature.toDictionary());
 
  return newFeature;
};

// subtract geometry
var subtractGeometries = function(feature1, feature2) {
  var geometry1 = feature1.geometry();
  var geometry2 = feature2.geometry();
  return geometry1.difference(geometry2);
};

var allBuffers = ee.List([])

var parks_0 = parks;
Map.addLayer(parks_0, {}, 'Buffer around Bangalore Parks ' + (0));
allBuffers = allBuffers.add(parks_0)
var prev = parks_0
var colors = ["Red", "Green", "Orange", "Yellow", "Pink"]

var total = 5;
for(var j = 0; j < total; j++){
  var parks_1 = parks.map(newBuffer)
  var temp = parks_1
  parks_1 = parks_1.map(function(f1) {
    var index = parks_1.toList(parks_1.size()).indexOf(f1)
    var f2 = ee.Feature(prev.toList(prev.size()).get(index))
    return ee.Feature(subtractGeometries(f1, f2), f1.toDictionary())
  });
  
  // changing state
  prev = temp
  i += 1
  allBuffers = allBuffers.add(parks_1)
  
  Map.addLayer(parks_1,  {color: colors[j]}, 'Buffer around Bangalore Parks ' + (i));
}

//Add pollutant images
var image_so2 = pol_SO2.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('SO2_column_number_density')
            .mean()
            .clip(parks)
            
var image_no2 = pol_NO2.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('NO2_column_number_density')
            .mean()
            .clip(parks)
            
            
var image_ch4 = pol_CH4.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('CH4_column_volume_mixing_ratio_dry_air')
            .mean()
            .clip(parks)

var image_o3 = pol_O3.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('O3_column_number_density')
            .mean()
            .clip(parks)

var image_co = pol_CO.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('CO_column_number_density')
            .mean()
            .clip(parks) 
            

// Check the type of image
print("Type of image_so2:", typeof image_so2);

// Check if image_so2 is an ee.Image object
print("Is image_so2 an ee.Image?", image_so2 instanceof ee.Image);

// Check the type of park
print("Type of a park feature:", typeof parks.get(0));
print(parks.first());
// Check if a park feature is an ee.Feature object
print("Is a park feature an ee.Feature?", parks.first() instanceof ee.Feature);

// Check if the geometry method is available on a park feature
print("Does park feature have a geometry method?", parks.get(0).geometry !== undefined);

// var sampleFeature = parks.first();
// var geometry = sampleFeature.geometry();
// print("Geometry of sample feature:", geometry);

// var featureCount = parks.size();
// print("Number of features in parks:", featureCount);

// Function to calculate pollutant statistics for each park
var calculateStatistics = function(image, park) {
  var stats = image.reduceRegion({
    reducer: ee.Reducer.mean().combine({
    reducer2: ee.Reducer.minMax(),
    sharedInputs: true
    }),
    geometry: park.geometry(),
    scale: 30,
    maxPixels: 1e9
  });
  
  // Map over the stats to format them as features
  var features = ee.Feature(null, stats)
    .set('date', image.date().format('YYYY-MM-dd'))
    .set('park_name', park.get('name')); // Assuming 'name' is the property containing park names
  
  return features;
};

// Function to get statistics for all pollutants and parks
var getResults = function(parks, images) {
  var results = ee.List(images).map(function(image) {
    var stats = parks.map(function(park) {
      return calculateStatistics(image, ee.Feature(park));
    });
    return stats;
  }).flatten();
  
  return results;
};

// Function to format the results
var format = function(table) {
  var rows = table.distinct('date');
  var columns = parks.aggregate_array('name'); 
  var formattedResults = rows.map(function(row) {
    var date = row.get('date');
    var parkStats = table.filter(ee.Filter.eq('date', date));
    var values = parkStats.aggregate_array('pollutant_min', 'pollutant_max', 'pollutant_mean');
    return ee.Feature(null, values).set('date', date);
  });
  
  return formattedResults;
};

// Export to CSV function
var exportToCsv = function(table, desc, name) {
  Export.table.toDrive({
    collection: table,
    description: desc,
    fileNamePrefix: name,
    fileFormat: "CSV"
  });
};

// Assuming you have defined the pollutant images (image_so2, image_no2, etc.) and parks beforehand

// Get data for all pollutants and parks

var image_so2 = pol_SO2.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('SO2_column_number_density')
            .mean()
            .clip(parks)
            
var image_no2 = pol_NO2.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('NO2_column_number_density')
            .mean()
            .clip(parks)
            
            
var image_ch4 = pol_CH4.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('CH4_column_volume_mixing_ratio_dry_air')
            .mean()
            .clip(parks)

var image_o3 = pol_O3.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('O3_column_number_density')
            .mean()
            .clip(parks)

var image_co = pol_CO.filterBounds(parks)
            .filterDate('2024-01-01', '2024-01-31')
            .select('CO_column_number_density')
            .mean()
            .clip(parks) 
            
var images = [image_so2, image_no2, image_ch4, image_o3, image_co]; 

//checking the type of iamges array
print(images);

var results = getResults(parks, images);

// Format the results
var formattedResults = format(results);

// Export the formatted results to CSV
exportToCsv(formattedResults, "PollutantStatistics", "pollutant_stats");

正确解析

 这里的正确思路是我们需要进行分析,也就是说我们的作用对象是影像,而非影像集合,所以这里我们不能混淆这里两个概念,首先看一下两个函数的差异:

ee.Image(args)

An object to represent an Earth Engine image. This constructor accepts a variety of arguments:

  • A string: an EarthEngine asset id,

  • A string and a number: an EarthEngine asset id and version,

  • A number or ee.Array: creates a constant image,

  • A list: creates an image out of each list element and combines them into a single image,

  • An ee.Image: returns the argument,

  • Nothing: results in an empty transparent image.

Arguments:

args (Image|List<Object>|Number|Object|String, optional):

Constructor argument.

Returns: Image

ee.ImageCollection(args)

ImageCollections can be constructed from the following arguments:

  • A string: assumed to be the name of a collection,

  • A list of images, or anything that can be used to construct an image.

  • A single image.

  • A computed object - reinterpreted as a collection.

Arguments:

args (ComputedObject|Image|List<Object>|String):

The constructor arguments.

Returns: ImageCollection

这是两个之间的差异,然后再看reduce region的函数

reduceRegion(reducer, geometryscalecrscrsTransformbestEffortmaxPixelstileScale)

Apply a reducer to all the pixels in a specific region.

Either the reducer must have the same number of inputs as the input image has bands, or it must have a single input and will be repeated for each band.

Returns a dictionary of the reducer's outputs.

Arguments:

this:image (Image):

The image to reduce.

reducer (Reducer):

The reducer to apply.

geometry (Geometry, default: null):

The region over which to reduce data. Defaults to the footprint of the image's first band.

scale (Float, default: null):

A nominal scale in meters of the projection to work in.

crs (Projection, default: null):

The projection to work in. If unspecified, the projection of the image's first band is used. If specified in addition to scale, rescaled to the specified scale.

crsTransform (List, default: null):

The list of CRS transform values. This is a row-major ordering of the 3x2 transform matrix. This option is mutually exclusive with 'scale', and replaces any transform already set on the projection.

bestEffort (Boolean, default: false):

If the polygon would contain too many pixels at the given scale, compute and use a larger scale which would allow the operation to succeed.

maxPixels (Long, default: 10000000):

The maximum number of pixels to reduce.

tileScale (Float, default: 1):

A scaling factor between 0.1 and 16 used to adjust aggregation tile size; setting a larger tileScale (e.g. 2 or 4) uses smaller tiles and may enable computations that run out of memory with the default.

Returns: Dictionary

具体分析

这里其实最主要的问题是我们作用的对象是image,但是这里我们要写入function的时候,我们写入的方式不对,所以这里出现了错误,这里的问题就在于我们需要重新解析我们的函数,函数需要重新分开来操作,整体的思路是我们要map,也就是对每一个操作的影像进行分析,然后添加属性什么的问题就可以进行了。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mfbz.cn/a/597021.html

如若内容造成侵权/违法违规/事实不符,请联系我们进行投诉反馈qq邮箱809451989@qq.com,一经查实,立即删除!

相关文章

MySQL数据库—多表设计(有这一篇够!)

▐ 数据库设计范式 • 第一范式&#xff1a;确保每列保持原子性 ( 列不可再分解 ) 例如联系方式包括&#xff1a;电话/邮箱/微信... 那么我们设计表时就需要将它具体化 • 第二范式&#xff1a;要有主键&#xff0c;通过主键可以精确的定位到某行数据. 其他字段都依赖于主…

JAVA----Thread(2

Thread 提供的属性和方法 目录 Thread 提供的属性和方法一.构造方法1.Thread() :2.Thread(Runnable target) :3.Thread(String name) :main 线程 4.Thread(Runnable target, String name) : 二.属性1.ID (getId)2.名称(getName)3.状态(getState)4.优先级 (getPriority)5.是否后…

如何用中医揿针治疗肩周炎?

点击文末领取揿针的视频教程跟直播讲解 首先我们先来了解什么是肩周炎 【中医辨证】 肩周炎中医称之为漏肩风、锁肩风、肩凝症等&#xff0c;将肩周炎的一系列症状归纳为痹证的范畴&#xff0c;故又有肩痹、肩胛周痹等病名。 在中医古典医籍《素问痹论》中有骨痹、筋痹、脉…

LangChain Agent最全教程学习

LangChain Agent的终极指南&#xff0c;本教程是您使用 Python 创建第一个agent的重要指南&#xff0c;请立即开始你的 LLM 开发之旅。 一、什么是LangChain Agent&#xff08;代理&#xff09; LangChain中代理背后的想法是利用语言模型以及要执行的一系列操作。代理正在使用…

C++常用库函数——strcmp、strchr

1、strcmp&#xff1a;比较两个字符串的值是否相等 例如 char a1[6] "AbDeG",*s1 a1;char a2[6] "AbdEg",* s2 a2;s1 2;s2 2;printf("%d \n", strcmp(s1, s2));return(0); s1指向a1&#xff0c;s2指向a2&#xff0c;strcmp表示比较s1和s…

Stable Diffusion学习记录

文章目录 前言电脑配置推荐环境搭建下载地址安装步骤步骤一&#xff0c;打开下载的秋叶整合包&#xff0c;路径秋叶整合包/sd-wenui-aki步骤二&#xff0c;打开下载好的sd-webui-aki-v4.8.7解压包 Stable Diffusion软件配置&#xff0c;插件安装&#xff0c;模型下载Stable Dif…

四川易点慧电子商务抖音小店:潜力无限的新零售风口

在当今数字化浪潮中&#xff0c;电子商务已经成为推动经济发展的重要引擎。四川易点慧电子商务有限公司凭借其敏锐的市场洞察力和创新精神&#xff0c;成功在抖音小店这一新兴平台上开辟出一片新天地。本文将探讨四川易点慧电子商务抖音小店的潜力及其在新零售领域的影响力。 一…

C#知识|如何在WinForm窗体中实现分割线绘制?

哈喽&#xff0c;你好啊&#xff0c;我是雷工&#xff01; 在上位机UI设计中经常会用到分割线&#xff0c;用来分割界面区域。 像在KingSCADA、杰控、昆仑通态、WinCC、组态王、力控、易控等组态软件中非常简单&#xff0c;有现成的划线操作&#xff0c;选中相关工具直接绘制即…

Python接口自动化测试之【测试函数、测试类/测试方法的封装】

前言 在pythonpytest 接口自动化系列中&#xff0c;我之前的文章基本都没有将代码进行封装&#xff0c;但实际编写自动化测试脚本中&#xff0c;我们都需要将测试代码进行封装&#xff0c;才能被测试框架识别执行。 例如单个接口的请求代码如下&#xff1a; import requests …

高效转化,智能私信软件策略揭秘

在数字营销的浪潮中&#xff0c;智能私信软件策略正成为提升转化率的重要工具。这种软件以其个性化、自动化的特点&#xff0c;正在重新定义与客户的互动方式&#xff0c;让企业能够更加高效地吸引并留住潜在客户。 智能私信软件的核心在于其高度的定制化和人性化设计。通过大数…

【LLama】Llama3 的本地部署与lora微调(基于xturn)

系列课程代码文档&#xff08;前2节课可跳过&#xff09;&#xff1a;https://github.com/SmartFlowAI/Llama3-Tutorial 课程视频&#xff1a;https://space.bilibili.com/3546636263360696/channel/series XTuner &#xff1a;https://github.com/InternLM/xtuner/blob/main/R…

[C++]VS2022配置cplex12.8过程中出现ext未声明标识符语法错误:标识符“ImplClass“

这个时候&#xff0c;主要的是看报错&#xff0c;根据报错&#xff0c;去网上寻找解决办法。因为这个时候&#xff0c;代码可能并没有任何错误&#xff0c;只不过你是VS2022&#xff0c;老师是VS2017或者其他版本。不同的版本之间代码运行问题&#xff0c;如果你换成cplex12.10…

全网详细的PostgreSQL数据库详细的安装步骤教学

安装 PostgreSQL 数据库的步骤因操作系统的不同而有所差异。以下是在 Windows、Linux 和 macOS 上安装 PostgreSQL 的详细步骤&#xff1a; Windows 上安装 PostgreSQL 下载安装程序&#xff1a; 访问 PostgreSQL 官方网站&#xff08;https://www.postgresql.org/&#xff09…

Linux服务器常用巡检命令

在Linux服务器上进行常规巡检是确保服务器稳定性和安全性的重要措施之一。以下是一些常用的巡检命令和技巧&#xff1a; 1. 查看系统信息 1.1 系统信息显示 命令&#xff1a;uname -a ​​​​ [rootlinux100 ~]# uname -a Linux linux100 4.15.0-70-generic #79-Ubuntu SMP…

激发创新活力,泸州老窖锻造人才“铁军”(内附长江酒道短评)

执笔 | 姜 姜 编辑 | 古利特 刚刚站上300亿元新台阶&#xff0c;泸州老窖再次传来喜讯。 <<<左右滑动查看更多>>> 4月28日&#xff0c;四川省庆祝“五一”国际劳动节大会在成都召开。泸州老窖股份有限公司工业4.0项目秘书长赵丙坤、泸州老窖酿酒有限责任公…

Leetcode—387. 字符串中的第一个唯一字符【简单】

2024每日刷题&#xff08;127&#xff09; Leetcode—387. 字符串中的第一个唯一字符 实现代码 class Solution { public:int firstUniqChar(string s) {int count[26] {0};for(char c: s) {count[c - a];}for(int i 0; i < s.length(); i) {if(count[s[i] - a] 1) {re…

Partisia Blockchain 生态zk跨链DEX上线,加密资产将无缝转移

在 5 月 1 日&#xff0c;由 Partisia Blockchain 与 zkCross 创建合作推出的 Partisia zkCrossDEX 在 Partisia Blockchain 生态正式上线。Partisia zkCrossDEX 是 Partisia Blockchain 上重要的互操作枢纽&#xff0c;其融合了 zkCross 的 zk 技术跨链互操作方案&#xff0c;…

【简单介绍下7-Zip】

&#x1f3a5;博主&#xff1a;程序员不想YY啊 &#x1f4ab;CSDN优质创作者&#xff0c;CSDN实力新星&#xff0c;CSDN博客专家 &#x1f917;点赞&#x1f388;收藏⭐再看&#x1f4ab;养成习惯 ✨希望本文对您有所裨益&#xff0c;如有不足之处&#xff0c;欢迎在评论区提出…

分享几个副业,一天搞100~200不成问题,一不小心收益比你主业还多

每次家庭聚会&#xff0c;总是那些老掉牙的话题在耳边萦绕&#xff1a;“孩子&#xff0c;你工资多少啊&#xff1f;买车买房了吗&#xff1f;”仿佛只有按部就班地上班、结婚生子&#xff0c;才是人生的唯一出路。 然而&#xff0c;在这个充满机遇的时代&#xff0c;谁说“不上…

【go项目01_学习记录03】

学习记录 1 路由http.ServeMux1.1 查看HandleFunc方法源码1.2 查看ListenAndServe方法源码1.3 重构&#xff1a;使用自定义的 ServeMux1.4 http.ServeMux 的局限性1.4.1 URI 路径参数1.4.2 请求方法过滤1.4.3 不支持路由命名 1.5 http.ServeMux 的优缺点 1 路由http.ServeMux …