Ejemplo n.º 1
0
        public PostCodeDataReader(string category, string postCodeFilePath, int leaKeyColumn, int wardKeyColumn, int nuts1KeyColumn, int constituencyKeyColumn,
                                  int lAKeyColumn, int countyKeyColumn, int postCode7Column, int postCode8Column, int eastingColumn, int northingColumn,
                                  string filepathLA, int lookupLAKeyColumn, int lookupLANameColumn,
                                  string filepathLEA, int lookupLEAKeyColumn, int lookupLEANameColumn,
                                  string filepathCty, int lookupCtyKeyColumn, int lookupCtyNameColumn,
                                  string filepathWard, int lookupWardKeyColumn, int lookupWardNameColumn,
                                  string filepathRegion, int lookupRegionKeyColumn, int lookupRegionNameColumn,
                                  string filepathConstituency, int lookupConstituencyKeyColumn, int lookupConstituencyNameColumn)
        {
            _filePath = postCodeFilePath;

            ReadLookUp("Constituency", filepathConstituency, lookupConstituencyKeyColumn, lookupConstituencyNameColumn);
            ReadLookUp("Ward", filepathWard, lookupWardKeyColumn, lookupWardNameColumn);
            ReadLookUp("Region", filepathRegion, lookupRegionKeyColumn, lookupRegionNameColumn);
            ReadLookUp("County", filepathCty, lookupCtyKeyColumn, lookupCtyNameColumn);
            ReadLookUp("LA", filepathLA, lookupLAKeyColumn, lookupLANameColumn);
            ReadLookUp("LEA", filepathLEA, lookupLEAKeyColumn, lookupLEANameColumn);

            _textReader            = File.OpenText(_filePath);
            _category              = category;
            _currentPostCodeRecord = new PostCode();
            _leaKeyColumn          = leaKeyColumn;
            _wardKeyColumn         = wardKeyColumn;
            _nuts1KeyColumn        = nuts1KeyColumn;
            _constituencyKeyColumn = constituencyKeyColumn;
            _lAKeyColumn           = lAKeyColumn;
            _countyKeyColumn       = countyKeyColumn;
            _postCode7Column       = postCode7Column;
            _postCode8Column       = postCode8Column;
            _eastingColumn         = eastingColumn;
            _northingColumn        = northingColumn;
            _fileLength            = _textReader.BaseStream.Length;
            currentPosition        = 0;
        }
