Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert pixel coordinates to lat, lng #51

Closed
Spiruel opened this issue Nov 1, 2018 · 4 comments
Closed

Convert pixel coordinates to lat, lng #51

Spiruel opened this issue Nov 1, 2018 · 4 comments

Comments

@Spiruel
Copy link

Spiruel commented Nov 1, 2018

Without downloading Sentinel images and reading them with the use of another library, eg Rasterio - I am struggling to find an effective way using sentinelhub-py of converting pixel coordinates to latitude and longitude. Can anyone help?

@AleksMat
Copy link
Contributor

AleksMat commented Nov 2, 2018

Hi @Spiruel,

With tools from sentinelhub-py you can transform from pixel coordinates (row, column in your image) to WGS84 via one of the UTM coordinate reference systems.

First you need to know which UTM CRS you are working with and a transform vector of your image in that UTM. Then you have to use sentinelhub.pixel_to_utm function and then sentinelhub.to_wgs84 function. Their parameters are specified in documentation.

In order to be able to help you further I would probably have to know the following:
Which type of satellite data are you working with? If you are working with Sentinel-2, are you using original tiles provided by ESA or images downloaded from Sentinel Hub? Do you require a precise transformation for any pixel?

@Spiruel
Copy link
Author

Spiruel commented Nov 2, 2018

Hi @AleksMat,

Thanks for your reply. I came across sentinelhub.geo_utils.pixel_to_utm but didn't know how to obtain the transform easily through sentinelhub-py. If you could let me how how to get the UTM CRS and transform vector that would be really helpful. Currently I've been obtaining the crs and transform by writing the images to disk and re-reading them into rasterio.

I'm currently using Sentinel 2 data retrieved via OGC or AWS. I don't think I need a very precise transformation for any pixel (ie. pixel centres?) - just a mapping from (row,col) -> (lat,lng) would be great.

@AleksMat
Copy link
Contributor

AleksMat commented Nov 5, 2018

At the moment sentinelhub-py does not support reading geo info from downloaded images. For that we would probably have to add rasterio, gdal or some similar package as a dependency. However in this case you can get required information . All you need is CRS, coordinates of upper left corner of your image and resolution of your image.

  • If you are using OGC (WMS, WCS) requests I suggest downloading data in UTM CRS (it will also improve accuracy of your final result). You can use sentinelhub.geo_utils.to_utm_bbox to transform your BBox object into a correct UTM. To download images with known resolution I also suggest using WcsRequest instead of WmsRequest.

  • If you are downloading data from AWS (i.e. using AwsProductRequest or AwsTileRequest) you can use parameter metafiles. The parameter takes a list of additional metadata files to download. In your case you require tileInfo.json. Check this example to see its content and its HTTP address. From tileOrigin you can read the required data. Here is a code example how to obtain it:

from sentinelhub import AwsTileRequest

request = AwsTileRequest(tile='T01CCV', time='2017-01-14', bands=[], metafiles=['tileInfo.json'])
tile_info = request.get_data()[0]

@Spiruel
Copy link
Author

Spiruel commented Nov 5, 2018

Many thanks for clearing that up!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants