简体   繁体   English

如何将x,y坐标投影到netcdf文件中的纬度/经度

[英]How to project x,y coordinates to lat/lon in netcdf file

I have downloaded the velocity field of the Greenland ice sheet from the CCI website as a NetCDF file. 我已经从CCI网站下载了格陵兰冰盖的速度场作为NetCDF文件。 However, the projection is given as (see below, where x ranges between [-639750,855750] and y [-655750,-3355750]) 但是,投影的给定方式为(请参见下文,其中x介于[-639750,855750]和y [-655750,-3355750]之间)

How can I project these data to actual lat/lon coordinates in the NetCDF file? 如何将这些数据投影到NetCDF文件中的实际纬度/经度坐标? Thanks already! 已经谢谢你了! For the ones interested: the file can be downloaded here: http://products.esa-icesheets-cci.org/products/downloadlist/IV/ 对于感兴趣的人:可在此处下载文件: http : //products.esa-icesheets-cci.org/products/downloadlist/IV/

Variables:
    crs                                
           Size:       1x1
           Dimensions: 
           Datatype:   int32
           Attributes:
                       grid_mapping_name                     = 'polar_stereographic'
                       standard_parallel                     = 70
                       straight_vertical_longitude_from_pole = -45
                       false_easting                         = 0
                       false_northing                        = 0
                       unit                                  = 'meter'
                       latitude_of_projection_origin         = 90
                       spatial_ref                           = 'PROJCS["WGS 84 / NSIDC Sea Ice Polar Stereographic North",GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]],PROJECTION["Polar_Stereographic"],PARAMETER["latitude_of_origin",70],PARAMETER["central_meridian",-45],PARAMETER["scale_factor",1],PARAMETER["false_easting",0],PARAMETER["false_northing",0],UNIT["metre",1,AUTHORITY["EPSG","9001"]],AXIS["X",EAST],AXIS["Y",NORTH],AUTHORITY["EPSG","3413"]]'
    y                                  
           Size:       5401x1
           Dimensions: y
           Datatype:   double
           Attributes:
                       units         = 'm'
                       axis          = 'Y'
                       long_name     = 'y coordinate of projection'
                       standard_name = 'projection_y_coordinate'
    x                                  
           Size:       2992x1
           Dimensions: x
           Datatype:   double
           Attributes:
                       units         = 'm'
                       axis          = 'X'
                       long_name     = 'x coordinate of projection'
                       standard_name = 'projection_x_coordinate'

If you want to transform the whole grid from its native Polar Stereographic coordinates to a geographic (longitude by latitude) grid, you'll probably want to use a tool like gdalwarp . 如果要将整个网格从其原始的Polar Stereographic坐标转换为地理(经度和纬度)网格,则可能需要使用gdalwarp之类的工具。 I don't think that's the question you're asking, though. 不过,我认为这不是您要问的问题。

If I'm reading your question correctly, you want to pick points out of the file and locate them as lon/lat coordinate pairs. 如果我正确地阅读了您的问题,则希望从文件中挑选点并将其定位为lon / lat坐标对。 I'm assuming that you know how to get a location as an XY pair out of your netCDF file, along with the velocity values at that location. 我假设您知道如何从netCDF文件中获取一个XY对位置,以及该位置的速度值。 I'm also assuming that you're doing this in Python, since you put that tag on this question. 我还假设您正在Python中执行此操作,因为您已将标记放在此问题上。

Once you've got an XY pair, you just need a function (with a bunch of parameters) to transform it to lon/lat. 一旦有了XY对,您只需要一个函数(带有一堆参数)即可将其转换为lon / lat。 You can find that function in the pyproj module. 您可以在pyproj模块中找到该函数。

Pyproj wraps the proj4 C library, which is very widely used for coordinate system transformations. Pyproj包装了proj4 C库,该库非常广泛地用于坐标系转换。 If you have an XY pair in projected coordinates and you know the definition of the projected coordinate system, you can use pyproj's transform function like this: 如果投影坐标中有XY对,并且知道投影坐标系的定义,则可以使用pyproj的transform函数,如下所示:

import pyproj

# Output coordinates are in WGS 84 longitude and latitude
projOut = pyproj.Proj(init='epsg:4326')

