easyidp.geotiff.geo2pixel#
- easyidp.geotiff.geo2pixel(points_hv, header, return_index=False)#
Convert point cloud xyz coordinate to geotiff pixel coordinate (horizontal, vertical)
- 参数:
points_hv (numpy nx2 array) – [horizontal, vertical] points
header (dict) – the geotiff head dictionary from get_header()
return_index (bool, default false) – if false: will get float coordinates -> (23.5, 27.8) if true: will get int pixel index -> (23, 27)
- 返回:
pixel position of these points (horizontal, vertical)
- 返回类型:
ndarray
备注
Please note: gis UTM coordinate, horizontal is x axis, vertical is y axis, origin at left upper.
To crop image ndarray:
the first columns is vertical pixel (along height),
the second columns is horizontal pixel number (along width),
the third columns is 3 or 4 bands (RGB, alpha),
the x and y is reversed compared with gis coordinates.
This function has already do this reverse, so that you can use the output directly.
示例
# 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]])