Beispiel #1
0
    def toMgrs(self):
        '''Convert this UTM coordinate to an MGRS grid reference.

           See function L{toMgrs} in module L{mgrs} for more details.

           @return: The MGRS grid reference (L{Mgrs}).
        '''
        if self._mgrs is None:
            from mgrs import toMgrs  # PYCHOK recursive import
            self._mgrs = toMgrs(self, name=self.name)
        return self._mgrs
Beispiel #2
0
 def formatCoord(self, pt, delimiter, outputFormat, order):
     '''Format the coordinate according to the settings from
     the settings dialog.'''
     if outputFormat == 'native':
         # Formatin in the native CRS
         if order == 0:
             msg = str(pt.y()) + delimiter + str(pt.x())
         else:
             msg = str(pt.x()) + delimiter + str(pt.y())
     elif outputFormat == 'mgrs':
         # Make sure the coordinate is transformed to EPSG:4326
         canvasCRS = self.canvas.mapRenderer().destinationCrs()
         epsg4326 = QgsCoordinateReferenceSystem("EPSG:4326")
         transform = QgsCoordinateTransform(canvasCRS, epsg4326)
         pt4326 = transform.transform(pt.x(), pt.y())
         try:
             msg = mgrs.toMgrs(pt4326.y(), pt4326.x())
         except:
             msg = None
     else:
         # Make sure the coordinate is transformed to EPSG:4326
         canvasCRS = self.canvas.mapRenderer().destinationCrs()
         epsg4326 = QgsCoordinateReferenceSystem("EPSG:4326")
         transform = QgsCoordinateTransform(canvasCRS, epsg4326)
         pt4326 = transform.transform(pt.x(), pt.y())
         self.latlon.setCoord(pt4326.y(), pt4326.x())
         self.latlon.setPrecision(self.settings.dmsPrecision)
         if self.latlon.isValid():
             if outputFormat == 'dms':
                 if order == 0:
                     msg = self.latlon.getDMS(delimiter)
                 else:
                     msg = self.latlon.getDMSLonLatOrder(delimiter)
             elif outputFormat == 'ddmmss':
                 if order == 0:
                     msg = self.latlon.getDDMMSS(delimiter)
                 else:
                     msg = self.latlon.getDDMMSSLonLatOrder(delimiter)
             else:  # decimal degrees
                 if order == 0:
                     msg = str(self.latlon.lat) + delimiter + str(
                         self.latlon.lon)
                 else:
                     msg = str(self.latlon.lon) + delimiter + str(
                         self.latlon.lat)
         else:
             msg = None
     return msg
    def write_polygon(self, poly):
        self.report_point = []
        z = poly.elev
        # print "point count: {}".format(poly.polygon.GetPointCount())
        # print "geometry count: {}".format(poly.polygon.GetGeometryCount())
        # if id == 5:
        #     for keyName in inspect.getmembers(poly.polygon):
        #        print keyName
        # for i in range(0, poly.polygon.GetPointCount()):
        #     point = poly.polygon.GetPoint(i)
        #     point_mgrs = mgrs.toMgrs(point[1], point[0], 5)
        #     print point
        #     # self.report_point.append(point_mgrs)
        #     print "probehlo"

        for ring in poly.polygon:
            for i in range(0, ring.GetPointCount()):
                point = ring.GetPoint(i)
                point_mgrs = mgrs.toMgrs(point[1], point[0], 5)
                # print "point mgrs: {}".format(point_mgrs)
                self.report_point.append(point_mgrs)

        # print len(self.report_point)
        self.createReport(z)