예제 #1
0
    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)
예제 #2
0
 def ReprojectENToMap(self, e, n, useDefinedProjection):
     """Reproject east, north from user defined projection
     
     :param e,n: coordinate (for DMS string, else float or string)
     :param useDefinedProjection: projection defined by user in settings dialog
     
     @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
             projIn = settings
             projOut = RunCommand('g.proj', flags='jf', read=True)
             proj = projIn.split(' ')[0].split('=')[1]
             if proj in ('ll', 'latlong', 'longlat'):
                 e, n = utils.DMS2Deg(e, n)
                 proj, coord1 = utils.ReprojectCoordinates(coord=(e, n),
                                                           projIn=projIn,
                                                           projOut=projOut,
                                                           flags='d')
                 e, n = coord1
             else:
                 e, n = float(e), float(n)
                 proj, coord1 = utils.ReprojectCoordinates(coord=(e, n),
                                                           projIn=projIn,
                                                           projOut=projOut,
                                                           flags='d')
                 e, n = coord1
     elif self.mapFrame.GetMap().projinfo['proj'] == 'll':
         e, n = utils.DMS2Deg(e, n)
     else:
         e, n = float(e), float(n)
     return e, n
예제 #3
0
    def ReprojectENToMap(self, e, n, useDefinedProjection):
        """Reproject east, north from user defined projection

        :param e,n: coordinate (for DMS string, else float or string)
        :param useDefinedProjection: projection defined by user in settings dialog

        @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
                projIn = settings
                projOut = RunCommand("g.proj", flags="jf", read=True)
                proj = projIn.split(" ")[0].split("=")[1]
                if proj in ("ll", "latlong", "longlat"):
                    e, n = utils.DMS2Deg(e, n)
                    proj, coord1 = utils.ReprojectCoordinates(coord=(e, n),
                                                              projIn=projIn,
                                                              projOut=projOut,
                                                              flags="d")
                    e, n = coord1
                else:
                    e, n = float(e), float(n)
                    proj, coord1 = utils.ReprojectCoordinates(coord=(e, n),
                                                              projIn=projIn,
                                                              projOut=projOut,
                                                              flags="d")
                    e, n = coord1
        elif self.mapFrame.GetMap().projinfo["proj"] == "ll":
            e, n = utils.DMS2Deg(e, n)
        else:
            e, n = float(e), float(n)
        return e, n
예제 #4
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"],
                )
예제 #5
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'])
예제 #6
0
 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)
예제 #7
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)