Lattitude Longitude Mapping Trouble

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 10
Accepted Solution

Lattitude Longitude Mapping Trouble

Hi.

I'm interested in building a custom geographic map of the regions used wthin the UK for our business.

I know all of the postcode areas that make up each of the the regions. I have also found a file on the net that shows the longitude and lattitude of each postcode district (IE AB10, SA17 etc) in the UK.

But the lattitude and longitude in this file, which is compatible with google maps etc doesn't match with the UK map file in SAS.

The lattitude and longitude in SAS has 10 decimal places, which i can't see documented anywhere else. The most tends to be 8 decimal places whcih gives an accuracy of 1.11mm!

if you need any more information please ask.

Thanks.


Accepted Solutions
Solution
‎02-14-2013 12:21 PM
Trusted Advisor
Posts: 1,300

Re: Lattitude Longitude Mapping Trouble

get the shapefile:

http://www.sharegeo.ac.uk/handle/10672/51

/* Defining our .shp file as a map in SAS */

proc mapimport datafile="/path/to/gb_pca_2010.shp" out=mymap; run;

/* a list of some starbucks locations by postal code */

data starbucks;

length pc $ 254 ;

input pc & $;

pc2=compress(substr(pc,1,2),,'d');

cards;

LA1 1HZ

PR2 5PZ

FY3 8LL

FY1 4HU

PR1 6UY

PR4 2PR

PR1 8HL

PR5 4AW

BB1 2EE

PR8 1PF

PR7 5LR

PR7 5LR

BL6 5UZ

BL6 5UZ

BL6 6JA

WN5 0PU

CA10 2DW

CA10 2DW

WN1 1PE

BL1 2AR

BL9 7BQ

OL11 3PT

CA10 2DW

WA10 6DQ

CH45 2HZ

M17 8EH

M41 7ZA

M17 8BL

WA5 3AX

M8 8EP

WA5 7YA

L6 1BA

BD1 1HY

M4 3AQ

M2 7EF

M4 3AB

M4 3ES

M3 3WR

M3 3HN

M2 4EN

M1 1LZ

L3 9BS

M2 5PB

M1 4BD

L3 5UG

M17 8EH

M1 3GB

L1 4DS

L3 1DG

;

run;

proc sql;

create table mydata as

select pc2 as label,count(*) as zzz

from starbucks

group by pc2;

quit;

proc gmap data=mydata map=mymap all;

id label;

choro zzz / range;

run;

quit;

/* Postal code reference data (not used):

AB Aberdeen

AL St Albans

B Birmingham

BA Bath

BB Blackburn

BD Bradford

BH Bournemouth

BL Bolton

BN Brighton

BR Bromley

BS Bristol

BT Belfast

CA Carlisle

CB Cambridge

CF Cardiff

CH Chester

CM Chelmsford

CO Colchester

CR Croydon

CT Canterbury

CV Coventry

CW Crewe

DA Dartford

DD Dundee

DE Derby

DG Dumfries

DH Durham

DL Darlington

DN Doncaster

DT Dorchester

DY Dudley

E London E

EC London EC

EH Edinburgh

EN Enfield

EX Exeter

FK Falkirk

FY Fylde

G Glasgow

GL Gloucester

GU Guildford

HA Harrow

HD Huddersfield

HG Harrogate

HP Hemel Hempstead

HR Hereford

HS Outer Hebrides

HU Hull

HX Halifax

IG Ilford

IP Ipswich

IV Inverness

KA Kilmarnock

KT Kingston upon Thames

KW Kirkwall

KY Kirkcaldy

L Liverpool

LA Lancaster

LD Llandrindod Wells

LE Leicester

LL Llandudno

LN Lincoln

LS Leeds

LU Luton

M Manchester

ME Medway

MK Milton Keynes

ML Motherwell

N London N

NE Newcastle upon Tyne

NG Nottingham

NN Northampton

NP Newport

NR Norwich

NW London NW

OL Oldham

OX Oxford

PA Paisley

PE Peterborough

PH Perth

PL Plymouth

PO Portsmouth

PR Preston

RG Reading

RH Redhill

RM Romford

S Sheffield

SA Swansea

SE London SE

SG Stevenage

SK Stockport

SL Slough

SM Sutton

SN Swindon

SO Southampton

SP Salisbury Plain

SR Sunderland

SS Southend-on-Sea

ST Stoke-on-Trent

SW London SW

SY Shrewsbury

TA Taunton

TD Teviotdale

TF Telford

TN Tonbridge

TQ Torquay

TR Truro

TS Teesside

TW Twickenham

UB Uxbridge

W London W

WA Warrington

WC London WC

WD Watford

WF Wakefield

WN Wigan

WR Worcester

WS Walsall

WV Wolverhampton

YO York

ZE Lerwick

GY Guernsey

JE Jersey

IM Isle of Man

*/

gmap2.png

View solution in original post


All Replies
Solution
‎02-14-2013 12:21 PM
Trusted Advisor
Posts: 1,300

Re: Lattitude Longitude Mapping Trouble

