geowatch.gis.sensors package¶
Submodules¶
Module contents¶
A submodule where each file contains information and functionality specific to a particular GEO sensor.
- geowatch.gis.sensors.sentinel2_grid()[source]¶
Grabs sentinel2 grid information from the web (if needed)
- Returns:
A data frame where each row contains the tile name and the reversed-WGS84 (GeoJSON style) coordinates in shapely.geometry.Polygon format.
- Return type:
geopandas.GeoDataFrame
References
https://gisgeography.com/arcgis-shapefile-files-types-extensions/ https://github.com/justinelliotmeyers/Sentinel-2-Shapefile-Index
CommandLine
xdoctest -m /home/joncrall/code/watch/kwgis/gis/sensors/sentinel2.py
Example
>>> # xdoctest: +SKIP("slow, not currently used") >>> from kwgis.gis.sensors.sentinel2 import * # NOQA >>> s2_tiles = sentinel2_grid() >>> assert s2_tiles.crs.name == 'WGS 84' >>> # Print out the first 5 tile rows >>> # print(s2_tiles.iloc[0:5]) # xdoctest: +IGNORE_WANT >>> ''' >>> Name geometry >>> 0 01CCV POLYGON Z ((180.00000 -73.05974 0.00000, 176.8... >>> 1 01CCV POLYGON Z ((-180.00000 -72.07333 0.00000, -179... >>> 2 01CDH POLYGON Z ((180.00000 -83.80855 0.00000, 174.7... >>> 3 01CDH POLYGON Z ((-180.00000 -82.82590 0.00000, -176... >>> 4 01CDJ POLYGON Z ((180.00000 -82.91344 0.00000, 175.7... >>> ''' >>> # >>> # Demo how to convert each polygon into its UTM zone >>> import kwimage >>> from kwgis.utils import util_gis >>> import pyproj >>> utm_codes = [] >>> # Only take some of the tiles for test speed >>> s2_tiles = s2_tiles.iloc[0:100] >>> for poly in ub.ProgIter(s2_tiles.geometry, desc='find utm'): >>> lon = poly.centroid.x >>> lat = poly.centroid.y >>> utm_epsg = util_gis.utm_epsg_from_latlon(lat, lon) >>> utm_codes.append(utm_epsg) >>> s2_tiles['utm_epsg'] = utm_codes >>> # Group all tiles within the same zone together >>> groups = dict(list(s2_tiles.groupby('utm_epsg'))) >>> utm_groups = {} >>> for utm_epsg in ub.ProgIter(groups, desc='proj to utm'): >>> utm_crs = pyproj.CRS.from_epsg(utm_epsg) >>> # convert group into its utm coordinates >>> utm_group = groups[utm_epsg].to_crs(utm_crs) >>> utm_groups[utm_epsg] = utm_group >>> # Measure the area of each UTM Polygon >>> all_utm_areas = [] >>> for utm_epsg, utm_group in utm_groups.items(): >>> all_utm_areas.extend([s.area for s in utm_group.geometry]) >>> # Print out statistics about the chosen S2-tile UTM areas >>> import kwarray >>> area_stats = kwarray.stats_dict(all_utm_areas) >>> print('area_stats = {}'.format(ub.urepr( >>> area_stats, nl=1, precision=0, align=':')))
… area_stats = {
‘mean’ : 8463072768, ‘std’ : 3774869504, ‘min’ : 65260336, ‘max’ : 12056040448, … ‘shape’: (100,),
}