Skip to content

A PowerShell wrapper for the postcodes.io API used for working with UK postcode data

License

Notifications You must be signed in to change notification settings

isjwuk/posh-postcodes.io

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

posh-postcodes.io

A PowerShell wrapper for the postcodes.io API used for working with UK postcode data

PowerShell

Postcodes.io

Postcodes.io is an open sourced project maintained by Ideal Postcodes. It is a free resource, allowing developers to search, reverse geocode and extract UK postcode and associated data.

Functions

The following functions are included in this module.

Name Description
Get-MatchingPostcode Submit a postcode query and receive a complete list of postcode matches and all associated postcode data.
Get-NearestOutwardCode Returns nearest outcodes for a given longitude and latitude or a given Outcode
Get-NearestPostcode Returns nearest postcodes for a given longitude and latitude, or a given postcode.
Get-OutwardCode Geolocation data for the centroid of the outward code specified.
Get-PostcodeInfo Returns a single postcode entity for a given postcode.
Get-RandomPostcode Returns a random postcode and all available data for that postcode.
Test-Postcode Convenience method to validate a postcode.

Example Usage

Install and Import the module

The module can be installed from the PowerShell Gallery

Install-Module Posh-Postcodes.io 
Import-Module Posh-Postcodes.io

Lookup a Postcode

The following example will return information associated with the postcode L4 0TH.

Get-PostcodeInfo -Postcode 'L4 0TH'

postcode                        : L4 0TH
quality                         : 1
eastings                        : 336209
northings                       : 393151
country                         : England
nhs_ha                          : North West
longitude                       : -2.961584
latitude                        : 53.431267
european_electoral_region       : North West
primary_care_trust              : Liverpool
region                          : North West
lsoa                            : Liverpool 018A
msoa                            : Liverpool 018
incode                          : 0TH
outcode                         : L4
parliamentary_constituency      : Liverpool, Walton
parliamentary_constituency_2024 : Liverpool Riverside
admin_district                  : Liverpool
parish                          : Liverpool, unparished area
admin_county                    :
date_of_introduction            : 198001
admin_ward                      : Anfield
ced                             :
ccg                             : NHS Cheshire and Merseyside
nuts                            : Liverpool
pfa                             : Merseyside
codes                           : @{admin_district=E08000012;
                                    admin_county=E99999999; 
                                    admin_ward=E05015279;
                                    parish=E43000166;
                                    parliamentary_constituency=E14000794;
                                    parliamentary_constituency_2024=E14001338;
                                    ccg=E38000101;
                                    ccg_id=99A;
                                    ced=E99999999;
                                    nuts=TLD72;
                                    lsoa=E01006542;
                                    msoa=E02001364;
                                    lau2=E08000012;
                                    pfa=E23000004}

Get-Help

Full descriptions and examples are available through Get-Help, for example

Get-Help Get-PostcodeInfo -Examples
Get-Help Test-Postcode
Get-Help Get-NearestPostcode -ShowWindow

Testing

Pester is used for unit testing.

Invoke-Pester .\tests\*.Tests.ps1 -Output detailed

PSScriptAnalyzer is used for identifying common issues

Invoke-ScriptAnalyzer -Path .\Posh-Postcodes.io.psd1
Invoke-ScriptAnalyzer -Path .\methods\*.psm1

About

A PowerShell wrapper for the postcodes.io API used for working with UK postcode data

Resources

License

Stars

Watchers

Forks

Packages

No packages published