如何使用JavaScript根据ShapeFile剪辑Geotiff?

发布于 2025-01-26 03:46:03 字数 2248 浏览 2 评论 0原文

情况:我正在使用ReactJS和Geotiff.js在地图上的Geotiff文件中绘制数据。我正在使用的geotiff文件的一个示例是以下链接:

我想做的:当用户单击特定状态(区域或任何特定形状)时,TIFF文件中提供的数据仅适用于该形状。基本上,我想根据给定的形状将数据夹在Geotiff文件中(假设我具有形状边界定义。进一步的形状边界的投影系统和Geotiff文件是相同的)。

请建议使用Georaster,Leflet,Georaster-Layer-For-For-for Leaflet或其他一些库。

这是目前的代码,可以在地图上显示整个TIFF数据。

代码:

import { useEffect, useRef } from "react";
import proj4 from "proj4";
import { useLeafletContext } from "@react-leaflet/core";
import { useMap } from "react-leaflet";
import parseGeoraster from "georaster";
import GeoRasterLayer from "georaster-layer-for-leaflet";

window.proj4 = proj4;

const GeotiffLayer = ({ url, options }) => {
const geoTiffLayerRef = useRef();
const context = useLeafletContext();
const map = useMap();

useEffect(() => {
    const container = context.layerContainer || context.map;

    fetch(url)
        .then((response) => response.arrayBuffer())
        .then((arrayBuffer) => {
            console.log(arrayBuffer);
            parseGeoraster(arrayBuffer).then((georaster) => {
                console.log("georaster:", georaster.values[0][1]);
                options.georaster = georaster;
                geoTiffLayerRef.current = new GeoRasterLayer(options);
                container.addLayer(geoTiffLayerRef.current);

                map.fitBounds(geoTiffLayerRef.current.getBounds());
            });
        });

    // return () => {
    //     container.removeLayer(geoTiffLayerRef.current);
    // };
}, [context, url, map, options]);

return null;
};

export default GeotiffLayer;

输出:

图1说明了地图上显示的整个TIFF文件。

图2说明了单击特定状态后的输出。
单击特定状态后输出“

我想做的事情:当用户点击特定状态时,只能显示TIFF数据,而不是针对其他形状显示形状。

请建议使用Georaster,Leflet,Georaster-Layer-For-For-for Leaflet或其他一些图书馆建议任何方法。

Situation: I am plotting data provided in a GeoTIFF file on a map using Reactjs and geoTiff.js. An example of the GeoTiff files I am using is at the following link: https://drive.google.com/file/d/1yc2Lo5vQrFPAJRe5VklorrvIXuhB1nE0/view.

What I want to do: When the user clicks on a specific state (district or any specific shape) then the data provided in the tiff file should be visible only for that shape. Basically, I want to clip the data in the GeoTIFF file according to a given shape (assuming I have the shape boundary definitions. Further the projection system of the shape boundaries and the GeoTiff file are the same).

Please suggest any approach using georaster, leaflet, georaster-layer-for-leaflet, or some other library.

Here is the code as of now to show whole tiff data on the map.

Code:

import { useEffect, useRef } from "react";
import proj4 from "proj4";
import { useLeafletContext } from "@react-leaflet/core";
import { useMap } from "react-leaflet";
import parseGeoraster from "georaster";
import GeoRasterLayer from "georaster-layer-for-leaflet";

window.proj4 = proj4;

const GeotiffLayer = ({ url, options }) => {
const geoTiffLayerRef = useRef();
const context = useLeafletContext();
const map = useMap();

useEffect(() => {
    const container = context.layerContainer || context.map;

    fetch(url)
        .then((response) => response.arrayBuffer())
        .then((arrayBuffer) => {
            console.log(arrayBuffer);
            parseGeoraster(arrayBuffer).then((georaster) => {
                console.log("georaster:", georaster.values[0][1]);
                options.georaster = georaster;
                geoTiffLayerRef.current = new GeoRasterLayer(options);
                container.addLayer(geoTiffLayerRef.current);

                map.fitBounds(geoTiffLayerRef.current.getBounds());
            });
        });

    // return () => {
    //     container.removeLayer(geoTiffLayerRef.current);
    // };
}, [context, url, map, options]);

return null;
};

export default GeotiffLayer;

Output:

Fig 1 illustrates the whole tiff file shown on the map.
Fig 1 illustrates the whole tiff file shown on the map.

Fig 2 illustrates the output after a click on the specific state.
illustrates the output after a click on the specific state

What I want to do: When the user clicks on the specific state then tiff data should be shown only for the selected shape, not for other shapes.

Please suggest any approach using georaster, leaflet, georaster-layer-for-leaflet, or some other library.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文