easyidp.geotiff.geo2pixel

easyidp.geotiff.geo2pixel(points_hv, header, return_index=False)

[Deprecated] Convert geo coordinate (lon, lat) to geotiff pixel coordinate (horizontal, vertical)

..caution:

Since v2.0.2, this function is deprecated, the conversion method is old and may not accurate.
Please use `:func:`easyidp.geotiff.GeoTiff.geo2pixel <easyidp.geotiff.GeoTiff.geo2pixel>` instead,
a warpper for `rasterio.io.DatasetReader.index()` function
参数:
  • points_hv (numpy nx2 array) -- [horizontal, vertical] points

  • header (dict) -- the geotiff head dictionary from get_header()

  • return_index (bool, default false) -- 如果为 false:将获得浮点坐标 -> (23.5, 27.8) 如果为 true:将获得整数像素索引 -> (23, 27)

返回:

这些点的像素位置(水平,垂直)

返回类型:

ndarray

备注

请注意:GIS UTM 坐标,水平是 x 轴,垂直是 y 轴,原点在左上角。

To crop image ndarray:

  • 第一列是垂直像素(沿高度),

  • 第二列是水平像素数(沿宽度),

  • 第三列是 3 或 4 个波段(RGB,alpha),

  • x 和 y 与 GIS 坐标相比是反向的。

此功能已完成此反向操作,因此您可以直接使用输出。

示例

# manual specify header just as example (no need to open geotiff)
>>> header = {'width': 19436, 'height': 31255, 'dim':4,
              'scale': [0.001, 0.001], 'nodata': None,
              'tie_point': [484576.70205, 3862285.5109300003],
              'proj': pyproj.CRS.from_string("WGS 84 / UTM zone 53N")}
# prepare coord data (no need to read)
>>> gis_coord = np.asarray([
        [ 484593.67474654, 3862259.42413431],
        [ 484593.41064743, 3862259.92582402],
        [ 484593.64841806, 3862260.06515117],
        [ 484593.93077419, 3862259.55455913],
        [ 484593.67474654, 3862259.42413431]])
# get the results
>>> idp.geotiff.geo2pixel(gis_coord, header, return_index=True)
array([[16972, 26086],
       [16708, 25585],
       [16946, 25445],
       [17228, 25956],
       [16972, 26086]])