Exemplo n.º 1
0
    def test_simple_format(self):
        """
        Test QgsBabelSimpleImportFormat
        """
        f = QgsBabelSimpleImportFormat('shapefile', 'ESRI Shapefile',
                                       Qgis.BabelFormatCapability.Waypoints,
                                       ['shp', 'shx'])
        self.assertEqual(f.name(), 'shapefile')
        self.assertEqual(f.description(), 'ESRI Shapefile')
        self.assertEqual(f.extensions(), ['shp', 'shx'])
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Waypoints
                                         | Qgis.BabelFormatCapability.Import))
        f = QgsBabelSimpleImportFormat(
            'shapefile', 'ESRI Shapefile',
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Waypoints
                                         | Qgis.BabelFormatCapability.Tracks))
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Waypoints
                                         | Qgis.BabelFormatCapability.Tracks
                                         | Qgis.BabelFormatCapability.Import))

        self.assertEqual(
            f.importCommand('babel.exe', Qgis.GpsFeatureType.Waypoint,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-w', '-i', 'shapefile', '-o',
                                'gpx', 'c:/test/test.shp', 'c:/test/test.gpx'
                            ])
        self.assertEqual(
            f.importCommand('babel.exe', Qgis.GpsFeatureType.Track,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-t', '-i', 'shapefile', '-o',
                                'gpx', 'c:/test/test.shp', 'c:/test/test.gpx'
                            ])
        self.assertEqual(
            f.importCommand('babel.exe', Qgis.GpsFeatureType.Route,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-r', '-i', 'shapefile', '-o',
                                'gpx', 'c:/test/test.shp', 'c:/test/test.gpx'
                            ])

        # with quoted paths
        self.assertEqual(
            f.importCommand('babel.exe', Qgis.GpsFeatureType.Route,
                            'c:/test/test.shp', 'c:/test/test.gpx',
                            Qgis.BabelCommandFlag.QuoteFilePaths),
            [
                '"babel.exe"', '-r', '-i', 'shapefile', '-o', 'gpx',
                '"c:/test/test.shp"', '"c:/test/test.gpx"'
            ])

        # export not supported
        self.assertEqual(
            f.exportCommand('babel.exe', Qgis.GpsFeatureType.Waypoint,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [])
Exemplo n.º 2
0
    def test_gps_device_format(self):
        """
        Test QgsBabelGpsDeviceFormat
        """
        f = QgsBabelGpsDeviceFormat("%babel -w -i garmin -o gpx %in %out",
                                    "%babel -w -i gpx -o garmin %in %out",
                                    "%babel -r -i garmin -o gpx %in %out",
                                    "%babel -r -i gpx -o garmin %in %out",
                                    "%babel -t -i garmin -o gpx %in %out",
                                    "%babel -t -i gpx -o garmin %in %out")
        # waypoint/track/route capability should be automatically set/removed
        # depending on whether the corresponding commands are empty
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Waypoints
                                         | Qgis.BabelFormatCapability.Import
                                         | Qgis.BabelFormatCapability.Export
                                         | Qgis.BabelFormatCapability.Tracks
                                         | Qgis.BabelFormatCapability.Routes))

        self.assertEqual(
            f.importCommand('babel.exe', Qgis.GpsFeatureType.Waypoint,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-w', '-i', 'garmin', '-o', 'gpx',
                                'c:/test/test.shp', 'c:/test/test.gpx'
                            ])
        self.assertEqual(
            f.importCommand('babel.exe', Qgis.GpsFeatureType.Track,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-t', '-i', 'garmin', '-o', 'gpx',
                                'c:/test/test.shp', 'c:/test/test.gpx'
                            ])
        self.assertEqual(
            f.importCommand('babel.exe', Qgis.GpsFeatureType.Route,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-r', '-i', 'garmin', '-o', 'gpx',
                                'c:/test/test.shp', 'c:/test/test.gpx'
                            ])

        self.assertEqual(
            f.exportCommand('babel.exe', Qgis.GpsFeatureType.Waypoint,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-w', '-i', 'gpx', '-o', 'garmin',
                                'c:/test/test.shp', 'c:/test/test.gpx'
                            ])
        self.assertEqual(
            f.exportCommand('babel.exe', Qgis.GpsFeatureType.Track,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-t', '-i', 'gpx', '-o', 'garmin',
                                'c:/test/test.shp', 'c:/test/test.gpx'
                            ])
        self.assertEqual(
            f.exportCommand('babel.exe', Qgis.GpsFeatureType.Route,
                            'c:/test/test.shp', 'c:/test/test.gpx'), [
                                'babel.exe', '-r', '-i', 'gpx', '-o', 'garmin',
                                'c:/test/test.shp', 'c:/test/test.gpx'
                            ])

        # with quoted paths
        self.assertEqual(
            f.exportCommand('babel.exe', Qgis.GpsFeatureType.Route,
                            'c:/test/test.shp', 'c:/test/test.gpx',
                            Qgis.BabelCommandFlag.QuoteFilePaths),
            [
                '"babel.exe"', '-r', '-i', 'gpx', '-o', 'garmin',
                '"c:/test/test.shp"', '"c:/test/test.gpx"'
            ])

        # waypoint/track/route capability should be automatically set/removed
        # depending on whether the corresponding commands are empty
        f = QgsBabelGpsDeviceFormat("%babel -w -i garmin -o gpx %in %out",
                                    None, None, None, None, None)
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Waypoints
                                         | Qgis.BabelFormatCapability.Import))
        f = QgsBabelGpsDeviceFormat(None,
                                    "%babel -w -i gpx -o garmin %in %out",
                                    None, None, None, None)
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Waypoints
                                         | Qgis.BabelFormatCapability.Export))
        f = QgsBabelGpsDeviceFormat(None, None,
                                    "%babel -r -i garmin -o gpx %in %out",
                                    None, None, None)
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Routes
                                         | Qgis.BabelFormatCapability.Import))
        f = QgsBabelGpsDeviceFormat(None, None, None,
                                    "%babel -r -i gpx -o garmin %in %out",
                                    None, None)
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Routes
                                         | Qgis.BabelFormatCapability.Export))
        f = QgsBabelGpsDeviceFormat(None, None, None, None,
                                    "%babel -t -i garmin -o gpx %in %out",
                                    None)
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Tracks
                                         | Qgis.BabelFormatCapability.Import))
        f = QgsBabelGpsDeviceFormat(None, None, None, None, None,
                                    "%babel -t -i gpx -o garmin %in %out")
        self.assertEqual(
            f.capabilities(),
            Qgis.BabelFormatCapabilities(Qgis.BabelFormatCapability.Tracks
                                         | Qgis.BabelFormatCapability.Export))