def __init__(self): """ Initialization """ GdalAux.check_gdal_data() GdalAux.check_proj4_data() self.geo = Geod(ellps='WGS84')
def get_transformed_point(cls, long_in, lat_in, epsg_inputs=4326, epsg_calc=3857): """" Perform coordinate pair transformation Args: long_in: Input longitude lat_in: Input latitude epsg_inputs: Input EPSG CRS epsg_calc: Output EPSG CRS Returns: list: X, Y """ GdalAux.check_gdal_data() osr_inputs = osr.SpatialReference() osr_inputs.ImportFromEPSG(epsg_inputs) osr_calc = osr.SpatialReference() if epsg_calc == 3857: osr_calc.ImportFromWkt(wkt_3857) else: osr_calc.ImportFromEPSG(epsg_calc) coord_transform = osr.CoordinateTransformation(osr_inputs, osr_calc) # print(type(coord_transform)) point = ogr.Geometry(ogr.wkbPoint) point.AddPoint(long_in, lat_in) point.Transform(coord_transform) # print(point) return point.GetX(), point.GetY()
def __init__(self): # same as LibInfo variables self.app_name = name self.app_version = __version__ self.app_author = "G.Masetti (CCOM/JHC)" self.app_author_email = "*****@*****.**" self.app_license = "LGPL v3" self.app_license_url = "https://www.hydroffice.org/license/" self.app_path = os.path.abspath(os.path.dirname(__file__)) self.app_url = "https://www.hydroffice.org/abc/" self.app_manual_url = "https://www.hydroffice.org/manuals/abc/index.html" self.app_support_email = "*****@*****.**" self.app_latest_url = "https://www.hydroffice.org/latest/abc.txt" # additional AppInfo-specific variables self.app_media_path = os.path.join(self.app_path, "media") self.app_main_window_object_name = "MainWindow" self.app_license_path = os.path.join(self.app_media_path, "LICENSE") self.app_icon_path = os.path.join(self.app_media_path, "app_icon.png") self.app_tabs_icon_size = 36 self.app_toolbars_icon_size = 24 GdalAux.check_gdal_data() GdalAux.check_proj4_data()
def __init__(self, s57, grids, version="2018", scale=10000, with_laser=True, is_target_detection=False, progress_bar=None): if version not in ["2015", "2016", "2017", "2018"]: raise RuntimeError("unsupported specs version: %s" % version) super().__init__(s57=s57, grids=grids) self.type = valsou_algos["VALSOU_CHECK_v7"] self.version = version self.scale = scale self.with_laser = with_laser self.is_target_detection = is_target_detection self.all_features = self.s57.rec10s self.progress = progress_bar self.dist_2mm = None self.valsou_features = list() self.valsou_2mm_features = list() self.valsou_1node_features = list() self.valsou_geo = None self.valsou_utm = None self.valsou_closest = None self.valsou_closest_2 = None self.valsou_visited = None self.out_of_bbox = False self.deconflicted = False self.geo2loc = None # dtm self.bathy_nodata = None self.bathy_values = None self.bathy_is_double = False self.bathy_hrs = None self.bathy_transform = None self.bathy_rows = None self.bathy_cols = None GdalAux.check_gdal_data()
def _georef_fliers(self): """Helper function that looks at the flagged array and store the node != 0 as feature fliers""" # selected holes fliers_x = list() fliers_y = list() fliers_z = list() fliers_ck = list() nz_y, nz_x = self.flag_grid.nonzero() for i, x in enumerate(nz_x): y = nz_y[i] fliers_x.append(x) fliers_y.append(y) fliers_z.append(self.bathy_values[y, x]) fliers_ck.append(self.flag_grid[y, x]) GdalAux.check_gdal_data() # logger.debug("crs: %s" % self.bathy_crs) try: osr_csar = osr.SpatialReference() osr_csar.ImportFromWkt(self.bathy_hrs) osr_geo = osr.SpatialReference() osr_geo.ImportFromEPSG(4326) # geographic WGS84 loc2geo = osr.CoordinateTransformation(osr_csar, osr_geo) except Exception as e: raise IOError("unable to create a valid coords transform: %s" % e) if len(fliers_x) == 0: logger.info( "No fliers detected in current slice, total fliers: %s" % len(self.flagged_fliers)) return tile = self.grids.tiles[0] flagged_xs = list() flagged_ys = list() flagged_zs = list() flagged_cks = list() for i, x in enumerate(fliers_x): e = tile.convert_easting(int(x)) n = tile.convert_northing(int(fliers_y[i])) z = fliers_z[i] c = fliers_ck[i] logger.debug("#%d: %.0f, %.0f -> %.2f %.2f %.2f : %d" % (i, x, fliers_y[i], e, n, z, c)) flagged_xs.append(e) flagged_ys.append(n) flagged_zs.append(z) flagged_cks.append(c) logger.info("Initial lists length: %s, %s, %s, %s" % (len(self.flagged_xs), len(self.flagged_ys), len(self.flagged_zs), len(self.flagged_cks))) # convert flagged nodes to geographic coords try: xs = np.array(flagged_xs) ys = np.array(flagged_ys) cks = np.array(flagged_cks) # logger.debug("xs: %s" % xs) # logger.debug("ys: %s" % ys) # convert to geographic if gdal.__version__[0] == '3': lonlat = np.array( loc2geo.TransformPoints(np.vstack((xs, ys)).transpose()), np.float64) lonlat.T[[0, 1]] = lonlat.T[[1, 0]] # print(lonlat) else: lonlat = np.array( loc2geo.TransformPoints(np.vstack((xs, ys)).transpose()), np.float64) # add checks lonlat[:, 2] = cks # store as list of list self.flagged_fliers += lonlat.tolist() self.flagged_xs += flagged_xs self.flagged_ys += flagged_ys self.flagged_zs += flagged_zs self.flagged_cks += flagged_cks logger.info("Detected %s possible fliers" % len(self.flagged_fliers)) logger.info("Resulting lists lengths: %s, %s, %s, %s" % (len(self.flagged_xs), len(self.flagged_ys), len(self.flagged_zs), len(self.flagged_cks))) logger.debug(f"Flagged fliers: {self.flagged_fliers}") except Exception as e: raise RuntimeError( "Unable to perform conversion of the flagged fliers to geographic: %s" % e)
def test_gdal_data(self): GdalAux.check_gdal_data()