一些Arcgis操作

多值提取至點

https://desktop.arcgis.com/zh-cn/arcmap/latest/tools/spatial-analyst-toolbox/extract-multi-values-to-points.htm

參數說明數據類型
in_point_features

要添加柵格值的輸入點要素。

Feature Layer
in_rasters
[Raster, {Output Field Name}]

要基於輸入點要素的位置提取的輸入柵格值。

您還可以爲存儲柵格值的字段指定名稱。默認情況下,將根據輸入柵格數據集的名稱創建唯一的字段名稱。

Extract Values
bilinear_interpolate_values
(可選)

指定是否使用插值。

  • NONE — 不應用任何插值法;將使用像元中心值。這是默認設置。
  • BILINEAR — 將使用雙線性插值法根據相鄰像元的有效值計算像元值。除非所有相鄰像元都爲 NoData,否則會在插值時忽略 NoData 值。
Boolean

使用插值法將多個柵格的像元值提取到 shapefile 點要素類的屬性中。

# Name: ExtractMultiValuesToPoints_Ex_02.py
# Description: Extracts the cells of multiple rasters as attributes in
#    an output point feature class.  This example takes a multiband IMG
#    and two GRID files as input.
# Requirements: Spatial Analyst Extension

# Import system modules
import arcpy
from arcpy import env
from arcpy.sa import *

# Set environment settings
env.workspace = "C:/sapyexamples/data"

# Set local variables
inPointFeatures = "poi.shp"
inRasterList = [["doqq.img", "doqqval"], ["redstd", "focalstd"], 
                ["redmin", "focalmin"]]

# Check out the ArcGIS Spatial Analyst extension license
arcpy.CheckOutExtension("Spatial")

# Execute ExtractValuesToPoints
ExtractMultiValuesToPoints(inPointFeatures, inRasterList, "BILINEAR")

shp轉csv

直接使用geopandas庫讀取

#加載geopandas
import geopandas as gpd
#讀取geopandas
shp_file = r'E:\projects\weather\\VIIRS\樣本點全2.shp'
df_geo = gpd.read_file(shp_file)

刪除geometry座標信息

del df_geo['geometry']

csv轉shp

詳見之前文章

https://www.cnblogs.com/wkfvawl/p/16676691.html

grd轉tif

將Mrh文件下的所有grd文件都轉成tif文件

import arcpy
from arcpy.sa import *
import sys, string, os

idx = 'Mrh'
dir = r'E:\projects\weather\ANUSPLIN\mapdata\\'
path = dir + idx
files = os.listdir(path)
for f in files:
    if os.path.splitext(f)[1] == '.grd':
        Input_raster_file = path + os.sep + f
        Raster_Format = "TIFF"
        Output_Workspace = path
        basename = os.path.splitext(f)[0]
        Output_raster = Output_Workspace + os.sep + basename + '.tif'
        arcpy.RasterToOtherFormat_conversion(Input_raster_file, Output_Workspace, Raster_Format)
        print(Output_raster)
        os.remove(Input_raster_file)

批量裁剪柵格

核心ExtractByMask函數,兩個參數一個是被裁剪的柵格名,另一個是裁剪用的shp

import arcpy
from arcpy.sa import *
import sys, string, os
path = r'E:\數據\NDVI\\'
new = r'E:\數據\NDVI_tif\\'
shp = "E:\projects\weather\ANUSPLIN\mapdata\雲南省.shp"
files = os.listdir(path)
for f in files:
    name = 'ndvi' + f + 'a'
    out = new + f + '.tif'
    raster = arcpy.Raster(path + f + '\\' + name)#讀取adf文件
    outExtractByMask = ExtractByMask(raster,shp)
    outExtractByMask.save(out) 
    
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章