def ReprojectENFromMap(self, e, n, useDefinedProjection, precision, format): """Reproject east, north to user defined projection. :param e,n: coordinate @throws SbException if useDefinedProjection is True and projection is not defined in UserSettings """ if useDefinedProjection: settings = UserSettings.Get( group="projection", key="statusbar", subkey="proj4" ) if not settings: raise SbException(_("Projection not defined (check the settings)")) else: # reproject values proj, coord = utils.ReprojectCoordinates( coord=(e, n), projOut=settings, flags="d" ) if coord: e, n = coord if proj in ("ll", "latlong", "longlat") and format == "DMS": return utils.Deg2DMS(e, n, precision=precision) else: return "%.*f; %.*f" % (precision, e, precision, n) else: raise SbException(_("Error in projection (check the settings)")) else: if self.mapFrame.GetMap().projinfo["proj"] == "ll" and format == "DMS": return utils.Deg2DMS(e, n, precision=precision) else: return "%.*f; %.*f" % (precision, e, precision, n)
def GetCenterString(self, map): """Get current map center in appropriate format""" region = map.GetCurrentRegion() precision = int( UserSettings.Get(group="projection", key="format", subkey="precision")) format = UserSettings.Get(group="projection", key="format", subkey="ll") projection = UserSettings.Get(group="projection", key="statusbar", subkey="proj4") if self.mapFrame.GetProperty("projection"): if not projection: raise SbException( _("Projection not defined (check the settings)")) else: proj, coord = utils.ReprojectCoordinates( coord=(region["center_easting"], region["center_northing"]), projOut=projection, flags="d", ) if coord: if proj in ("ll", "latlong", "longlat") and format == "DMS": return "%s" % utils.Deg2DMS( coord[0], coord[1], precision=precision) else: return "%.*f; %.*f" % (precision, coord[0], precision, coord[1]) else: raise SbException( _("Error in projection (check the settings)")) else: if self.mapFrame.GetMap( ).projinfo["proj"] == "ll" and format == "DMS": return "%s" % utils.Deg2DMS( region["center_easting"], region["center_northing"], precision=precision, ) else: return "%.*f; %.*f" % ( precision, region["center_easting"], precision, region["center_northing"], )
def OnGoTo(self, event): """Go to position """ try: e, n = self.GetValue().split(';') e, n = self.ReprojectENToMap( e, n, self.mapFrame.GetProperty('projection')) self.mapFrame.GetWindow().GoTo(e, n) self.widget.SetFocus() except ValueError: # FIXME: move this code to MapWindow/BufferedWindow/MapFrame region = self.mapFrame.GetMap().GetCurrentRegion() precision = int( UserSettings.Get(group='projection', key='format', subkey='precision')) format = UserSettings.Get(group='projection', key='format', subkey='ll') if self.mapFrame.GetMap( ).projinfo['proj'] == 'll' and format == 'DMS': self.SetValue("%s" % utils.Deg2DMS(region['center_easting'], region['center_northing'], precision=precision)) else: self.SetValue("%.*f; %.*f" % \ (precision, region['center_easting'], precision, region['center_northing'])) except SbException as e: # FIXME: this may be useless since statusbar update checks user defined projection and this exception raises when user def proj does not exists self.statusbar.SetStatusText(str(e), 0)
def GetCenterString(self, map): """Get current map center in appropriate format""" region = map.GetCurrentRegion() precision = int( UserSettings.Get(group='projection', key='format', subkey='precision')) format = UserSettings.Get(group='projection', key='format', subkey='ll') projection = UserSettings.Get(group='projection', key='statusbar', subkey='proj4') if self.mapFrame.GetProperty('projection'): if not projection: raise SbException( _("Projection not defined (check the settings)")) else: proj, coord = utils.ReprojectCoordinates( coord=(region['center_easting'], region['center_northing']), projOut=projection, flags='d') if coord: if proj in ('ll', 'latlong', 'longlat') and format == 'DMS': return "%s" % utils.Deg2DMS( coord[0], coord[1], precision=precision) else: return "%.*f; %.*f" % (precision, coord[0], precision, coord[1]) else: raise SbException( _("Error in projection (check the settings)")) else: if self.mapFrame.GetMap( ).projinfo['proj'] == 'll' and format == 'DMS': return "%s" % utils.Deg2DMS(region['center_easting'], region['center_northing'], precision=precision) else: return "%.*f; %.*f" % (precision, region['center_easting'], precision, region['center_northing'])
def ReprojectENFromMap(self, e, n, useDefinedProjection, precision, format): """!Reproject east, north to user defined projection. @param e,n coordinate @throws SbException if useDefinedProjection is True and projection is not defined in UserSettings """ if useDefinedProjection: settings = UserSettings.Get(group='projection', key='statusbar', subkey='proj4') if not settings: raise SbException( _("Projection not defined (check the settings)")) else: # reproject values proj, coord = utils.ReprojectCoordinates(coord=(e, n), projOut=settings, flags='d') if coord: e, n = coord if proj in ('ll', 'latlong', 'longlat') and format == 'DMS': return utils.Deg2DMS(e, n, precision=precision) else: return "%.*f; %.*f" % (precision, e, precision, n) else: raise SbException( _("Error in projection (check the settings)")) else: if self.mapFrame.GetMap( ).projinfo['proj'] == 'll' and format == 'DMS': return utils.Deg2DMS(e, n, precision=precision) else: return "%.*f; %.*f" % (precision, e, precision, n)
def OnGoTo(self, event): """Go to position""" try: e, n = self.GetValue().split(";") e, n = self.ReprojectENToMap( e, n, self.mapFrame.GetProperty("useDefinedProjection") ) self.mapFrame.GetWindow().GoTo(e, n) self.widget.SetFocus() except ValueError: # FIXME: move this code to MapWindow/BufferedWindow/MapFrame region = self.mapFrame.GetMap().GetCurrentRegion() precision = int( UserSettings.Get(group="projection", key="format", subkey="precision") ) format = UserSettings.Get(group="projection", key="format", subkey="ll") if self.mapFrame.GetMap().projinfo["proj"] == "ll" and format == "DMS": self.SetValue( "%s" % utils.Deg2DMS( region["center_easting"], region["center_northing"], precision=precision, ) ) else: self.SetValue( "%.*f; %.*f" % ( precision, region["center_easting"], precision, region["center_northing"], ) ) except SbException as e: # FIXME: this may be useless since statusbar update checks user # defined projection and this exception raises when user def proj # does not exists self.statusbar.SetStatusText(str(e), 0)
def ReprojectRegionFromMap(self, region, useDefinedProjection, precision, format): """Reproject region values .. todo:: reorganize this method to remove code useful only for derived class SbCompRegionExtent """ if useDefinedProjection: settings = UserSettings.Get(group='projection', key='statusbar', subkey='proj4') if not settings: raise SbException( _("Projection not defined (check the settings)")) else: projOut = settings proj, coord1 = utils.ReprojectCoordinates(coord=(region["w"], region["s"]), projOut=projOut, flags='d') proj, coord2 = utils.ReprojectCoordinates(coord=(region["e"], region["n"]), projOut=projOut, flags='d') # useless, used in derived class proj, coord3 = utils.ReprojectCoordinates(coord=(0.0, 0.0), projOut=projOut, flags='d') proj, coord4 = utils.ReprojectCoordinates( coord=(region["ewres"], region["nsres"]), projOut=projOut, flags='d') if coord1 and coord2: if proj in ('ll', 'latlong', 'longlat') and format == 'DMS': w, s = utils.Deg2DMS(coord1[0], coord1[1], string=False, precision=precision) e, n = utils.Deg2DMS(coord2[0], coord2[1], string=False, precision=precision) ewres, nsres = utils.Deg2DMS( abs(coord3[0]) - abs(coord4[0]), abs(coord3[1]) - abs(coord4[1]), string=False, hemisphere=False, precision=precision) return self._formatRegion(w=w, s=s, e=e, n=n, ewres=ewres, nsres=nsres) else: w, s = coord1 e, n = coord2 ewres, nsres = coord3 return self._formatRegion(w=w, s=s, e=e, n=n, ewres=ewres, nsres=nsres, precision=precision) else: raise SbException( _("Error in projection (check the settings)")) else: if self.mapFrame.GetMap( ).projinfo['proj'] == 'll' and format == 'DMS': w, s = utils.Deg2DMS(region["w"], region["s"], string=False, precision=precision) e, n = utils.Deg2DMS(region["e"], region["n"], string=False, precision=precision) ewres, nsres = utils.Deg2DMS(region['ewres'], region['nsres'], string=False, precision=precision) return self._formatRegion(w=w, s=s, e=e, n=n, ewres=ewres, nsres=nsres) else: w, s = region["w"], region["s"] e, n = region["e"], region["n"] ewres, nsres = region['ewres'], region['nsres'] return self._formatRegion(w=w, s=s, e=e, n=n, ewres=ewres, nsres=nsres, precision=precision)