简体   繁体   English

如何从python中的2个numpy数组中提取经度/纬度坐标?

[英]How to extract lat / long coordinates from 2 numpy arrays in python?

I basically have 2 arrays, one containing Lattitude values, one Longitude. 我基本上有2个数组,一个包含纬度值,一个经度。 What I want is to extract those that meet a certain requirement . 我要提取的是那些符合一定条件的东西。

xLong = np.extract(abs(Long-requirement)<0.005,Long)
xLat = np.extract(abs(Lat-requirement)<0.005,Lat)

Lat and Long are numpy arrays. Lat和Long是numpy数组。

However, I only want to get those coordinates that both lat/long meet the requirement and I'm not sure how to do it . 但是,我只想获取经纬度都满足要求的那些坐标,而且我不确定如何做到。

If it's possible, I need to use numpy functions since I'm looking for optimization as well. 如果可能的话,因为我也在寻找优化,所以我需要使用numpy函数。 I know that I can iterate through all using a for and just add to different array but that would take a lot of time 我知道我可以使用for进行遍历并添加到其他数组中,但这会花费很多时间

You need to do this with boolean indexing. 您需要使用布尔索引进行此操作 Whenever you create an boolean array the same shape as your array of interest, you can get just the True values out by indexing with the boolean array. 只要创建与目标数组形状相同的布尔数组,就可以通过使用布尔数组建立索引来获取True值。 I assume below that Long and Lat are the same size; 在下面,我假设LongLat大小相同; if they're not the code will throw an exception. 如果不是,则代码将引发异常。

# start building the boolean array.  long_ok and lat_ok will be the same
# shape as xLong and xLat.
long_ok = np.abs(Long - requirement) < 0.005
lat_ok = np.abs(Lat - requirement) < 0.005

# both_ok is still a boolean array which is True only where 
# long and lat are both in the region of interest
both_ok = long_ok & lat_ok

# now actually index into the original arrays.
long_final = Long[both_ok]
lat_final = Lat[both_ok]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从使用numpy arange生成的坐标列表生成坐标列表(lat,long) - How do I generate a list of coordinates (lat, long) from list of coordinates generated using numpy arange Python,Numpy,Scipy:如何从GPS坐标中排除位置错误? (平均lon,lat) - Python, numpy, scipy: How to exclude a location error from GPS coordinates? (averaging lon, lat) 如何从 GPS 初始点生成 GPS 坐标(纬度和经度) - How to generate GPS coordinates (Lat and Long) from GPS initial point numpy:从二维数组中提取数据和坐标 - Numpy: extract data and coordinates from 2-D arrays 如何从 python 轻松提取 numpy arrays(矩阵)到 ZBF57C906FA7D2BB66D9D9672E4158? - How to easily extract numpy arrays (Matrices) from python to excel? Python 使用 xarray 从 NETCDF 文件中提取多个纬度/经度 - Python extract multiple lat/long from NETCDF files using xarray 使用 Python,是否可以遍历栅格并为每个像素提取纬度/经度坐标? - Using Python, is it possible loop through a raster and extract Lat/Long coordinates for each pixel? Python中两个(纬度,经度)坐标之间的位置 - Position between two (lat,long)-coordinates in Python 在 R/Python/GIS 中,如何在地图中叠加多个纬度/经度坐标并创建一个变量来指示所叠加的坐标是否匹配 - In R/Python/GIS, how to overlay multiple lat/long coordinates in a map and create a variable indicating if coordinates overlayed match or not 将经纬度坐标的CSV文件输入API中提取天气数据? - Input CSV file of lat and long coordinates into API to extract the weather data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM