def get_zone_from_name(s: str) -> Number: split_string = s.lower().rsplit('u', 1) c = len(split_string) if c == 2: s = split_string[1] elif c != 0: return 0 zone = num_or_none(s) if zone is None: return 0 return zone
def test_utils_py_0(): for b in (False, 'False', 'OfF', 'no'): assert not base.is_true(b) for b in (True, 'TruE', 'ON', 'yes'): assert base.is_true(b) assert base.enum_to_str(Extent.UNION) == 'UNION' assert base.enum_to_str('UNION') == 'UNION' filename = Path('abc') / Path('def') / Path('a.txt') assert base.is_path_like(Path(filename)) assert base.is_path_like(str(filename)) assert not base.is_path_like(None) assert not base.is_path_like([filename]) assert base.get_suffix(filename) == '.txt' assert base.get_extension(filename) == 'txt' for idx, b in enumerate((0x23, 0xc1, 0xab, 0x00)): byte = base.get_byte(0xab_c1_23, idx) assert byte == b assert base.path_join(filename, 'a', 'b') == str(filename / 'a' / 'b') assert base.num(42) == 42 assert base.num('42') == 42 assert isinstance(base.num('42'), int) assert base.num(42.0) == 42.0 assert base.num('42.0') == 42.0 assert isinstance(base.num('42.0'), float) assert base.num('42.') == 42.0 assert isinstance(base.num('42.'), float) assert base.num(42.5) == 42.5 assert base.num('42.5') == 42.5 assert base.num_or_none('') is None assert base.num_or_none(None) is None assert base.num_or_none('1a') is None assert base.num_or_none('42') == 42 assert base.num_or_none('42.0') == 42.0
def polar_deg(polarity: MaybeSequence[Union[str, bool, Real, RadioPolarity]]): if isinstance(polarity, SequenceNotString.__args__): return [RadioParams.polar_deg(p) for p in polarity] if isinstance(polarity, (RadioPolarity, bool)): return 90 if polarity else 0 if isinstance(polarity, str): p = num_or_none(polarity) if p is not None: return p p = polarity[0].lower() return 90 if p in ['v', 't'] else 0 if not polarity: return 0 return polarity
def parse_proj_string_and_zone( talos_pj: Optional[Union[str, Real]], zone: Optional[Real] = None, ED50_towgs84='-87,-98,-121') -> Tuple[str, Real]: # '+proj=tmerc +k=0.9996 +lon_0={} +x_0=500000 +datum=WGS84 +units=m +no_defs' # '+proj=tmerc +k=0.9996 +lon_0={} +x_0=500000 +ellps=intl +towgs84=x,y,z +units=m +no_defs' # # '+proj=utm +zone={} +datum=WGS84 +units=m +no_defs' # '+proj=utm +zone={} +ellps=intl +towgs84=x,y,z +units=m +no_defs' # # '+proj=latlong +datum=WGS84 +no_defs' # '+proj=latlong +ellps=intl +towgs84=x,y,z +no_defs' pj_string = None if zone is None: number = num_or_none(talos_pj) if number is not None: if isinstance(number, int) and number > 100: pj_string = '+init=epsg:{}'.format(number) else: zone = number else: zone = get_zone_from_name(talos_pj) if pj_string is None and isinstance(talos_pj, str): if talos_pj.startswith('+'): pj_string = talos_pj elif talos_pj.lower().startswith('epsg'): pj_string = '+init=' + talos_pj if pj_string is None: if isinstance(talos_pj, str) and talos_pj[0].lower() == 'e': datum_str = '+ellps=intl +towgs84=' + ED50_towgs84 else: datum_str = '+datum=WGS84' pj_string = proj_string_from_utm_zone(zone=zone, datum_str=datum_str) return pj_string, zone