diff --git a/azDigitizer.py b/azDigitizer.py index c021d14..e4a3e42 100644 --- a/azDigitizer.py +++ b/azDigitizer.py @@ -68,7 +68,7 @@ def accept(self): try: distance = float(self.distLineEdit.text()) azimuth = float(self.azimuthLineEdit.text()) - units = self.unitsComboBox.currentIndex() # 0 km, 1 m, 2 nm, 3 miles, 4 ft + units = self.unitsComboBox.currentIndex() # 0 km, 1 m, 2 nm, 3 miles, 4 yards, 5 ft, 6 inches, 7 cm start = self.checkBox.isChecked() except: self.iface.messageBar().pushMessage("", tr("Either distance or azimuth were invalid"), level=Qgis.Warning, duration=4) diff --git a/geodesicLayerMeasure.py b/geodesicLayerMeasure.py index 08af4cf..ae19120 100644 --- a/geodesicLayerMeasure.py +++ b/geodesicLayerMeasure.py @@ -22,7 +22,7 @@ from .settings import epsg4326, geod, settings from .utils import tr, DISTANCE_LABELS -unitsAbbr = ['km', 'm', 'nm', 'mi','yd','ft'] +unitsAbbr = ['km','m','cm','mi','yd','ft','in','nm'] class GeodesicLayerMeasureAlgorithm(QgsProcessingAlgorithm): """ @@ -198,14 +198,18 @@ def unitDistance(self, units, distance): return distance / 1000.0 elif units == 1: # meters return distance - elif units == 2: # nautical miles - return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceNauticalMiles) + elif units == 2: # centimeters + return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceCentimeters) elif units == 3: # miles return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceMiles) elif units == 4: # yards return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceYards) - else: # feet + elif units == 5: # feet return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceFeet) + elif units == 6: # inches + return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceFeet) * 12 + elif units == 7: # nautical miles + return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceNauticalMiles) def name(self): return 'measurelayer' diff --git a/geodesicMeasureTool.py b/geodesicMeasureTool.py index 1ba4d50..7da559d 100644 --- a/geodesicMeasureTool.py +++ b/geodesicMeasureTool.py @@ -13,7 +13,8 @@ from qgis.PyQt import uic from .settings import epsg4326, settings, geod -from .utils import tr +from .utils import tr, DISTANCE_LABELS +unitsAbbr = ['km','m','cm','mi','yd','ft','in','nm'] class GeodesicMeasureTool(QgsMapTool): @@ -70,8 +71,6 @@ def canvasMoveEvent(self, event): FORM_CLASS, _ = uic.loadUiType(os.path.join( os.path.dirname(__file__), 'ui/geodesicMeasureDialog.ui')) -UNITS = [tr('meters'), tr('kilometers'), tr('feet'), tr('yards'),tr('miles'),tr('nautical miles')] - class GeodesicMeasureDialog(QDialog, FORM_CLASS): def __init__(self, iface, parent): super(GeodesicMeasureDialog, self).__init__(parent) @@ -87,7 +86,7 @@ def __init__(self, iface, parent): self.saveToLayerButton.clicked.connect(self.saveToLayer) self.saveToLayerButton.setEnabled(False) - self.unitsComboBox.addItems(UNITS) + self.unitsComboBox.addItems(DISTANCE_LABELS) self.tableWidget.setColumnCount(3) self.tableWidget.setSortingEnabled(False) @@ -135,7 +134,7 @@ def initGeodLabel(self): self.geodLabel.setText(label) def unitsChanged(self): - label = "Distance [{}]".format(UNITS[self.unitsComboBox.currentIndex()]) + label = "Distance [{}]".format(DISTANCE_LABELS[self.unitsComboBox.currentIndex()]) item = QTableWidgetItem(label) self.tableWidget.setHorizontalHeaderItem(2, item) ptcnt = len(self.capturedPoints) @@ -321,31 +320,23 @@ def clear(self): def unitDistance(self, distance): units = self.unitsComboBox.currentIndex() - if units == 0: # meters - return distance - elif units == 1: # kilometers + if units == 0: # kilometers return distance / 1000.0 - elif units == 2: # feet - return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceFeet) - elif units == 3: # yards - return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceYards) - elif units == 4: # miles + elif units == 1: # meters + return distance + elif units == 2: # centimeters + return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceCentimeters) + elif units == 3: # miles return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceMiles) - else: # nautical miles + elif units == 4: # yards + return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceYards) + elif units == 5: # feet + return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceFeet) + elif units == 6: # inches + return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceFeet) * 12 + elif units == 7: # nautical miles return distance * QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMeters, QgsUnitTypes.DistanceNauticalMiles) def unitDesignator(self): units = self.unitsComboBox.currentIndex() - if units == 0: # meters - return 'm' - elif units == 1: # kilometers - return 'km' - elif units == 2: # feet - return 'ft' - elif units == 3: # yards - return 'yd' - elif units == 4: # miles - return 'mi' - else: # nautical miles - return 'nm' - \ No newline at end of file + return unitsAbbr[units] diff --git a/lineDigitizer.py b/lineDigitizer.py index fdc144b..b65b3d2 100644 --- a/lineDigitizer.py +++ b/lineDigitizer.py @@ -81,7 +81,7 @@ def accept(self): return for x, v in enumerate(values): values[x] = float(v) - units = self.unitsComboBox.currentIndex() # 0 km, 1 m, 2 nm, 3 miles, 4 ft + units = self.unitsComboBox.currentIndex() # 0 km, 1 m, 2 nm, 3 miles, 4 yards, 5 feet, 6 inches, 7 cm except: self.iface.messageBar().pushMessage("", tr("One or more entered values were invalid"), level=Qgis.Warning, duration=4) return diff --git a/metadata.txt b/metadata.txt index f8a0fe2..b1de2ed 100644 --- a/metadata.txt +++ b/metadata.txt @@ -2,7 +2,7 @@ name=Shape Tools qgisMinimumVersion=3.2 description=Shape Tools is a collection of geodesic shapes and tools. Create ellipse, line of bearing, pie wedge, donut, arc wedge, polygon, star, ellipse rose, hypocyloid, polyfoil, epicycloid, and heart shapes. Tools include "XY to Line" tool, densify lines and polygons along geodesic paths, geodesic line break, geodesic measuring and create a measurement layer, geodesic scale, rotate, flip and translate tools, and digitize points at an azimuth & distance tools. -version=3.3.2 +version=3.3.3 author=C Hamilton email=adenaculture@gmail.com about=Shape Tools is a collection of geodesic shapes and tools. Shape Tools is installed in the Vector menu. @@ -24,6 +24,7 @@ icon=images/shapes.png experimental=False deprecated=False changelog= + 3.3.3 - Added inches and centimeters for units of measure in all the respective tools. 3.3.2 - Bug fix. 3.3.1 - Added geodesic flip & rotation tools 3.3.0 - Added geodesic transformation tool diff --git a/readme.md b/readme.md index 430b23b..51467e7 100644 --- a/readme.md +++ b/readme.md @@ -158,7 +158,7 @@ This function can also be accessed from the **Processing Toolbox**. ## ![Geodesic Measure Tool](images/measure.png) Geodesic Measure Tool -This provides the ability to measure distances using geodesic (shortest path) algorithms. The results returned are similar to those used by Google Earth and makes for a nice baseline of distances. It also includes the heading from the first point to the second and a heading from the second point to the first. The units are in degrees. The units of distance can be meters, kilometers, feet, yards, miles, and nautical miles. Simply click on the ***Geodesic Measure Tool*** icon and start clicking on the map. Notice that the ellipsoid used to calculate measurements is listed in the lower left-hand corner. By default this is set to ***WGS 84***, but it can be changed in the ***Settings*** menu. +This provides the ability to measure distances using geodesic (shortest path) algorithms. The results returned are similar to those used by Google Earth and makes for a nice baseline of distances. It also includes the heading from the first point to the second and a heading from the second point to the first. The units are in degrees. The units of distance can be kilometers, meters, centimeters, miles, yards, feet, inches, and nautical miles. Simply click on the ***Geodesic Measure Tool*** icon and start clicking on the map. Notice that the ellipsoid used to calculate measurements is listed in the lower left-hand corner. By default this is set to ***WGS 84***, but it can be changed in the ***Settings*** menu.
@@ -172,7 +172,7 @@ By right-mouse clicking on the **Measurement** layer and selecting **Open Attrib ## ![Geodesic Measurement Layer](images/linedigitize.png) Geodesic Measurement Layer -This take either a polygon or line layer and for each of the geometries calculates the geodesic distances of each feature. The user can choose whether each line segment is measured and output as a line measurement or whether the entire line/polygon geometry is measured. It outputs a new line layer of lines that contain attributes with all the measurements. If measuring individual line segments the attributes are a label, distance, units of measure, azimuth/bearing to the next point, and the total distance of the geometry. If measuring the entire geometry then the attributes are a label, distance, and units of measure. The input is either a line or polygon layer. Select whether you want to measure the entire line or polygon or each line segment within the line or polygon. **Distance units** can be kilometers, meters, nautical miles, miles, yards, or feet. **Use automatic styling** styles the QGIS layer with the label string in the attribute table and with the text and line colors found in **Settings**. +This take either a polygon or line layer and for each of the geometries calculates the geodesic distances of each feature. The user can choose whether each line segment is measured and output as a line measurement or whether the entire line/polygon geometry is measured. It outputs a new line layer of lines that contain attributes with all the measurements. If measuring individual line segments the attributes are a label, distance, units of measure, azimuth/bearing to the next point, and the total distance of the geometry. If measuring the entire geometry then the attributes are a label, distance, and units of measure. The input is either a line or polygon layer. Select whether you want to measure the entire line or polygon or each line segment within the line or polygon. **Distance units** can be kilometers, meters, centimeters, miles, yards, feet, inches, or nautical miles. **Use automatic styling** styles the QGIS layer with the label string in the attribute table and with the text and line colors found in **Settings**. diff --git a/utils.py b/utils.py index 303d88e..8685154 100644 --- a/utils.py +++ b/utils.py @@ -7,21 +7,25 @@ def tr(string): return QCoreApplication.translate('Processing', string) -DISTANCE_LABELS=[tr("Kilometers"),tr("Meters"),tr("Nautical Miles"),tr("Miles"),tr('Yards'),tr("Feet")] +DISTANCE_LABELS=[tr("Kilometers"),tr("Meters"),tr("Centimeters"),tr("Miles"),tr('Yards'),tr("Feet"),tr("Inches"),tr("Nautical Miles")] def conversionToMeters(units): if units == 0: # Kilometers measureFactor = 1000.0 elif units == 1: # Meters measureFactor = 1.0 - elif units == 2: # Nautical Miles - measureFactor = QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceNauticalMiles, QgsUnitTypes.DistanceMeters) + elif units == 2: # Centimeters + measureFactor = QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceCentimeters , QgsUnitTypes.DistanceMeters) elif units == 3: # Miles measureFactor = QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceMiles, QgsUnitTypes.DistanceMeters) elif units == 4: # Yards measureFactor = QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceYards, QgsUnitTypes.DistanceMeters) elif units == 5: # Feet measureFactor = QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceFeet, QgsUnitTypes.DistanceMeters) + elif units == 6: # Inches + measureFactor = QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceFeet, QgsUnitTypes.DistanceMeters) / 12.0 + elif units == 7: # Nautical Miles + measureFactor = QgsUnitTypes.fromUnitToUnitFactor(QgsUnitTypes.DistanceNauticalMiles, QgsUnitTypes.DistanceMeters) return measureFactor def normalizeLongitude(pts):