[英]Can Python export latitude/longitude from Satellite images?
I have a satellite image and it has latitude/longitude for each pixel.我有一张卫星图像,每个像素都有纬度/经度。 Can I export the coordinate value of each pixel to.CSV file or.txt file by using Python?
我可以使用Python将每个像素的坐标值导出到.CSV文件或.txt文件吗? If it can,how to do that?
如果可以,该怎么做?
Yes you can export latitude/longitude from satellite images.是的,您可以从卫星图像中导出纬度/经度。 For.tif images Below is the source code.
For.tif images 下面是源代码。
import numpy as np import pandas as pd import rasterio as rio导入 numpy 作为 np 导入 pandas 作为 pd 导入 rasterio 作为 rio
tifImage = "imagename.tif" tifImage = "图像名.tif"
def extractLatLon(imageName, NumOfBands): def extractLatLon(imageName, NumOfBands):
with rio.open(imageName) as src:
image = src.read(NumOfBands)
height, width = image.shape[0], image.shape[1]
rows, cols = np.meshgrid(np.arange(width), np.arange(height))
xs, ys = rio.transform.xy(src.transform, rows, cols)
lat, lon = np.array(xs), np.array(ys)
return lat, lon
# Flatten lat, lon if you want to [according to your needs]
def DataFrame(lat, lon): return pd.DataFrame({'lat': lat, 'lon': lon}).to_csv('File_name_to_be_saved.csv') def DataFrame(lat, lon): return pd.DataFrame({'lat': lat, 'lon': lon}).to_csv('File_name_to_be_saved.csv')
lat, lon = extractLatLon("ImageName.tif", NumOfBands=3) DataFrame(lat, lon) lat, lon = extractLatLon("ImageName.tif", NumOfBands=3) DataFrame(lat, lon)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.