favyen commited on
Commit
8ffecfc
1 Parent(s): d283f0d

Add example of mapping longitude/latitude to tile

Browse files
Files changed (1) hide show
  1. README.md +36 -0
README.md CHANGED
@@ -52,6 +52,42 @@ The Sentinel-2, Sentinel-1, and Landsat images are GeoTIFFS so they contain geor
52
  Other data does not have georeference metadata, but data at each tile is aligned, so the georeference metadata from the above images is applicable to the other data as well with only a resolution shift.
53
 
54
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
55
  Sentinel-2
56
  ----------
57
 
 
52
  Other data does not have georeference metadata, but data at each tile is aligned, so the georeference metadata from the above images is applicable to the other data as well with only a resolution shift.
53
 
54
 
55
+ Mapping Longitude and Latitude to Tile
56
+ --------------------------------------
57
+
58
+ Here is an example of mapping longitude and latitude to a tile.
59
+
60
+ First install packages:
61
+
62
+ pip install rasterio shapely utm
63
+
64
+ Then launch Python shell:
65
+
66
+ from rasterio.crs import CRS
67
+ from rasterio.warp import transform_geom
68
+ import shapely
69
+ import utm
70
+ # Define source location.
71
+ src_crs = CRS.from_epsg(4326)
72
+ src_point = shapely.Point(-122.331711, 47.648450)
73
+ # Get UTM zone.
74
+ _, _, zone_suffix, _ = utm.from_latlon(src_point.y, src_point.x)
75
+ epsg_code = 32600 + zone_suffix
76
+ dst_crs = CRS.from_epsg(epsg_code)
77
+ # Transform to UTM CRS.
78
+ dst_point = transform_geom(src_crs, dst_crs, src_point)
79
+ dst_point = shapely.geometry.shape(dst_point)
80
+ # dst_point is in projection coordinates (meters).
81
+ # Now convert to pixel coordinates at 1.25 m/pixel.
82
+ col = int(dst_point.x/1.25)
83
+ row = int(dst_point.y/-1.25)
84
+ # Print the prefix for the image filenames.
85
+ print(f"{epsg_code}_{col//512}_{row//512}")
86
+ # Print the prefix for the tar filenames to know which one to download.
87
+ # These group together many 1.25 m/pixel 512x512 tiles into one tar file.
88
+ print(f"{epsg_code}_{col//512//32}_{row//512//32}")
89
+
90
+
91
  Sentinel-2
92
  ----------
93