Exemplo n.º 1
0
 def conversionToMeters(self, units):
     if units == 2:  # Nautical Miles
         measureFactor = QGis.fromUnitToUnitFactor(QGis.NauticalMiles,
                                                   QGis.Meters)
     elif units == 0:  # Kilometers
         measureFactor = 1000.0
     elif units == 1:  # Meters
         measureFactor = 1.0
     elif units == 3:  # Miles
         measureFactor = QGis.fromUnitToUnitFactor(QGis.Feet,
                                                   QGis.Meters) * 5280.0
     elif units == 4:  # Feet
         measureFactor = QGis.fromUnitToUnitFactor(QGis.Feet, QGis.Meters)
     return measureFactor
Exemplo n.º 2
0
 def unitDistance(self, distance):
     units = self.unitsComboBox.currentIndex()
     if units == 0: # meters
         return distance
     elif units == 1: # kilometers
         return distance / 1000.0
     elif units == 2: # feet
         return distance * QGis.fromUnitToUnitFactor(QGis.Meters, QGis.Feet)
     elif units == 3: # yards
         return distance * QGis.fromUnitToUnitFactor(QGis.Meters, QGis.Feet) / 3.0
     elif units == 4: # miles
         return distance * QGis.fromUnitToUnitFactor(QGis.Meters, QGis.Miles)
     else: # nautical miles
         return distance * QGis.fromUnitToUnitFactor(QGis.Meters, QGis.NauticalMiles)
Exemplo n.º 3
0
    def _calc_size(self):
        realSize = self.realsize
        canvaswidth = self.canvas.width()
        mapunitsperpixel = abs(self.canvas.mapUnitsPerPixel())
        mapunits = self.canvas.mapUnits()
        prefered_units = roam.config.settings.get("prefer_units", "meters")
        newunits = QGis.fromLiteral(prefered_units, QGis.Meters)
        mapunitsperpixel *= QGis.fromUnitToUnitFactor(mapunits, newunits)
        mapunits = newunits

        # Convert the real distance into pixels
        barwidth = realSize / mapunitsperpixel

        if barwidth < 30:
            barwidth = canvaswidth / 4

        while barwidth > canvaswidth / 3:
            barwidth /= 3

        realSize = barwidth * mapunitsperpixel

        # Round
        powerof10 = math.floor(math.log10(realSize))
        scaler = math.pow(10.0, powerof10)
        realSize = round(realSize / scaler) * scaler
        barwidth = realSize / mapunitsperpixel
        label, realSize = self._label_size(mapunits, realSize)
        metrics = QFontMetrics(self.font)
        fontwidth = metrics.width(label)
        fontheight = metrics.height()

        sizelabel = QLocale.system().toString(realSize)
        sizelabel = "{} {}".format(sizelabel, label)

        barwidth = self._adjust_bar_size(barwidth, mapunits)
        barwidth = barwidth + fontwidth

        return barwidth, realSize, sizelabel, (fontwidth, fontheight)
Exemplo n.º 4
0
    def _calc_size(self):
        realSize = self.realsize
        canvaswidth = self.canvas.width()
        mapunitsperpixel = abs(self.canvas.mapUnitsPerPixel())
        mapunits = self.canvas.mapUnits()
        prefered_units = roam.config.settings.get("prefer_units", "meters")
        newunits = QGis.fromLiteral(prefered_units, QGis.Meters)
        mapunitsperpixel *= QGis.fromUnitToUnitFactor(mapunits, newunits)
        mapunits = newunits

        # Convert the real distance into pixels
        barwidth = realSize / mapunitsperpixel

        if barwidth < 30:
            barwidth = canvaswidth / 4

        while barwidth > canvaswidth / 3:
            barwidth /= 3

        realSize = barwidth * mapunitsperpixel

        # Round
        powerof10 = math.floor(math.log10(realSize))
        scaler = math.pow(10.0, powerof10)
        realSize = round(realSize / scaler) * scaler
        barwidth = realSize / mapunitsperpixel
        label, realSize = self._label_size(mapunits, realSize)
        metrics = QFontMetrics(self.font)
        fontwidth = metrics.width(label)
        fontheight = metrics.height()

        sizelabel = QLocale.system().toString(realSize)
        sizelabel = "{} {}".format(sizelabel, label)

        barwidth = self._adjust_bar_size(barwidth, mapunits)
        barwidth = barwidth + fontwidth

        return barwidth, realSize, sizelabel, (fontwidth, fontheight)
Exemplo n.º 5
0
    def processEllipse(self, layer, outname, semimajorcol, semiminorcol,
                       orientcol, unitOfMeasure, defSemiMajor, defSemiMinor,
                       defOrientation):
        measureFactor = 1.0
        # The ellipse calculation is done in Nautical Miles. This converts
        # the semi-major and minor axis to nautical miles
        if unitOfMeasure == 2:  # Nautical Miles
            measureFactor = 1.0
        elif unitOfMeasure == 0:  # Kilometers
            measureFactor = QGis.fromUnitToUnitFactor(
                QGis.Meters, QGis.NauticalMiles) * 1000.0
        elif unitOfMeasure == 1:  # Meters
            measureFactor = QGis.fromUnitToUnitFactor(QGis.Meters,
                                                      QGis.NauticalMiles)
        elif unitOfMeasure == 3:  # Miles
            measureFactor = QGis.fromUnitToUnitFactor(
                QGis.Feet, QGis.NauticalMiles) * 5280.0
        elif unitOfMeasure == 4:  # Feet
            measureFactor = QGis.fromUnitToUnitFactor(QGis.Feet,
                                                      QGis.NauticalMiles)

        fields = layer.pendingFields()

        self.polygonLayer = QgsVectorLayer("Polygon?crs=epsg:4326", outname,
                                           "memory")
        ppolygon = self.polygonLayer.dataProvider()
        ppolygon.addAttributes(fields)
        self.polygonLayer.updateFields()

        iter = layer.getFeatures()
        num_features = 0
        num_good = 0
        for feature in iter:
            num_features += 1
            try:
                if semimajorcol != -1:
                    semi_major = float(feature[semimajorcol])
                else:
                    semi_major = defSemiMajor
                if semiminorcol != -1:
                    semi_minor = float(feature[semiminorcol])
                else:
                    semi_minor = defSemiMinor
                if orientcol != -1:
                    orient = float(feature[orientcol])
                else:
                    orient = defOrientation
                pt = feature.geometry().asPoint()
                # make sure the coordinates are in EPSG:4326
                pt = self.transform.transform(pt.x(), pt.y())
                geom = LatLon.getEllipseCoords(pt.y(), pt.x(),
                                               semi_major * measureFactor,
                                               semi_minor * measureFactor,
                                               orient)
                featureout = QgsFeature()
                featureout.setGeometry(QgsGeometry.fromPolygon([geom]))
                featureout.setAttributes(feature.attributes())
                ppolygon.addFeatures([featureout])
                num_good += 1
            except:
                # Just skip any lines that are badly formed
                pass
        self.polygonLayer.updateExtents()
        QgsMapLayerRegistry.instance().addMapLayer(self.polygonLayer)
        self.iface.messageBar().pushMessage(
            "",
            "{} Ellipses created from {} records".format(
                num_good, num_features),
            level=QgsMessageBar.INFO,
            duration=3)