From c74ec33495ab9c5dbbe8f079cd593e6b874bc022 Mon Sep 17 00:00:00 2001
From: A Nilsen <ban@nibio.no>
Date: Mon, 9 Jan 2023 13:42:12 +0000
Subject: [PATCH] Typo and translate from Norwegian into English

---
 get_nib.py | 73 +++++++++++++++++++++++++++---------------------------
 1 file changed, 36 insertions(+), 37 deletions(-)

diff --git a/get_nib.py b/get_nib.py
index 56145e1..44efc65 100644
--- a/get_nib.py
+++ b/get_nib.py
@@ -245,7 +245,7 @@ class getnib:
         ll = xform.transform(QgsPointXY(xmin,ymin))  # Bounding box's lower left corner
         ur = xform.transform(QgsPointXY(xmax,ymax))  # Bounding box's upper right corner
         # Get the maximum height and length of the bounding box (limit is set to 500 km)
-        xdist = (ur.x()-ll.x())/1000  # Get lenght in km (xmax-xmin)
+        xdist = (ur.x()-ll.x())/1000  # Get length in km (xmax-xmin)
         ydist = (ur.y()-ll.y())/1000  # Get height in km (ymax-ymin)
         if xdist > 500 or ydist > 500:
             self.iface.messageBar().pushMessage("Error", "Height or length of bounding box can't be > 500 km",level=Qgis.Critical, duration=3)
@@ -255,9 +255,8 @@ class getnib:
         return ok
 
     ## Bounding box ##
-
-    # When you change your mind during input (started input of one bb-option and then chnages to another bb-option),
-    # e.g. have entered a length or selected a file, but change your mind and click Use current map canvas insted.
+    # When you change your mind during input (started input of one bb-option and then changes to another bb-option),
+    # e.g. have entered a length or selected a file, but change your mind and click Use current map canvas instead.
     # Then length and the file should be wiped out.
     def notUdbb(self):
         self.dlg.lineEdit_lengthbb.clear()
@@ -433,7 +432,7 @@ class getnib:
 
         # As default: Set map canvas checkbox to checked
         """ If this should not be the default, comment # next line """
-        self.dlg.radioButton_ucmcbb.setChecked(True)    # Checked
+        self.dlg.radioButton_ucmcbb.setChecked(True)  # Checked
 
         # Clear the contents of the lineEdit_lengthbb from previous runs
         self.dlg.lineEdit_lengthbb.clear()
@@ -446,7 +445,7 @@ class getnib:
         # Clear the contents of the lineEdit_file (select file) from previous runs
         self.dlg.lineEdit_file.clear()
 
-        self.dlg.radioButton_file.setChecked(False)     # Unchecked
+        self.dlg.radioButton_file.setChecked(False)   # Unchecked
 
         # Fetch the currently loaded layers
         layers = QgsProject.instance().mapLayers()
@@ -460,9 +459,9 @@ class getnib:
             layer_list.append(item)                 # Includes duplicates
         unique_lyr = list(set(layer_list))          # No duplicates
         self.dlg.comboBox_lyr.addItems(unique_lyr)  # Populate combobox
-        self.dlg.comboBox_lyr.model().sort(0)       # Sort layer names (includes filepath) alfabetically
+        self.dlg.comboBox_lyr.model().sort(0)       # Sort layer names (includes filepath) alphabetically
 
-        # Length and height: allowing only 1-500
+        # Length and height: allowing only 1-500 due to max. 500 km x 500 km
         l = self.dlg.lineEdit_lengthbb
         l.setValidator(QRegExpValidator(QRegExp("[1-9]|[1-9][0-9]|[1-4][0-9][0-9]|500")))
         h = self.dlg.lineEdit_heightbb
@@ -474,13 +473,13 @@ class getnib:
 
         # Start- and end-year: must be 1900-current year
         currentDate = datetime.date.today()
-        cy = currentDate.year  # get current year, e.g. 2022 (position 0,1,2,3)
+        cy = currentDate.year  # get current year, e.g. 2023 (position 0,1,2,3)
         # cy = 2042  # used for testing the regexp
         cy = str(cy)  # Convert number to string
         d3 = cy[2]    # Get the third digit (in position 2)
         d4 = cy[3]    # Get the fourth digit (in position 3)
         # # Debugging
