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_1parks_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 stateprev = tempi += 1allBuffers = 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 featuresvar 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 namesreturn 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 parksvar 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.hqwc.cn/news/670444.html

如若内容造成侵权/违法违规/事实不符,请联系编程知识网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

电销卡与电话管家是什么

防封电销卡是啥&#xff1f; 也许有的人并不是很清晰&#xff0c;实际上防封电销卡也是电销业务流程运用避免封号的一种手机卡&#xff0c;它的作用实际上跟一般的用号码卡语音通话是类似的&#xff0c;唯独不一样的是防封电销卡是加入白名单的&#xff0c;让电销业务在开展的过…

使用C#和EF Core实现高效的SQL批量插入

在软件开发中&#xff0c;批量插入数据是一个常见的需求&#xff0c;特别是在数据迁移、初始化数据库或进行大量数据处理时。Entity Framework Core (EF Core) 是一个流行的.NET对象关系映射器&#xff08;ORM&#xff09;&#xff0c;它简化了数据库操作&#xff0c;但在进行大…

C语言知识点补充——ASCLL码表

1、ASCLL码表 ASCII码表&#xff08;American Standard Code for Information Interchange&#xff09;是一种用于将字符编码为数字的标准。它定义了128个字符的编码方式&#xff0c;包括数字、字母、标点符号和控制字符等。每个字符都对应一个唯一的7位或8位二进制数 2、Ascl…

(Arxiv,2024)Mind the Modality Gap:通过跨模态对齐建立遥感视觉语言模型

文章目录 相关资料摘要引言相关工作对比语言图像预训练遥感域专用 CLIP 模型遥感中的多模态 CLIP 启发模型 方法模型算法输入阶段&#xff1a;输出阶段&#xff1a;步骤说明&#xff1a; 第一阶段&#xff1a;通过权重插值修补CLIP将遥感图像模态与自然图像和文本对齐 实验 相关…

【C++】继承 — 继承的引入、赋值切片详细讲解

前言 我们知道C语言是一门面向对象编程的语言&#xff0c;而面向对象编程有三大特性&#xff0c;它们分别是&#xff1a; 封装继承多态 目录 1. 继承的概念及定义1.1继承的概念1.2继承的定义格式1.3 继承的使用 2 基类和派生类对象赋值转换3 继承中的作用域3.1 派生类对象的存…

升级OpenSSH版本(安装telnet远程管理主机)

一 OpenSSH是什么 OpenSSH 是 SSH &#xff08;Secure SHell&#xff09; 协议的免费开源实现。SSH协议族可以用来进行远程控制&#xff0c; 或在计算机之间传送文件。而实现此功能的传统方式&#xff0c;如telnet(终端仿真协议)、 rcp ftp、 rlogin、 rsh都是极为不安全的&…

融资融券利率最低多少:一文了解2024年最低融资融券开通攻略(利率4%-5%)

一、什么是融资融券利率&#xff1f; 融资融券利率通常指的是投资者在进行融资融券交易时需要支付给券商的利息费用的比率&#xff08;年化利率&#xff09;。 具体来说&#xff0c;融资融券利率包括两部分&#xff1a; 1、融资利率&#xff1a;这是客户借入资金进行证券买入…

75.网络游戏逆向分析与漏洞攻防-角色与怪物信息的更新-伪造服务端更新属性消息欺骗客户端

免责声明&#xff1a;内容仅供学习参考&#xff0c;请合法利用知识&#xff0c;禁止进行违法犯罪活动&#xff01; 如果看不懂、不知道现在做的什么&#xff0c;那就跟着做完看效果&#xff0c;代码看不懂是正常的&#xff0c;只要会抄就行&#xff0c;抄着抄着就能懂了 内容…

【精品毕设推荐】基于Javaee的影视创作论坛的设计与实现

点击下载原文及代码 摘 要 随着时代的发展&#xff0c;互联网的出现&#xff0c;给传统影视行业带来的最大便利就是&#xff0c;方便了影视从业人员以及爱好者的交流和互动&#xff0c;而为用户提供一个书写影评&#xff0c;阅读影评以及回复影评的平台&#xff0c;以影评为…

Java_从入门到JavaEE_09

一、构造方法/构造器 含义&#xff1a;和new一起是创建对象的功能 特点&#xff1a; 与类名相同的方法没有返回项 注意&#xff1a; 当类中没有写构造方法时&#xff0c;系统会默认添加无参构造&#xff08;无参数的构造方法&#xff09;构造方法可以重载的 有参构造好处&…

04 深入浅出JVM

本课时的主题是 JVM 原理。JVM 是 Java 程序运行基础&#xff0c;面试时一定会遇到 JVM 相关的题。本课时会先对面试中 JVM 的考察点进行汇总介绍。然后对 JVM 内存模型、Java 的类加载机制、常用的 GC 算法这三个知识点进行详细讲解。最后汇总 JVM 考察点和加分项&#xff0c;…

嵌入式5-6QT

1> 思维导图 2> 自由发挥应用场景&#xff0c;实现登录界面。 要求&#xff1a;尽量每行代码都有注释。 #include "mywidget.h"MyWidget::MyWidget(QWidget *parent): QWidget(parent) {//设置标题this->setWindowTitle("MYQQ");//设置图标this…