Charpzy Posted December 6, 2022 Posted December 6, 2022 I'm looking to make a script in CAD which will return a National Grid Reference from and input Postcode For example User input: AL1 1BY Returns: TL 14584 06989 I've got a CSV from OS "CodePoint - Open" which supplies the Postcode, Easting, Northing, Lat & Long that can be used to grab part of the grid reference, but getting the first 2 letter "TL" is the main issue as the csv doesn't provide this and I'm not sure on how this is calculated. I've thought about making multiple CSVs (AL.csv, DN.csv, SL.csv...) with the postcodes in linking the Grid Reference to for example AL.csv AL1 1BY TL 14584 06989 AL1 1DQ TL 14524 06737 But would this cause issues with speed reading upwards of 10,000+ lines? I've also wondered if its possible to implement an API call with AutoLisp to use a postcode to NGR code but this isn't something I've done before or know if its possible? Quote
devitg Posted December 6, 2022 Posted December 6, 2022 10 minutes ago, Charpzy said: I'm looking to make a script in CAD which will return a National Grid Reference from and input Postcode For example User input: AL1 1BY Returns: TL 14584 06989 I've got a CSV from OS "CodePoint - Open" which supplies the Postcode, Easting, Northing, Lat & Long that can be used to grab part of the grid reference, but getting the first 2 letter "TL" is the main issue as the csv doesn't provide this and I'm not sure on how this is calculated. I've thought about making multiple CSVs (AL.csv, DN.csv, SL.csv...) with the postcodes in linking the Grid Reference to for example AL.csv . TL 14584 06989 AL1 1DQ TL 14524 06737 But would this cause issues with speed reading upwards of 10,000+ lines? I've also wondered if its possible to implement an API call with AutoLisp to use a postcode to NGR code but this isn't something I've done before or know if its possible? Please upload the CSv and the DWG where you will apply the LISP . as I can see , it seem to be at England. Quote
Charpzy Posted December 6, 2022 Author Posted December 6, 2022 I don't have a specific DWG where this will be used, it will just be used across multiple files in general - yeah all these postcodes are in England I've got multiple CSV files all in this format, but title different with different area in, for example AB.csv, AL.csv, HS.csv, SL.csv etc to help reduce the total size of the file CSV: HS.csv 15 minutes ago, devitg said: Please upload the CSv and the DWG where you will apply the LISP . as I can see , it seem to be at England. Quote
Steven P Posted December 6, 2022 Posted December 6, 2022 Does your CSV file give you just the reference in the (for example) 100km x 100km 'TL' square and nothing else or does it also give you the the km reference from the national grid reference point (a point just west of Lands end) If you have the full X and Y values then all you need to do is work out which square you are refering to, there are 125 options so a look up table is possible, perhaps dotted pairs with the lower left corner of the letters and the letters If you don't have the full reference and only say, the reference within each 100km square then you are going to need to do a bit of maths and work it out from the lattitude and longitude, then do a look up table to get the letters you want. So what is the output from the CSV file? for example 14584 06989 or 514584 206989 Are you able to post the CSV file so I can see what it gives you? Quote
Steven P Posted December 6, 2022 Posted December 6, 2022 Missed your post with the CSV file, you only have 5 letter to worry about... should be easy@ NA: 000000 900000 NB: 100000 900000 NF: 000000 800000 NG: 100000 800000 NL: 000000 700000 So look up your letters from above and add these numbers to the eastings and northings. I used Grid reference finder to get the grid references, you can do the same for more, say looking for say, SW000000 and copy the result Quote
Charpzy Posted December 6, 2022 Author Posted December 6, 2022 there is more than one csv file. there is about 115 csv files with all the UK postcodes, some csv files upto 40,000 rows of postcodes getting the righ csv file is fine, but its the fact there is so many rows, will it have a heavy impact on the speed of the script running if it needs to get through 40,000 rows potentially and what would the best way of going through them all be? 4 hours ago, Steven P said: Missed your post with the CSV file, you only have 5 letter to worry about... should be easy@ NA: 000000 900000 NB: 100000 900000 NF: 000000 800000 NG: 100000 800000 NL: 000000 700000 So look up your letters from above and add these numbers to the eastings and northings. I used Grid reference finder to get the grid references, you can do the same for more, say looking for say, SW000000 and copy the result Quote
abra-CAD-abra Posted December 7, 2022 Posted December 7, 2022 Refer to the thread below regarding (multiple) association lists, different ways to extract the information you want and, more importantly, performance considerations: https://stackoverflow.com/questions/36852628/autolisp-entity-data-retrieval/48857993#48857993 Quote
BIGAL Posted December 7, 2022 Posted December 7, 2022 (edited) Ok 1st csv file supplied is a Excel file not csv, so resaved as a new csv. Ok read 38921 lines it was basicly instant. So should be able to search full code list. Ps copied sample 40 times. Edited December 7, 2022 by BIGAL Quote
eldon Posted December 7, 2022 Posted December 7, 2022 19 hours ago, Charpzy said: I'm looking to make a script in CAD which will return a National Grid Reference from and input Postcode For example User input: AL1 1BY Returns: TL 14584 06989 I've got a CSV from OS "CodePoint - Open" which supplies the Postcode, Easting, Northing, Lat & Long that can be used to grab part of the grid reference, but getting the first 2 letter "TL" is the main issue as the csv doesn't provide this and I'm not sure on how this is calculated. ....... The CSV from OS CodePoint does not show Lat & Long. The OS grid is a Transverse Mercator one which only has Eastings and Northings. The "TL" is a reference to the grids. The first character comes from the 500 kilometre grid reference and the second character comes from the 100 kilometre grid reference. I looked on the OS web site for a table that gives the actual numbers, and could not find one - I may have been looking in the wrong place. However, I thought to make a csv table which contains all the references. Some of the 100 km squares are water only, so contain no OS data. Do check if you can because this is all my own work! HL,0,1200000 HM,100000,1200000 HN,200000,1200000 HO,300000,1200000 HP,400000,1200000 JL,500000,1200000 HQ,0,1100000 HR,100000,1100000 HS,200000,1100000 HT,300000,1100000 HU,400000,1100000 JQ,500000,1100000 HV,0,1000000 HW,100000,1000000 HX,200000,1000000 HY,300000,1000000 HZ,400000,1000000 JV,500000,1000000 NA,0,900000 NB,100000,900000 NC,200000,900000 ND,300000,900000 NE,400000,900000 OA,500000,900000 NF,0,800000 NG,100000,800000 NH,200000,800000 NJ,300000,800000 NK,400000,800000 OF,500000,800000 NL,0,700000 NM,100000,700000 NN,200000,700000 NO,300000,700000 NP,400000,700000 OL,500000,700000 NQ,0,600000 NR,100000,600000 NS,200000,600000 NT,300000,600000 NU,400000,600000 OQ,500000,600000 NW,100000,500000 NX,200000,500000 NY,300000,500000 NZ,400000,500000 OV,500000,500000 OW,600000,500000 SB,100000,400000 SC,200000,400000 SD,300000,400000 SE,400000,400000 TA,500000,400000 TB,600000,400000 SG,100000,300000 SH,200000,300000 SJ,300000,300000 SK,400000,300000 TF,500000,300000 TG,600000,300000 SM,100000,200000 SN,200000,200000 SO,300000,200000 SP,400000,200000 TL,500000,200000 TM,600000,200000 SQ,0,100000 SR,100000,100000 SS,200000,100000 ST,300000,100000 SU,400000,100000 TQ,500000,100000 TR,600000,100000 SV,0,0 SW,100000,0 SX,200000,0 SY,300000,0 SZ,400000,0 TV,500000,0 1 Quote
Charpzy Posted December 7, 2022 Author Posted December 7, 2022 i've been struggling to find info around this but csv you've made has help understand how its broken down, thank you! in the CSV files ive been making im storing each postcode along with its NGR next to it, using a batch converter online so the files im making have a format of AL1 1BY,TL,14584,06989 AL1 1DQ,TL,14524,06737 I'm breaking this each csv file down into the start of the postcode similar to how its done with the OS Code Points (AL, DN, SL etc...), this way i can avoid doing any calculation within the script (probably a backwards way of doing it) from this if it was to use it to grab a mapping piece their master mapping id just have to reformat the NGR to something similar to TL10NE 10 minutes ago, eldon said: The CSV from OS CodePoint does not show Lat & Long. The OS grid is a Transverse Mercator one which only has Eastings and Northings. The "TL" is a reference to the grids. The first character comes from the 500 kilometre grid reference and the second character comes from the 100 kilometre grid reference. I looked on the OS web site for a table that gives the actual numbers, and could not find one - I may have been looking in the wrong place. However, I thought to make a csv table which contains all the references. Some of the 100 km squares are water only, so contain no OS data. Do check if you can because this is all my own work! HL,0,1200000 HM,100000,1200000 HN,200000,1200000 HO,300000,1200000 HP,400000,1200000 JL,500000,1200000 HQ,0,1100000 HR,100000,1100000 HS,200000,1100000 HT,300000,1100000 HU,400000,1100000 JQ,500000,1100000 HV,0,1000000 HW,100000,1000000 HX,200000,1000000 HY,300000,1000000 HZ,400000,1000000 JV,500000,1000000 NA,0,900000 NB,100000,900000 NC,200000,900000 ND,300000,900000 NE,400000,900000 OA,500000,900000 NF,0,800000 NG,100000,800000 NH,200000,800000 NJ,300000,800000 NK,400000,800000 OF,500000,800000 NL,0,700000 NM,100000,700000 NN,200000,700000 NO,300000,700000 NP,400000,700000 OL,500000,700000 NQ,0,600000 NR,100000,600000 NS,200000,600000 NT,300000,600000 NU,400000,600000 OQ,500000,600000 NW,100000,500000 NX,200000,500000 NY,300000,500000 NZ,400000,500000 OV,500000,500000 OW,600000,500000 SB,100000,400000 SC,200000,400000 SD,300000,400000 SE,400000,400000 TA,500000,400000 TB,600000,400000 SG,100000,300000 SH,200000,300000 SJ,300000,300000 SK,400000,300000 TF,500000,300000 TG,600000,300000 SM,100000,200000 SN,200000,200000 SO,300000,200000 SP,400000,200000 TL,500000,200000 TM,600000,200000 SQ,0,100000 SR,100000,100000 SS,200000,100000 ST,300000,100000 SU,400000,100000 TQ,500000,100000 TR,600000,100000 SV,0,0 SW,100000,0 SX,200000,0 SY,300000,0 SZ,400000,0 TV,500000,0 Quote
devitg Posted December 7, 2022 Posted December 7, 2022 I downloaded the AL postcode , of course is huge . I strip the header and 2 first PC. It have all data , 53 columns, and 7779 rows + head PostcodeIn Use?LatitudeLongitudeEastingNorthingGrid RefCounty AL1 1AGYes51.74529-0.328628515487206498TL154064Hertfordshire AL1 1AJYes51.744498-0.328599515491206410TL154064Hertfordshire AL postcodes - header and first 2 .csv AL postcodes.csv 1 Quote
Steven P Posted December 7, 2022 Posted December 7, 2022 7 minutes ago, devitg said: I downloaded the AL postcode , of course is huge . For the OP, do you want all the UK postcodes by the way? Thinking of course that this is going to be a very big file, so only save what you need, 1.7 million postcodes makes for a very large file. If you don't need latitude and longitude then removing them will save just under half the file size? Might be that if you can programme the conversion it would almost be as quick to calculate them if needed from the grid reference as a look up would be to find them. Quote
Charpzy Posted December 7, 2022 Author Posted December 7, 2022 Where abouts did you download this from? this file would be much more useful than the ones i currently have 34 minutes ago, devitg said: I downloaded the AL postcode , of course is huge . I strip the header and 2 first PC. It have all data , 53 columns, and 7779 rows + head PostcodeIn Use?LatitudeLongitudeEastingNorthingGrid RefCounty AL1 1AGYes51.74529-0.328628515487206498TL154064Hertfordshire AL1 1AJYes51.744498-0.328599515491206410TL154064Hertfordshire AL postcodes - header and first 2 .csv 2.47 kB · 0 downloads AL postcodes.csv 5.93 MB · 1 download Quote
eldon Posted December 7, 2022 Posted December 7, 2022 When Latitude and Longitude are mentioned with the Ordnance Survey, I always wonder whether it is referenced to the Prime Meridian, the "Golden Nail" at Greenwich, or to the GPS Meridian which is 103m further east? Quote
devitg Posted December 7, 2022 Posted December 7, 2022 3 hours ago, Charpzy said: Where abouts did you download this from? this file would be much more useful than the ones i currently have I did from England POSTCODE up to Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.