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

news2024/9/23 23:23:11

简介

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.coloradmin.cn/o/1645148.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

VastGaussian:用于大型场景重建的巨大3D高斯函数

VastGaussian:用于大型场景重建的巨大3D高斯函数 摘要IntroductionRelated WorkPreliminariesMethod VastGaussian: Vast 3D Gaussians for Large Scene Reconstruction. 摘要 现有基于NeRF的大型场景重建方法在视觉效果和渲染速度方面往往存在限制。虽然最近的3D高斯分裂在小…

宝兰德通过广东教育行业信创适配认证,拓展教育信创生态圈

近日&#xff0c;由宝兰德自主研发的多款中间件产品通过广东省教育行业信创适配中心的适配测试。测试表明&#xff0c;宝兰德四款中间件产品&#xff08;分布式缓存软件V3.0、应用服务器软件V9.5、消息中间件软件 V2.1、Web服务器软件V3.1&#xff09; 与当前主流国产操作系统统…

SpringBoot集成阿里云短信验证码服务

一&#xff1a;前言 最近在项目开发过程中&#xff0c;需要去写一个发送手机短信验证码的功能。在网上查了一下&#xff0c;有很多服务器可供选择&#xff0c;本文的话是基于阿里云服务的短信验证码功能实现。 关于注册和开通服务这些需要操作的&#xff0c;请各位小伙伴参考官…

Flutter开发Dart中的队列(Queue)

文章目录 Dart中的队列&#xff08;Queue&#xff09;基本操作示例队列的类型队列的应用总结 Dart中的队列&#xff08;Queue&#xff09; 队列是一种抽象的数据结构&#xff0c;遵循“先进先出”&#xff08;FIFO&#xff09;的原则。这意味着最早添加的元素将首先被移除。队…

品高虚拟化后端存储的发展演进

在品高虚拟化技术不断发展的过程中&#xff0c;虚拟化的后端存储一直是关注的焦点之一。 本文将从最初的文件存储和NFS开始&#xff0c;追溯到集中式存储SAN&#xff0c;然后选择了Ceph的RBD方式&#xff0c;并最终抵达选择支持vhost协议的后端存储的现状&#xff0c;我们将探…

银价下跌怎么办?现货白银买卖分析方法要掌握

现货白银买卖分析是进行现货白银投资的基础&#xff0c;尤其是近几个交易日现货白银价格出现了下跌后&#xff0c;更加凸显了买卖分析能力在市场中的重要性。不光要会买&#xff0c;还得懂得如何卖。下面我们来介绍2个现货白银买卖分析的方法。 基于RSI指标的现货白银买卖分析。…

python+barcode快速生成条形码(电商测试小工具)

背景 需要测试自助收银机&#xff0c;每次都要在线生成条码&#xff0c;而且生成次数还有限制 需求 满足自定义条形码&#xff0c;可以生成条形码图片 方案 python 3.8以上 barcode 1.0.4 python-barcode 0.15.1 代码 用于生成Code128条形码…

WINDOWS配置IIS

1.安装IIS 1.1.打开启用Windows功能 打开“控制面板” > “程序和功能” > “启用或关闭 Windows 功能”。 1.2.启用IIS功能 打开“控制面板” > “程序和功能” > “启用或关闭 Windows 功能”。 勾选“Internet Information Services”&#xff0c;然后点击“确定…

学习中遇到的问题

1.UFUNCTION() 不是所有函数都能加UFUNCTION()修饰&#xff0c;涉及UE反射机制。 2.初始化用{} 初始化列表 3.创建C文件时修改了路径 这时.cpp文件会报错&#xff0c;只需删掉前面多余路径即可 4.函数的移除 1.虚幻5.1 UUserWidget不再包含OnLevelRemovedFromWorld() 转而使用…

ai续写软件哪个好?盘点3款经典好用的!

随着科技的不断发展&#xff0c;AI续写软件逐渐成为了许多内容创作者、学生、研究人员等的得力助手。这类软件能够通过机器学习和自然语言处理技术&#xff0c;为用户提供高质量的文本续写服务。但市场上众多的AI续写软件让人眼花缭乱&#xff0c;那么&#xff0c;究竟哪款AI续…

Nftables漏洞原理分析(CVE-2022-32250)

