当前位置: 首页 > article >正文

ArcGIS API for JavaScript 缓冲区分析、河涌关联分析、集中连片分析

1、ArcGIS API for JavaScript 实现缓冲区分析、河涌关联分析、集中连片分析。
2、场景需求:查询缓冲区域范围的鱼塘;查询某条河涌关联的鱼塘;鱼塘的集中连片性。
3、vue页面实现代码示例:

<template>
   <div/>
</template>
<script>
import * as geometryEngine from '@arcgis/core/geometry/geometryEngine.js'
import Graphic from '@arcgis/core/Graphic'
export default {
	props: {
        mapAndView: {
            type: Object,
            default: () => {
                return {}
            }
        }
    },
    data() {
        return {
            
        }
    },
    computed: {
        ...mapState({
            highlight: state => state.map.highlight,
            distance: state => state.aquaculture.distance,
            buffer: state => state.aquaculture.spatialAnalyse.buffer,
            riverRelated: state => state.aquaculture.spatialAnalyse.riverRelated,
            continuous: state => state.aquaculture.spatialAnalyse.continuous
        })
    },
	mounted() {
        this.addMapClickEventListener()
    },
	methods: {
		 addMapClickEventListener() {
            const clickHandler = this.mapAndView.on('click', event => {
                this.mapAndView.hitTest(event).then(async res => {
                    if (!res.results.length) {
                        return
                    }
                    let graphic = res.results[0].graphic
                    //缓冲区分析
                    if (this.buffer) {
                        this.goAndHighlight(graphic)
                        this.doBuffer(graphic.geometry, this.distance)
                    }
                    //河涌关联分析
                    if (this.riverRelated && graphic.layer.id === 'riverLayer') {
                        this.goAndHighlight(graphic)
                        this.doRiverRelated(graphic.geometry, this.distance)
                    }
                    //养殖场、鱼塘集中连片分析
                    if (this.continuous && (graphic.layer.id === 'aquacultureLayer' || graphic.layer.id === 'pondLayer')) {
                        this.mapAndView.graphics.removeAll()
                        this.doCentrallyContinuous(graphic.geometry, 20, graphic.layer.id)
                    }
                })
            })

            this.$once('hook:beforeDestroy', () => {
                if (clickHandler) {
                    clickHandler.remove()
                }
            })
        },
        //高亮与定位
        goAndHighlight(graphic) {
            this.mapAndView.whenLayerView(graphic.layer).then(layerView => {
                if (this.highlight) {
                    this.highlight.remove()
                }
                this.$store.commit('map/setHighlight', layerView.highlight(graphic))
                this.mapAndView.goTo({ target: graphic })
            })
        },
        // 空间几何图形查询
		queryFeaturesByGeometry(mapView, layerId, geometry, relationship) {
		    if (!mapView?.map) {
		        return
		    }
		    const queryLayer = mapView.map.findLayerById(layerId)
		    if (!queryLayer) {
		        return
		    }
		    return queryLayer.queryFeatures({
		        geometry: geometry, // 绘制的范围(点、线、面等几何图形)
		        outFields: ['*'], // 返回的字段
		        returnGeometry: true, // 是否返回geometry
		        spatialRelationship: relationship || 'intersects', // // 空间关系:相交、包含等
		        where: '' // 其它查询条件,格式参考sql语句,例如status = 1;
		    }).then(res => {
		        if (res.features.length) {
		            return res.features
		        }
		    })
		 },
		 // 缓冲区分析  distance:缓冲区距离(数值类型)
		 async doBuffer(geometry, distance) {
		     // 根据距离获取缓冲区域图形
		     const bufferGeometry = geometryEngine.geodesicBuffer(geometry, distance, 'meters')// 缓冲区
		     //缓冲区域添加在地图上的渲染效果
		     let symbol = {
		         type: 'simple-fill',
		         color: 'rgba(255,0,255,0.3)',
		         outline: {
		             color: '#F0DB6F',
		             style: 'dot',
		             width: 1
		         }
		     }
		     let graphic = new Graphic({ 
		         geometry: bufferGeometry,
		         symbol: symbol 
		     })
			 this.mapAndView.graphics.removeAll()
		     this.mapAndView.graphics.add(graphic)
		     // 空间查询缓冲区范围内的鱼塘
		     fishPondFeatures = await this.queryFeaturesByGeometry(this.mapAndView, 'pondLayer', bufferGeometry)
		     console.log('缓冲区范围的鱼塘:',  fishPondFeatures)
		     //地图渲染鱼塘
		     this.renderGraphics(fishPondFeatures)
		 },
		 // 河涌关联分析(空间位置距离关联)  distance:缓冲区距离(数值类型)
        async doRiverRelated(geometry, distance) {
        	// 根据距离获取缓冲区域图形
        	const bufferGeometry = geometryEngine.geodesicBuffer(geometry, distance, 'meters')// 缓冲区
        	//缓冲区域添加在地图上的渲染效果
            let symbol = {
                type: 'simple-fill',
                color: 'rgba(0,255,0,0.3)',
                outline: {
                    color: '#F0DB6F',
                    style: 'dot',
                    width: 1
                }
            }
            let graphic = new Graphic({ 
                geometry: bufferGeometry,
                symbol: symbol 
            })

             this.mapAndView.graphics.removeAll()
		     this.mapAndView.graphics.add(graphic)
		     // 空间查询缓冲区范围内的鱼塘(河涌关联的鱼塘)
		     fishPondFeatures = await this.queryFeaturesByGeometry(this.mapAndView, 'pondLayer', bufferGeometry)
		     console.log('河涌关联的鱼塘:',  fishPondFeatures)
		      //地图渲染鱼塘
		     this.renderGraphics(fishPondFeatures)
        },
        // 养殖场、鱼塘的集中连片分析  distance:聚合距离(数值类型)
        async doCentrallyContinuous(geometry, distance, layerId) {
            // 聚合图形(缓冲区图形)
            // 第一次缓冲区查询
            let bufferGeometry = geometryEngine.geodesicBuffer(geometry, distance, 'meters')
            let features = await this.queryFeaturesByGeometry(this.mapAndView, layerId, bufferGeometry)
             // 第二次缓冲区查询( 第一次查询结果构建目标参数)
            let tempRings = []
            features.map(item => {
                tempRings.push(item.geometry.rings[0])
            })
            geometry.rings = tempRings
            bufferGeometry = geometryEngine.geodesicBuffer(geometry, distance, 'meters')
            let secondFeatures = await this.queryFeaturesByGeometry(this.mapAndView, layerId, bufferGeometry)
            // 多次缓冲查询,直到最后查询到的图形list数据相同为止
            if (JSON.stringify(secondFeatures) === JSON.stringify(features)) {
                //地图渲染集中连片区域
                let features = this.renderGraphics(secondFeatures)
            } else {
                //递归查询
                this.doCentrallyContinuous(geometry, distance, layerId)
            }
        },
        // 渲染集中连片区域
        renderGraphics(features) {
            let symbol = {
                type: 'simple-fill',
                color: 'rgba(255,0,255,0.3)',
                outline: {
                    color: '#F0DB6F',
                    width: 1
                }
            }
            let graphics = []
            features.map(item => {
                let graphic = new Graphic({ 
                    geometry: item.geometry,
                    attributes: item.attributes,
                    symbol: symbol 
                })
                graphics.push(graphic)
            })
            this.mapAndView.graphics.addMany(graphics)
            return features
        },
	}
}
</script>

