def test_hex_area(self): for i in range(0, 15): self.assertTrue(isinstance(h3.hex_area(i), float)) self.assertTrue(isinstance(h3.hex_area(i, 'm^2'), float)) with pytest.raises(ValueError) as e_info: h3.hex_area(5, 'ft^2') self.assertTrue(isinstance(e_info.value, ValueError))
list_hex_edge_km = [] list_hex_edge_m = [] list_hex_perimeter_km = [] list_hex_perimeter_m = [] list_hex_area_sqkm = [] list_hex_area_sqm = [] for i in range(0, max_res + 1): ekm = h3.edge_length(resolution=i, unit='km') em = h3.edge_length(resolution=i, unit='m') list_hex_edge_km.append(round(ekm, 3)) list_hex_edge_m.append(round(em, 3)) list_hex_perimeter_km.append(round(6 * ekm, 3)) list_hex_perimeter_m.append(round(6 * em, 3)) akm = h3.hex_area(resolution=i, unit='km^2') am = h3.hex_area(resolution=i, unit='m^2') list_hex_area_sqkm.append(round(akm, 3)) list_hex_area_sqm.append(round(am, 3)) df_meta = pd.DataFrame({ "edge_length_km": list_hex_edge_km, "perimeter_km": list_hex_perimeter_km, "area_sqkm": list_hex_area_sqkm, "edge_length_m": list_hex_edge_m, "perimeter_m": list_hex_perimeter_m, "area_sqm": list_hex_area_sqm }) df_meta[[ "edge_length_km", "perimeter_km", "area_sqkm", "edge_length_m",
import numpy import sqlalchemy from sqlalchemy.sql import func import rasterio import shapefile from h3 import h3 import shapely.geometry as sgeom from shapely.prepared import prep from database import db from raster_data import ecoregion_tile_from_geocoordinates RESOLUTION: int = 5 AREA: float = h3.hex_area(RESOLUTION, "km^2") # The resolution of our hexes should be about 450 km² following Gavin (2017) assert h3.hex_area(RESOLUTION - 1, "km^2") > 450 > AREA ARCMIN: float = 111.319 / 60. # km, at the equator. SQUARE_OF_15_ARCSEC: float = (ARCMIN / 4.)**2 # km², at the equator class Ecoregions: cache = None @classmethod def ecoregions(cls): """ >>> eco = Ecoregions.ecoregions()