Ejemplo n.º 2
0
        public bool Read()
        {
            string currentLine = null;

            if (_recordCount == 0)
            {
                //read the header row and ignore
                currentLine     = _textReader.ReadLine();
                currentPosition = _textReader.BaseStream.Position;
            }

            currentLine     = _textReader.ReadLine();
            currentPosition = _textReader.BaseStream.Position;
            if (_textReader.EndOfStream)
            {
                return(false);
            }
            else
            {
                string[] items = currentLine.Replace("\",\"", "|").Replace("\"", "").Split('|');
                _currentPostCodeRecord = new PostCode()
                {
                    ConstituencyID     = items[_constituencyKeyColumn],
                    County             = items[_countyKeyColumn],
                    Lad_Ua             = items[_lAKeyColumn],
                    Lea                = items[_leaKeyColumn],
                    Nuts1              = items[_nuts1KeyColumn],
                    Parl_Con           = items[_constituencyKeyColumn],
                    Ward               = items[_wardKeyColumn],
                    PostCode7          = items[_postCode7Column],
                    PostCode8          = items[_postCode8Column],
                    ConstituencyName   = ConstituencyLookUp.ContainsKey(items[_constituencyKeyColumn]) ?ConstituencyLookUp[items[_constituencyKeyColumn]] :null,
                    CountyName         = CountyLookUp.ContainsKey(items[_countyKeyColumn]) ? CountyLookUp[items[_countyKeyColumn]] : null,
                    LEAName            = LEALookUp.ContainsKey(items[_leaKeyColumn]) ? LEALookUp[items[_leaKeyColumn]] : null,
                    LocalAuthorityName = LALookUp.ContainsKey(items[_lAKeyColumn]) ? LALookUp[items[_lAKeyColumn]] : null,
                    RegionName         = RegionLookUp.ContainsKey(items[_nuts1KeyColumn]) ? RegionLookUp[items[_nuts1KeyColumn]] : null,
                    WardName           = WardLookUp.ContainsKey(items[_wardKeyColumn]) ? WardLookUp[items[_wardKeyColumn]] : null,
                    PostCodeCompressed = items[_postCode7Column].Replace(" ", ""),
                    Easting            = items[_eastingColumn],
                    Northinging        = items[_northingColumn]
                };
                if (_currentPostCodeRecord.CountyName == null)
                {
                    if (_currentPostCodeRecord.Lad_Ua != null && _currentPostCodeRecord.Lad_Ua.Length > 8)
                    {
                        int LAInt = Convert.ToInt32(_currentPostCodeRecord.Lad_Ua.Substring(2));
                        if (LAInt >= 9000001 && LAInt <= 9000033)
                        {
                            _currentPostCodeRecord.CountyName = "Greater London";
                        }
                        else if (LAInt >= 8000001 && LAInt <= 8000010)
                        {
                            _currentPostCodeRecord.CountyName = "Greater Manchester";
                        }
                        else if (LAInt >= 8000011 && LAInt <= 8000015)
                        {
                            _currentPostCodeRecord.CountyName = "Merseyside";
                        }
                        else if (LAInt >= 8000016 && LAInt <= 8000019)
                        {
                            _currentPostCodeRecord.CountyName = "South Yorkshire";
                        }
                        else if (LAInt >= 8000020 && LAInt <= 8000024)
                        {
                            _currentPostCodeRecord.CountyName = "Tyne and Wear";
                        }
                        else if (LAInt >= 8000025 && LAInt <= 8000031)
                        {
                            _currentPostCodeRecord.CountyName = "West Midlands";
                        }
                        else if (LAInt >= 8000032 && LAInt <= 8000036)
                        {
                            _currentPostCodeRecord.CountyName = "West Yorkshire";
                        }
                        else
                        {
                            switch (LAInt)
                            {
                            case 6000032:
                            case 6000055:
                            case 6000056:
                                _currentPostCodeRecord.CountyName = "Bedfordshire";
                                break;

                            case 6000036:
                            case 6000037:
                            case 6000038:
                            case 6000039:
                            case 6000040:
                            case 6000041:
                                _currentPostCodeRecord.CountyName = "Berkshire";
                                break;

                            case 6000023:
                                _currentPostCodeRecord.CountyName = "Bristol, City of";
                                break;

                            case 6000042:
                            case 7000004:
                                _currentPostCodeRecord.CountyName = "Buckinghamshire";
                                break;

                            case 6000031:
                                _currentPostCodeRecord.CountyName = "Cambridgeshire";
                                break;

                            case 6000006:
                            case 6000007:
                            case 6000049:
                            case 6000050:
                                _currentPostCodeRecord.CountyName = "Cheshire";
                                break;

                            case 6000052:
                            case 6000053:
                                _currentPostCodeRecord.CountyName = "Cornwall";
                                break;

                            case 6000015:
                                _currentPostCodeRecord.CountyName = "Derbyshire";
                                break;

                            case 6000026:
                            case 6000027:
                                _currentPostCodeRecord.CountyName = "Devon";
                                break;

                            case 6000028:
                            case 6000029:
                                _currentPostCodeRecord.CountyName = "Dorset";
                                break;

                            case 6000001:
                            case 6000004:
                            case 6000005:
                            case 6000047:
                                _currentPostCodeRecord.CountyName = "Durham";
                                break;

                            case 6000010:
                            case 6000011:
                                _currentPostCodeRecord.CountyName = "East Riding of Yorkshire";
                                break;

                            case 6000043:
                                _currentPostCodeRecord.CountyName = "East Sussex";
                                break;

                            case 6000033:
                            case 6000034:
                                _currentPostCodeRecord.CountyName = "Essex";
                                break;

                            case 6000025:
                                _currentPostCodeRecord.CountyName = "Gloucestershire";
                                break;

                            case 6000044:
                            case 6000045:
                                _currentPostCodeRecord.CountyName = "Hampshire";
                                break;

                            case 6000019:
                                _currentPostCodeRecord.CountyName = "Herefordshire";
                                break;

                            case 6000046:
                                _currentPostCodeRecord.CountyName = "Isle of Wight";
                                break;

                            case 6000035:
                                _currentPostCodeRecord.CountyName = "Kent";
                                break;

                            case 6000008:
                            case 6000009:
                                _currentPostCodeRecord.CountyName = "Lancashire";
                                break;

                            case 6000016:
                                _currentPostCodeRecord.CountyName = "Leicestershire";
                                break;

                            case 6000012:
                            case 6000013:
                                _currentPostCodeRecord.CountyName = "Lincolnshire";
                                break;

                            case 6000002:
                            case 6000003:
                            case 6000014:
                                _currentPostCodeRecord.CountyName = "North Yorkshire";
                                break;

                            case 6000048:
                                _currentPostCodeRecord.CountyName = "Northumberland";
                                break;

                            case 6000018:
                                _currentPostCodeRecord.CountyName = "Nottinghamshire";
                                break;

                            case 6000017:
                                _currentPostCodeRecord.CountyName = "Rutland";
                                break;

                            case 6000020:
                            case 6000051:
                                _currentPostCodeRecord.CountyName = "Shropshire";
                                break;

                            case 6000022:
                            case 6000024:
                                _currentPostCodeRecord.CountyName = "Somerset";
                                break;

                            case 6000021:
                                _currentPostCodeRecord.CountyName = "Staffordshire";
                                break;

                            case 6000030:
                            case 6000054:
                                _currentPostCodeRecord.CountyName = "Wiltshire";
                                break;
                            }
                            if (LAInt == 6000004)
                            {
                                //Stockton is split between north yorkshire and durham
                                //change the ny wards from durham
                                switch (_currentPostCodeRecord.Ward)
                                {
                                case "E05001538":
                                case "E05001539":
                                case "E05001540":
                                case "E05001548":
                                case "E05001550":
                                case "E05001552":
                                    _currentPostCodeRecord.CountyName = "North Yorkshire";
                                    break;
                                }
                            }
                        }
                    }
                }
                if (_currentPostCodeRecord.CountyName == null)
                {
                    if (_currentPostCodeRecord.PostCode7.Substring(0, 2) == "GY")
                    {
                        _currentPostCodeRecord.CountyName = "Guernsey";
                    }
                    else if (_currentPostCodeRecord.PostCode7.Substring(0, 2) == "IM")
                    {
                        _currentPostCodeRecord.CountyName = "Isle of Man";
                    }
                    else if (_currentPostCodeRecord.PostCode7.Substring(0, 2) == "JE")
                    {
                        _currentPostCodeRecord.CountyName = "Jersey";
                    }
                }
            }
            _recordCount++;
            return(true);
        }