def wgs84_utm_zone(self): """ Finds the UTM zone where the first point of the GCP falls into :return utm zone string valid for a coordinates header """ if self.entries_count() > 0: entry = self.get_entry(0) longlat = CRS.from_epsg("4326") lon, lat = location.transform2(self.srs, longlat, entry.x, entry.y) utm_zone, hemisphere = location.get_utm_zone_and_hemisphere_from(lon, lat) return "WGS84 UTM %s%s" % (utm_zone, hemisphere)
def __init__(self, geo_path): self.geo_path = geo_path self.entries = {} self.srs = None with open(self.geo_path, 'r') as f: contents = f.read().strip() lines = list(map(str.strip, contents.split('\n'))) if lines: self.raw_srs = lines[0] # SRS self.srs = location.parse_srs_header(self.raw_srs) longlat = CRS.from_epsg("4326") for line in lines[1:]: if line != "" and line[0] != "#": parts = line.split() if len(parts) >= 3: i = 3 filename = parts[0] x, y = [float(p) for p in parts[1:3]] z = float(parts[3]) if len(parts) >= 4 else None # Always convert coordinates to WGS84 if z is not None: x, y, z = location.transform3( self.srs, longlat, x, y, z) else: x, y = location.transform2(self.srs, longlat, x, y) omega = phi = kappa = None if len(parts) >= 7: omega, phi, kappa = [float(p) for p in parts[4:7]] i = 7 horizontal_accuracy = vertical_accuracy = None if len(parts) >= 9: horizontal_accuracy, vertical_accuracy = [ float(p) for p in parts[7:9] ] i = 9 extras = " ".join(parts[i:]) self.entries[filename] = GeoEntry( filename, x, y, z, omega, phi, kappa, horizontal_accuracy, vertical_accuracy, extras) else: logger.warning("Malformed geo line: %s" % line)
def write_reference_lla(self, offset_x, offset_y, proj4): reference_lla = self.path("reference_lla.json") longlat = CRS.from_epsg("4326") lon, lat = location.transform2(CRS.from_proj4(proj4), longlat, offset_x, offset_y) with open(reference_lla, 'w') as f: f.write( json.dumps({ 'latitude': lat, 'longitude': lon, 'altitude': 0.0 }, indent=4)) log.ODM_INFO("Wrote reference_lla.json")