Skip to content

Commit

Permalink
added centimeters and inches
Browse files Browse the repository at this point in the history
  • Loading branch information
hamiltoncj committed Jan 2, 2019
1 parent 38e6bba commit 14a0084
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 39 deletions.
2 changes: 1 addition & 1 deletion azDigitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 8 additions & 4 deletions geodesicLayerMeasure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
"""
Expand Down Expand Up @@ -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'
Expand Down
45 changes: 18 additions & 27 deletions geodesicMeasureTool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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'

return unitsAbbr[units]
2 changes: 1 addition & 1 deletion lineDigitizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion metadata.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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 protected]
about=Shape Tools is a collection of geodesic shapes and tools. Shape Tools is installed in the Vector menu.
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ This function can also be accessed from the **Processing Toolbox**.

## <a name="geodesic-measure"></a> ![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.

<div style="text-align:center"><img src="doc/geodesicmeasure.jpg" alt="Geodesic Measure Tool"></div>

Expand All @@ -172,7 +172,7 @@ By right-mouse clicking on the **Measurement** layer and selecting **Open Attrib

## <a name="geodesic-measure-layer"></a> ![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**.

<div style="text-align:center"><img src="doc/measurement-layer.jpg" alt="Geodesic Measurement Layer"></div>

Expand Down
10 changes: 7 additions & 3 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 14a0084

Please sign in to comment.