Get a tile's geocoding data

I’m trying to implement an accuracy assessment section for my plugin. Right now when testing this in Python and loading the whole scene, there is no problem. I’ll just get the validation data from a shapefile using a variation of this code snippet here to convert lat-long to x,y indices of my supplied raster.

pos = GeoPos(lat, lon)
self.source_product.getSceneGeoCoding().getPixelPos(pos, None)

The problem arises when I try to do this in SNAP because the tiling would screw up the returned x,y indices. I should change source_product to the current tile in focus, but then getSceneGeoCoding() would not work for that object-type. Looking at the API docs for tile methods, I could attempt a crude way of readjusting the indices relative to the tile using getRectangle(). Is there a better way to do this?

Lastly, is it normal that a custom processor that otherwise works when invoked from the Menu bar can’t be selected in GraphBuilder? Is there a workaround for that?


First the easy answer :

Yes, currently this is normal. Some operators are not compatible with the GraphBuilder, because some of there GUI elements don’t work with the GraphBuilder. But we have it on the agenda to make them compatible.

I’m not sure what your problem is with the GeoCoding and the tiling.
I assume that you have only one product. How the data is tiled should not affect the GeoCoding and the positions. Maybe you can explain in more detail what the problem is.

I see, thanks for the answer.

Yes, only one source. I was under the impression that the result given by getPixelPos() would be oriented relative to the full raster. For example, if a given raster is 1000x1000, and a given lat-long corresponds to:

self.source_product.getSceneGeoCoding().getPixelPos(pos, None).getX() = 995
self.source_product.getSceneGeoCoding().getPixelPos(pos, None).getY() = 995

So at an index of (995, 995) in the original product’s raster. But if we use this index in a 100x100 tile (so we need 100 of these 100x100 tiles to complete the whole scene), the index (995, 995) becomes meaningless because 1) that would yield out of bounds for the size of the tile and 2) the point is only contained at the 100th tile, at index (95, 95).

source_product[995, 995] = tile_100[95, 95]

So I was wondering if there is some kind of

current_tile.getPixelPos(lat, long).getX() = x_index_in_tile
current_tile.getPixelPos(lat, long).getY() = y_index_in_tile

Ah, okay. If you want the tile index for a pixel you can use the following example code:

    index_tile_x = product.getBandAt(0).getSourceImage().XToTileX()
    index_tile_y = product.getBandAt(0).getSourceImage().YToTileY()

And here you can find the ApiDoc:

But probably it will not yield the results you want.
From your postings I guess you are doing your own tiling and don’t use the tiling of the image. If so, you need to compute your own tile indices.
The implementation can be found here, if you need some advice.

1 Like

Thanks! I’m not doing my own tiling, I just gave a rough example in my previous post so hopefully this works.