-        # self.iface.messageBar().pushMessage("Info", "To siste sifre i år er: "+d3+', '+d4, level=Qgis.Info, duration=3)
+        # self.iface.messageBar().pushMessage("Info", "Two last digits in year are: "+d3+', '+d4, level=Qgis.Info, duration=3)
 
         # Verifying the entered years
         start = self.dlg.lineEdit_startyear
@@ -524,9 +523,8 @@ class getnib:
                 ymin = e.yMinimum()
                 ymax = e.yMaximum()
                 ok = self.check_bbsize(crs_proj_str, xmin, xmax, ymin, ymax)  # Check if bb is small enough
-            # If checked, use the length and height from map canvas sentre point
+            # If checked, use the length and height from map canvas centre point
             elif self.dlg.radioButton_udbb.isChecked():
-                # Get the extent of current map canvas (coordinates in the project's crs)
                 l = self.dlg.lineEdit_lengthbb.text()
                 h = self.dlg.lineEdit_heightbb.text()
                 if l == "" or h == "":
@@ -536,7 +534,7 @@ class getnib:
                     # Length and height (in km) requires projected coordinated. Ensures this by converting the coordinates to LAEA
                     e = iface.mapCanvas().extent().center()
                     # Debugging
-                    # self.iface.messageBar().pushMessage("Info", "Center x, y: " + str(e.x()) +", "+ str(e.y())+", "+crs_proj_str, level=Qgis.Info, duration=5)
+                    # self.iface.messageBar().pushMessage("Info", "Centre x, y: " + str(e.x()) +", "+ str(e.y())+", "+crs_proj_str, level=Qgis.Info, duration=5)
                     # Computes corner coordinates in LAE regardless input crs
                     xmin = e.x() - int(l)*1000/2
                     xmax = e.x() + int(l)*1000/2
@@ -544,11 +542,11 @@ class getnib:
                     ymax = e.y() + int(h)*1000/2
                     """ Check length and height of bounding box. Limit is set to 500 km """
                     ok = self.check_bbsize(crs_proj_str, xmin, xmax, ymin, ymax)  # Check if bb is small enough
-            else:  # a layer or a file is selcted
-                if self.dlg.radioButton_lyr.isChecked():  # layer-option checked
+            else:  # A layer or a file is selcted as bounding box
+                if self.dlg.radioButton_lyr.isChecked():  # Layer-option checked
                     lyr_name = self.dlg.comboBox_lyr.currentText()  # Get the layer name
                     if lyr_name != "":  #  If a layer is present/chosen
-                        # self.iface.messageBar().pushMessage("Info", "Valgt layer: "+lyr_name, level=Qgis.Info, duration=3)
+                        # self.iface.messageBar().pushMessage("Info", "Chosen layer: "+lyr_name, level=Qgis.Info, duration=3)
                         selectedLayer = QgsProject.instance().mapLayersByName(lyr_name)[0]  # Get this vector layer
                         # Get the extent of the layer (coordinates in the selected layer's crs)
                         e = selectedLayer.extent()
@@ -556,11 +554,11 @@ class getnib:
                         self.iface.messageBar().pushMessage("Error", "No layer selected!", level=Qgis.Critical, duration=3)
                         return  # Return from (end) plugin
 			    
-                elif self.dlg.radioButton_file.isChecked():  # file-option checked
-                    fname = self.dlg.lineEdit_file.text()  # get the text (path and filename)
+                elif self.dlg.radioButton_file.isChecked():  # File-option checked
+                    fname = self.dlg.lineEdit_file.text()  # Get the text (path and filename)
                     if fname != "":
-                        lname = os.path.splitext(os.path.basename(fname))[0] #get only the filename without the extension, will be used as layer name in the Layers panel in QGIS
-                        # self.iface.messageBar().pushMessage("Info", "Valgt fil: "+lname, level=Qgis.Info, duration=3)
+                        lname = os.path.splitext(os.path.basename(fname))[0]  #get only the filename without the extension, will be used as layer name in the Layers panel in QGIS
+                        # self.iface.messageBar().pushMessage("Info", "Chosen file: "+lname, level=Qgis.Info, duration=3)
                         file = r""+fname+""  # Reads the file
                         fLayer = QgsVectorLayer(file, lname, "ogr")  # If vector file
                         if not fLayer.isValid():  # If not valid vector laayer