# Input coordinates are in meters on the Polar Stereographic 
# projection given in the netCDF file
projIn = pyproj.Proj('+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 
    +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs ',
    preserve_units=True)

# here is a coordinate pair near the middle of your data set
x, y = 0.0, -2000000

# transform x,y to lon/lat
lon, lat = pyproj.transform(projIn, projOut, x, y)

# answer: lon = -45.0; lat = 71.6886

... and there you go. ...然后你去。 Note that the output longitude is -45.0, which should give you a nice warm feeling, since the input X coordinate was 0, and -45.0 is the central meridian of the data set's projection. 请注意,输出经度为-45.0,这应该给您带来温暖的感觉,因为输入的X坐标为0,而-45.0是数据集投影的中央子午线。 If you want your answer in radians instead of degrees, set the radians kwarg in the transform function to True . 如果要以弧度而不是度来回答,请将转换函数中的radians kwarg设置为True

Now for the hard part, which is actually the thing you do first -- defining the projIn and projOut that are used as arguments for the transform function. 现在,最困难的部分实际上是您首先要做的事情-定义用作转换函数参数的projInprojOut These are in the input and output coordinate systems for the transformation. 这些在变换的输入和输出坐标系中。 These are Proj objects, and they hold a mess of parameters for the coordinate system transformation equations. 这些是Proj对象,它们包含用于坐标系转换方程的一堆参数。 The proj4 developers have encapsulated them all in a tidy set of functions and the pyproj developers have put a nice python wrapper around them, so you and I don't have to keep track of all the details. proj4开发人员将它们全部封装在一组整齐的函数中,而pyproj开发人员在它们周围放置了一个不错的python包装器,因此您和我不必跟踪所有细节。 I will be grateful to them for all the days that remain to me. 我将感激他们一生中所有的日子。

The output coordinate system is trivial 输出坐标系微不足道

projOut = pyproj.Proj(init='epsg:4326')

The pyproj library can build a Proj object from an EPSG code. pyproj库可以从EPSG代码构建Proj对象。 4326 is the EPSG code for WGS 84 lon/lat. 4326是WGS 84 lon / lat的EPSG代码。 Done. 完成。

Setting projIn is harder, because your netCDF file defines its coordinate system with a WKT string, which (I'm pretty sure) can't be read directly by proj4 or pyproj. 设置projIn更加困难,因为您的netCDF文件使用WKT字符串定义了它的坐标系,(我很确定)proj4或pyproj无法直接读取它。 However, pyproj.Proj() will take a proj4 parameter string as an argument. 但是,pyproj.Proj() 采用proj4参数字符串作为参数。 I've already given you the one you need for this operation, so you can just take my for for it that this 我已经为您提供了进行此操作所需的工具,因此您可以为此而接受我的帮助

+proj=stere +lat_0=90 +lat_ts=70 +lon_0=-45 +k=1 +x_0=0 +y_0=0 +datum=WGS84 +units=m +no_defs

is the equivalent of this (which is copied directly from your netCDF file): 等效于此(直接从您的netCDF文件复制):

PROJCS["WGS 84 / NSIDC Sea Ice Polar Stereographic North",
  GEOGCS["WGS 84",
    DATUM["WGS_1984",
      SPHEROID["WGS 84",6378137,298.257223563,
        AUTHORITY["EPSG","7030"]],
      AUTHORITY["EPSG","6326"]],
    PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],
    UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],
    AUTHORITY["EPSG","4326"]],
  PROJECTION["Polar_Stereographic"],
  PARAMETER["latitude_of_origin",70],
  PARAMETER["central_meridian",-45],
  PARAMETER["scale_factor",1],
  PARAMETER["false_easting",0],
  PARAMETER["false_northing",0],
  UNIT["metre",1,AUTHORITY["EPSG","9001"]],
AXIS["X",EAST],
AXIS["Y",NORTH],
AUTHORITY["EPSG","3413"]]'

If you want to be able to do this more generally, you'll need another module to convert WKT coordinate system definitions to proj4 parameter strings. 如果您希望能够更一般地执行此操作,则需要另一个模块将WKT坐标系定义转换为proj4参数字符串。 One such module is osgeo.osr and there's an example program at this blog post that shows you how to do that conversion. 一个这样的模块osgeo.osr并有在这样的一个例子程序的博客文章将告诉您如何做到这一点的转换。