前言 在nftales中存在着集合(sets)&#xff0c;用于存储唯一值的集合。sets 提供了高效地检查一个元素是否存在于集合中的机制&#xff0c;它可以用于各种网络过滤和转发规则。 而CVE-2022-32250漏洞则是由于nftables在处理set时存在uaf的漏洞。 环境搭建 ubuntu20 QEMU-4…

透明加密软件选哪个好?选择时一定要注意以下三点

透明加密软件哪个好&#xff1f; 这是许多企事业单位在面临数据防泄漏问题时经常思考的问题。随着信息技术的发展&#xff0c;企业的数据安全变得越来越重要。透明加密技术作为一种有效的数据保护手段&#xff0c;被越来越多的企业所采用。然而&#xff0c;市场上的透明加密软…

项目实战 | 如何恰当的处理 Vue 路由权限

前言 哈喽&#xff0c;小伙伴你好&#xff0c;我是 嘟老板。最近接了一个成本千万级的前端项目运维工作&#xff0c;本着 知己知彼 的态度&#xff0c;我将整个前端的大致设计思路过了一遍。不看不知道&#xff0c;一看…吓一跳。光是 路由权限 这块儿的设计&#xff0c;都让我…

Q1保健品线上市场分析(一):护眼需求不减,叶黄素软糖卖爆!

如今网络时代的高速发展&#xff0c;用眼过度逐渐成为国人的常态&#xff0c;无论是儿童还是青少年、成年人、老年人&#xff0c;都可能面临眼部健康的问题。 在这样的大环境下&#xff0c;预防大于治疗的概念不断深入日常生活&#xff0c;进而推动了护眼产品市场的高速发展&a…

1W 3KVDC 隔离 稳压单输出 DC/DC 电源模块 ——TPV-SAR 系列

TPV-SAR系列产品是专门针对PCB上分布式电源系统中需要与输入电源隔离且输出精度要求较高的电源应用场合而设计。该产品适用于&#xff1b;1&#xff09;输入电源的电压变化≤5%&#xff1b;2&#xff09;输入输出之前要求隔离电压≥3000VDC&#xff1b;3&#xff09;对输出电压…

python学习笔记-01

python 在学习之前要了解的事项&#xff1a; 1.python缩进语法要求较为严格 2.是解释型语言 3.python2版本和python3版本不兼容 本系列笔记全部基于python3 1.hello world 安装好python之后&#xff0c;可以直接打开python&#xff0c;也可以通过cmd进入python。 print(&qu…

【如此简单!数据库入门系列】之存储设备简介

文章目录 1 前言2 存储设备分类3 主存层次结构4 磁盘结构5 RAID6 总结7 系列文章 1 前言 没有存储&#xff0c;就没有数据&#xff01; 如果说ER模型和数据库规范化是数据库概念模式的技术和方法&#xff0c;那么存储设备就是数据库物理模式的基础。 物理存储设备包含哪些类型…

河南大学大礼堂火灾事故引发安防监控对智能分析技术应用的思考

一、方案背景 2024年5月2日&#xff0c;在修缮施工期间的河南大学河南留学欧美预备学校旧址大礼堂发生火情。现场航拍画面显示&#xff0c;大礼堂经过火灾&#xff0c;房顶已经基本坍塌&#xff0c;被火烧过的建筑呈焦黑状。 公开资料显示&#xff0c;大礼堂属河南留学欧美预…

小程序激励广告视频多次回调问题

1.问题 2. 激励视频使用及解决方案 官方文档 let videoAd null; // 在页面中定义激励视频广告 Page({/*** 页面的初始数据*/data: {},/*** 生命周期函数--监听页面加载*/onLoad(options) {let that this;// 创建激励视频广告实例if (wx.createRewardedVideoAd) {videoAd w…

Docker镜像仓库-在私有镜像仓库推送或拉取镜像

推送镜像到私有仓库&#xff0c;要先让镜像打包 前缀为私有仓库地址的名字&#xff1a; 这里也是打包成功了:docker images 可以查看到 push推送镜像到镜像仓库: docker push 192.168.221.129:8080/nginx:1.0推送成功后在主机访问镜像仓库可以看到 这里已经有个镜像了。而且可…