@@ -575,7 +573,7 @@ class getnib:
                     else:
                         self.iface.messageBar().pushMessage("Error", "No file selected!", level=Qgis.Critical, duration=3)
                         return  # Return from (end) plugin
-                # Hverken layer eller fil er valgt
+                # Neither layer nor file is selected
                 else:
                     self.iface.messageBar().pushMessage("Error", "No extent", level=Qgis.Critical, duration=5)
                
@@ -585,7 +583,7 @@ class getnib:
                 iface.zoomToActiveLayer()
 			    
                 # Get selected layer's epsg:code                                    
-                crs_lyr = selectedLayer.crs()           # example:
+                crs_lyr = selectedLayer.crs()           # Example:
                 crs_lyr_str = crs_lyr.authid()          # EPSG:4258
                 try:
                     crs_lyr_int = int(crs_lyr_str[5:])  # 4258
@@ -603,7 +601,7 @@ class getnib:
                 # self.iface.messageBar().pushMessage("Info", "extent"+str(coords), level=Qgis.Info, duration=3)             
                 # If selected file or layer and project have different crs, the layer's 
                 # bounding box coordinates must be transformed into the project's crs
-                if crs_lyr_int != crs_proj_int:
+                if crs_lyr_int != crs_proj_int:  # Selected file or layer and project have NOT the same crs
                     sourceCrs = QgsCoordinateReferenceSystem(crs_lyr_str)
                     destCrs = QgsCoordinateReferenceSystem(crs_proj_str)
                     transformContext = QgsProject.instance().transformContext()
@@ -636,23 +634,24 @@ class getnib:
                 group = root.findGroup('Nib-prosjekt')  # Find the group
                 root.removeChildNode(group)             # Remove the group
             # Recreate Nib-prosjekt group
-            # Add a layer group to be used for all orthophoto-projects within the active layer's extent
-            if not root.findGroup("Nib-prosjekt"):     # If the group don't exist
+            # Add a layer group to be used for all orthophoto-projects within the bounding box
+            if not root.findGroup("Nib-prosjekt"):     # If the group doesn't exist,
                 group = root.addGroup('Nib-prosjekt')  # add the group and name it "Nib-prosjekt"
                 # group.setExpanded(False)               # Collapse the layer group
 
-            # Load Norge i bilder-project based on active layer's bounding box (geojson-format x1,y1;x2,y2;x3,y3;...)
+            # Load Norge i bilder-project based on the bounding box (geojson-format x1,y1;x2,y2;x3,y3;...)
             # https://norgeibilder.no/dok/webtjenester.pdf
             para=parse.quote('{Filter:"ortofototype in (1,2,3,4,8,9,12)",Coordinates:"'+coords+'",InputWKID:'+str(crs_proj_int)+',StopOnCover:false}')
             js = requests.get('https://tjenester.norgeibilder.no/rest/projectMetadata.ashx?request='+para).json()  #list with current of-project on json-format
-            print(js)  # {Success:true,ErrorMessage:null,ProjectList:[Sør-Varanger 2019,Sør-Varanger veg 2016,Sør-Varanger 2013,Sør-Varanger 2011],ProjectMetadata:null}
             nib_liste = js['ProjectList']
-            print('nib_liste =',nib_liste)  # nib_liste = ['Sør-Varanger 2019', 'Sør-Varanger veg 2016', 'Sør-Varanger 2013', 'Sør-Varanger 2011']
+            # Debugging
+            # print(js)  # {Success:true,ErrorMessage:null,ProjectList:[Sør-Varanger 2019,Sør-Varanger veg 2016,Sør-Varanger 2013,Sør-Varanger 2011],ProjectMetadata:null}
+            # print('nib_liste =',nib_liste)  # nib_liste = ['Sør-Varanger 2019', 'Sør-Varanger veg 2016', 'Sør-Varanger 2013', 'Sør-Varanger 2011']
             # self.iface.messageBar().pushMessage("Info", "All OF: "+ str(nib_liste),level=Qgis.Info, duration=3)
 
-            nib_liste_years = []  #Initialize
+            nib_liste_years = []  # Initialize
 
-            # Ensured 4 digits in start and end-year. However, the years might be wrong. start > end, < 4 digits. Checking this.
+            # Ensure 4 digits in start and end-year and start year < end year.
             if self.dlg.radioButton_btwyears.isChecked():
                 # Get the extent of current map canvas (coordinates in the project's crs)
                 start = self.dlg.lineEdit_startyear.text()
@@ -688,7 +687,7 @@ class getnib:
                             layer_parent = tree_layer.parent()
                             if str(layer_parent.name()) == 'Nib-prosjekt':  # If layer exists in group Nib-prosjekt, it will not be added
                                 self.iface.messageBar().pushMessage("Info", "WMS layer exists: "+ str(nibprosjwms),level=Qgis.Info, duration=1)
-                                continue  # Return the control to the beginning of the for loop
+                                continue  # Return the control to the beginning of the for-loop
                             else:  # The layer exists but not in the Nib-prosjekt group 
                                QgsProject.instance().addMapLayer(rlayer, False)  # Add the raster layer without showing it (False)
                                mygroup = root.findGroup("Nib-prosjekt")          # Get the group named "Nib-prosjekt"
@@ -696,7 +695,7 @@ class getnib:
                                # Uncheck the raster layer
                                QgsProject.instance().layerTreeRoot().findLayer(rlayer.id()).setItemVisibilityChecked(False)
                                self.iface.messageBar().pushMessage("Success", "WMS reloaded", level=Qgis.Success, duration=3)
-                    else:  # layer does not exist, thus it will be addedd
+                    else:  # The layer does not exist, thus it will be addedd
                         QgsProject.instance().addMapLayer(rlayer, False)  # Add the raster layer without showing it (False)
                         mygroup = root.findGroup("Nib-prosjekt")          # Get the group named "Nib-prosjekt"
                         mygroup.addLayer(rlayer)                          # Add the layer to this group
@@ -708,14 +707,14 @@ class getnib:
 
             # Current working directory will be set as destination folder for project lists
             cwd = os.getcwd()  # Get current working directory
-            # self.iface.messageBar().pushMessage("Info", "katalogen er:" +str(cwd), level=Qgis.Info, duration=3)
+            # self.iface.messageBar().pushMessage("Info", "Folder is:" +str(cwd), level=Qgis.Info, duration=3)
 
             if self.dlg.checkBox_sort.isChecked():
-                nib_liste = sorted(nib_liste)   # sort the nib_liste alphabetically
+                nib_liste = sorted(nib_liste)   # Sort the nib_liste alphabetically
 
             if self.dlg.checkBox_savelist.isChecked():
                 if self.dlg.radioButton_btwyears.isChecked():
-                    for y in years:  # years list is created above and contain all years from start to end year
+                    for y in years:  # Year-list is created above and contain all years from start to end year
                         # Delete files if existing
                         fn = str(cwd)+"\\OF_"+str(y)+".txt"
                         if os.path.isfile(fn):
@@ -725,7 +724,7 @@ class getnib:
                                 if year in n.split():
                                     if y == year:
                                         with open(str(cwd)+'\\OF_'+str(year)+'.txt','a',encoding='utf-8') as f:  # a = append to textfile
-                                            f.write(str(n)+'\n')   # write the OF-project for the specific year to the textfile
+                                            f.write(str(n)+'\n')   # Write the OF-project(s) for the specific year to the textfile
                 else:
                     # Delete file if existing
                     fn = str(cwd)+"\\OF_all.txt"
@@ -733,6 +732,6 @@ class getnib:
                         os.remove(fn) 
                     with open(str(cwd)+'\\OF_all.txt','w',encoding='utf-8') as f:  # w = write - will overwrite any existing content https://www.w3schools.com/python/python_file_write.asp
                        for n in nib_liste:
-                           f.write(str(n)+'\n')        # write the all OF-projects to the textfile
+                           f.write(str(n)+'\n')        # Write all OF-projects to the textfile
                 # Show message
                 self.iface.messageBar().pushMessage("Success", "List with Nib-projects saved to file", level=Qgis.Success, duration=3)
-- 
GitLab