get the shapefile:

http://www.sharegeo.ac.uk/handle/10672/51

/* Defining our .shp file as a map in SAS */

proc mapimport datafile="/path/to/gb_pca_2010.shp" out=mymap; run;

/* a list of some starbucks locations by postal code */

data starbucks;

length pc $ 254 ;

input pc & $;

pc2=compress(substr(pc,1,2),,'d');

cards;

LA1 1HZ

PR2 5PZ

FY3 8LL

FY1 4HU

PR1 6UY

PR4 2PR

PR1 8HL

PR5 4AW

BB1 2EE

PR8 1PF

PR7 5LR

PR7 5LR

BL6 5UZ

BL6 5UZ

BL6 6JA

WN5 0PU

CA10 2DW

CA10 2DW

WN1 1PE

BL1 2AR

BL9 7BQ

OL11 3PT

CA10 2DW

WA10 6DQ

CH45 2HZ

M17 8EH

M41 7ZA

M17 8BL

WA5 3AX

M8 8EP

WA5 7YA

L6 1BA

BD1 1HY

M4 3AQ

M2 7EF

M4 3AB

M4 3ES

M3 3WR

M3 3HN

M2 4EN

M1 1LZ

L3 9BS

M2 5PB

M1 4BD

L3 5UG

M17 8EH

M1 3GB

L1 4DS

L3 1DG

;

run;

proc sql;

create table mydata as

select pc2 as label,count(*) as zzz

from starbucks

group by pc2;

quit;

proc gmap data=mydata map=mymap all;

id label;

choro zzz / range;

run;

quit;

/* Postal code reference data (not used):

AB Aberdeen

AL St Albans

B Birmingham

BA Bath

BB Blackburn

BD Bradford

BH Bournemouth

BL Bolton

BN Brighton

BR Bromley

BS Bristol

BT Belfast

CA Carlisle

CB Cambridge

CF Cardiff

CH Chester

CM Chelmsford

CO Colchester

CR Croydon

CT Canterbury

CV Coventry

CW Crewe

DA Dartford

DD Dundee

DE Derby

DG Dumfries

DH Durham

DL Darlington

DN Doncaster

DT Dorchester

DY Dudley

E London E

EC London EC

EH Edinburgh

EN Enfield

EX Exeter

FK Falkirk

FY Fylde

G Glasgow

GL Gloucester

GU Guildford

HA Harrow

HD Huddersfield

HG Harrogate

HP Hemel Hempstead

HR Hereford

HS Outer Hebrides

HU Hull

HX Halifax

IG Ilford

IP Ipswich

IV Inverness

KA Kilmarnock

KT Kingston upon Thames

KW Kirkwall

KY Kirkcaldy

L Liverpool

LA Lancaster

LD Llandrindod Wells

LE Leicester

LL Llandudno

LN Lincoln

LS Leeds

LU Luton

M Manchester

ME Medway

MK Milton Keynes

ML Motherwell

N London N

NE Newcastle upon Tyne

NG Nottingham

NN Northampton

NP Newport

NR Norwich

NW London NW

OL Oldham

OX Oxford

PA Paisley

PE Peterborough

PH Perth

PL Plymouth

PO Portsmouth

PR Preston

RG Reading

RH Redhill

RM Romford

S Sheffield

SA Swansea

SE London SE

SG Stevenage

SK Stockport

SL Slough

SM Sutton

SN Swindon

SO Southampton

SP Salisbury Plain

SR Sunderland

SS Southend-on-Sea

ST Stoke-on-Trent

SW London SW

SY Shrewsbury

TA Taunton

TD Teviotdale

TF Telford

TN Tonbridge

TQ Torquay

TR Truro

TS Teesside

TW Twickenham

UB Uxbridge

W London W

WA Warrington

WC London WC

WD Watford

WF Wakefield

WN Wigan

WR Worcester

WS Walsall

WV Wolverhampton

YO York

ZE Lerwick

GY Guernsey

JE Jersey

IM Isle of Man

*/

gmap2.png

Occasional Contributor
Posts: 10

Re: Lattitude Longitude Mapping Trouble

Hi FriedEgg - Thanks for accepting my follow request and for providing the information above. Great and really helped millions.

It works great but i've just discovered that the level of geography is at postcode district level (ie SA18, KT6) as opposed to just postcode area (SA, KT)

Do you have any idea where i could get the more detailed shapefile?

Reeza - thanks for your help too.

I've already started to look in to the GREMOVE function to aggregate the segments into custom segments and remove the internal boundaries.

I just need a shapefile for postcode districts now!

Super User
Posts: 17,912

Re: Lattitude Longitude Mapping Trouble

FYI

Shapefiles are used in GIS programs and SAS uses them as well.

Google typically uses KML files. You can go between the different file types, but its easier once you know what you have specifically.

AFAIK, SAS works easiest with shape files. You can get KML files in but it took a bit of work the last time I tried it, but that was 5 years ago Smiley Happy

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 370 views
  • 4 likes
  • 3 in conversation