http://www.kler.cn/a/466385.html

相关文章:

  • 力扣hot100——栈
  • C++和OpenGL实现3D游戏编程【连载19】——着色器光照初步(平行光和光照贴图)(附源码)
  • GitHub Fork 和 Clone 的深度指南:操作解析与 Pull Request 完整流程20241231
  • BGP基础配置实验
  • 如何使用Termux 通过 SSH 连接到远程服务器
  • 个人交友系统|Java|SSM|JSP|
  • 高速网络数据包处理中的内核旁路技术
  • Ae 效果详解:漩涡条纹
  • .NET 8 + Ocelot + Consul 实现代理网关、服务发现
  • 365天深度学习训练营:第N1周:one-hot编码案例
  • 【Unity3D】LOD Group 多细节层次(CrossFade淡出淡入效果)
  • java: JDK isn‘t specified for module ‘product-service‘问题解决
  • 大数据-269 实时数仓 - DIM DW ADS 层处理 Scala实现将数据写出HBase等
  • 阅读线程池源码中遇到的retry:
  • 密码学精简版
  • 打靶记录24——Presidential
  • 【JavaScript】变量-常量-数据类型-类型转换
  • 如何使用axios实现并发请求
  • 【漫话机器学习系列】033.决策树回归(Decision Tree Regression)
  • 移动构造函数详解
  • MySQL使用通用二进制文件安装到Unix/Linux
  • 32单片机从入门到精通之开发环境——调试工具(七)
  • nodeJS下npm和yarn的关系和区别详解
  • 嵌入式应用软件开发中C语言方向面试题
  • ClickHouse副本搭建
  • 关于AI面试系统2025年趋势评估!