如何在坐标(纬度,经度)中计算截然相反的坐标,其中-90 <lat<90 and -180<lon<180< div><div id="text_translate"><p> 给定坐标点 X=(lat, lon) 和圆心 C=(lat_center, lon_center) 我想计算点 X 截然相反的坐标(假设 X 在圆心为 C 的圆内) .</p><p> 例如,如果 C=(45.9, 180),则与 X=(45.9, -179) 截然相反的值应该是 (45.9, 179)。</p><p> 以下 function 是一个近似值,但不能解决纬度在 (-90, 90) 和经度 (-180, 180) 之间的问题。</p><pre> def f(lat, lon, center): lat_center = center[0] lon_center = center[1] dist_lon = np.abs(lon - lon_center) if np.abs(lon - lon_center)&lt;180 else 360 - np.abs(lon - lon_center) dist_lat = np.abs(lat - lat_center) if np.abs(lat - lat_center)&lt;180 else 360 - np.abs(lat - lat_center) lon_op = lon_center + dist_lon if lon_center + dist_lon.= lon else lon_center - dist_lon lat_op = lat_center + dist_lat if lat_center + dist_lat,= lat else lat_center - dist_lat return np,round(lat_op. 2), np.round(lon_op, 2)</pre> </div></lat<90> - How to calculate diametrically opposite in coordinates(lat, lon) where -90<lat<90 and -180<lon<180

暂无
暂无

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

相关问题 如何将netcdf iris cube中的投影x和y坐标转换为lat lon - how to convert projection x and y coordinate in netcdf iris cube to lat lon 如何从x,y笛卡尔坐标tmerc投影获得纬度/经度? - How to get Lat/Lon from x,y Cartesian Coordinates tmerc projection? 使用Python的NetCDF文件的圆形lat / lon裁剪 - Circular lat/lon crop of a NetCDF file with Python 如何识别xarray中的时间,长度和纬度坐标? - How to identify time, lon, and lat coordinates in xarray? 如何在python中为数据集分配纬度/经度坐标? - How to assign lat/lon coordinates to a dataset in python? 使用 Python 从多个 netcdf 文件创建一个 4D(模型、时间、经度、纬度)netcdf 文件 - Create one 4D (model, time, lon, lat) netcdf file from multiple netcdf files using Python 使用纬度/经度坐标将凸包面积增加 x 百分比 - Increase area of convex hull by x percentage with lat / lon coordinates 如何使用cartopy将显示坐标转换为geographoc坐标(纬度,经度)? - How to convert display coordinates to geographoc coordinates (lat, lon) using cartopy? 将经纬度转换为x / y时,底图会创建较大的值 - Basemap creates large values when transforming lat/lon to x/y 如何在坐标(纬度,经度)中计算截然相反的坐标,其中-90 <lat<90 and -180<lon<180< div><div id="text_translate"><p> 给定坐标点 X=(lat, lon) 和圆心 C=(lat_center, lon_center) 我想计算点 X 截然相反的坐标(假设 X 在圆心为 C 的圆内) .</p><p> 例如,如果 C=(45.9, 180),则与 X=(45.9, -179) 截然相反的值应该是 (45.9, 179)。</p><p> 以下 function 是一个近似值,但不能解决纬度在 (-90, 90) 和经度 (-180, 180) 之间的问题。</p><pre> def f(lat, lon, center): lat_center = center[0] lon_center = center[1] dist_lon = np.abs(lon - lon_center) if np.abs(lon - lon_center)&lt;180 else 360 - np.abs(lon - lon_center) dist_lat = np.abs(lat - lat_center) if np.abs(lat - lat_center)&lt;180 else 360 - np.abs(lat - lat_center) lon_op = lon_center + dist_lon if lon_center + dist_lon.= lon else lon_center - dist_lon lat_op = lat_center + dist_lat if lat_center + dist_lat,= lat else lat_center - dist_lat return np,round(lat_op. 2), np.round(lon_op, 2)</pre> </div></lat<90> - How to calculate diametrically opposite in coordinates(lat, lon) where -90<lat<90 and -180<lon<180
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM