0

I'm trying to create a Python function to recognise which coordinate conversion to execute based on the last part of the filename - either BNG for British National Grid or ```IG`` for Irish Grid.

The uploaded file is in CSV format and the filename is extracted and broken up using:

                base_filename = os.path.basename(key)
                filename, extension = os.path.splitext(base_filename)
                device_parts = filename.split("_")
                self.device_name = device_parts[1]
                self.device_type = device_parts[2]

The filename used is always either test_data_BNG or test_data_IG

In order to convert the coordinates, I have tried the following code:


                if self.device_type == 'BNG':
                    inProj = Proj(init='epsg:27700') # British National Grid
                    outProj = Proj(init='epsg:4326') # WGS84
                    x1, y1 = row[1], row[2]  # easting, northing
                    x2, y2 = transform(inProj, outProj, x1, y1)
                    row[1], row[2] = y2, x2
                else:
                    inProj = Proj(init='epsg:29903') # Irish Grid
                    outProj = Proj(init='epsg:4326') # WGS84
                    x1, y1 = row[1], row[2]  # easting, northing
                    x2, y2 = transform(inProj, outProj, x1, y1)
                    row[1], row[2] = y2, x2
                
                        
                    json_doc = {}

But I get an "input must be an array, list, tuple or scalar" error.

How can I get python to convert to the correct coordinate system based on the end of the filename?

3
  • Did you try with Proj('epsg:4326')? – ThomasG77 Jun 15 at 9:47
  • @ThomasG77 yes I tried this too, but then got the error b'projection not named' – gues_505 Jun 15 at 9:55
  • Doing first import pyproj. Output of pyproj.__proj_version__ (version of proj)? Output of pyproj.__version__ (version of pyproj)? – ThomasG77 Jun 15 at 9:59
0

Figured it out! The code was reading the column names easting and northing, which is why it was throwing me the error. Instead I had to skip over the first line by using

   line_count += 1
else:
   if self.device_type == 'BNG':
1
  • Congrats. Never easy to be stuck but so much happy when found "the" solution ;) – ThomasG77 Jun 15 at 12:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.