PRO postcode_boundaries_diff ; A.D. COOL 19-JUL-2007 CLOSE,/ALL DEVICE, RETAIN=2, DECOMPOSED=0 ;LOAD_COLOURS,'fms rainbow' LOAD_COLOURS,'BLUE-RED' WINDOW,xs = 500,YS = 650,/FREE !P.POSITION=[0.1,0.18,0.9,0.95] ; Open population file dir = 'c:\Andrew\ASSA\Dark Sky\' ;pop_file = dir + 'pop_by_postcode_2006.txt' pop_file_2001 = dir + 'pop_by_postcode_2001.txt' pop_file_2006 = dir + 'pop_by_postcode_2006.txt' N_lines_2001 = File_Lines(pop_file_2001) N_lines_2006 = File_Lines(pop_file_2006) pop_data_2001 = strarr(N_Lines_2001) pop_data_2006 = strarr(N_Lines_2006) OPENR,lun,pop_file_2001,/get READF,lun,pop_data_2001 CLOSE,lun pop_data_2001 = strcompress(pop_data_2001) OPENR,lun,pop_file_2006,/get READF,lun,pop_data_2006 CLOSE,lun pop_data_2006 = strcompress(pop_data_2006) ;print,'N_lines_2001 = ',N_lines_2001 ;print,'N_lines_2006 = ',N_lines_2006 ; Cater for 5000-5999 = 1000 postcodes max ; pos 0 = postcode ; pos 1 = 1996, pos 2 = 2001, pos 3 = 2006 matched_pop_by_postcode = LONARR(1000,4) matched_pop_by_postcode(*,0) = -999 for i = 0,N_lines_2001-1 do begin post_code_2001 = long(strmid(pop_data_2001(i),0,4)) ; print,'Testing PC ', post_code_2001 for j = 0,N_lines_2006-1 do begin post_code_2006 = long(strmid(pop_data_2006(j),0,4)) IF post_code_2006 EQ post_code_2001 THEN BEGIN population_2001 = long(strmid(pop_data_2001(i),5,10)) population_2006 = long(strmid(pop_data_2006(j),5,10)) ; print,post_code_2001,post_code_2006, population_2001, population_2006, population_2006 - population_2001 matched_pop_by_postcode(post_code_2001-5000,0) = post_code_2001 matched_pop_by_postcode(post_code_2001-5000,1) = -999 ; 1996 data matched_pop_by_postcode(post_code_2001-5000,2) = population_2001 ; 2001 data matched_pop_by_postcode(post_code_2001-5000,3) = population_2006 ; 2006 data ENDIF END end OPENW,lun,dir + 'matched_pop_by_postcode.txt',/GET FOR i = 0,999 DO begin PRINTF,lun,matched_pop_by_postcode(i,*),format='(4(I8))' END CLOSE,lun !P.BACKGROUND = !COLOUR.WHITE !P.COLOR = !COLOUR.BLACK ; Set up map to plot Shapefile on ;MAP_SET, -34, 138, 0, /ISOTROPIC, $ ; /GRID, COLOR=black, $ ; LIMIT=[-38,132,-30,140.5] MAP_SET, -34.5, 138.5, 0, /ISOTROPIC, $ /GRID, COLOR=black, $ LIMIT=[-36,137,-33,140],title='SA Population Change by Postcode 2001->2006' ;MAP_SET, -34.5, 138.5, 0, /ISOTROPIC, $ ; /GRID, COLOR=black, $ ; LIMIT=[-38,133,-28,141.5] ; Fill the continent boundaries: ;MAP_CONTINENTS, /FILL_CONTINENTS, COLOR=!COLOUR.BROWN,/RSI,/COASTS MAP_CONTINENTS, /FILL_CONTINENTS, COLOR=!COLOUR.BROWN MAP_GRID,/BOX ; Overplot coastline data: ;MAP_CONTINENTS, /COASTS, COLOR=black ; Show national borders: ;MAP_CONTINENTS, /COUNTRIES, COLOR=black ;Open the states Shapefile in the examples directory myshape=OBJ_NEW('IDLffShape', 'c:\Andrew\ASSA\Dark Sky\Digital_Boundary_Data\postcode.shp') good_postcodes = where(matched_pop_by_postcode(*,0) NE -999) pop_diffs = matched_pop_by_postcode(good_postcodes,3) - matched_pop_by_postcode(good_postcodes,2) max_pop_diff = MAX(pop_diffs,MIN=min_pop_diff) print,'max_pop_diff = ',max_pop_diff,' min_pop_diff = ',min_pop_diff ;Get the number of entities so we can parse through them myshape->IDLffShape::GetProperty, N_ENTITIES=num_ent FOR x=1, (num_ent-1) DO BEGIN ;Get the Attributes for entity x attr = myshape->IDLffShape::GetAttributes(x) if x eq 1 then help,attr,/st index = where(matched_pop_by_postcode(*,0) EQ LONG(attr.ATTRIBUTE_1)) IF index NE -1 THEN BEGIN ;population = matched_pop_by_postcode(index,2) ; 2001 pop pop_diff = matched_pop_by_postcode(index,3) - matched_pop_by_postcode(index,2) ENDIF ELSE BEGIN pop_diff = 0 ENDELSE half_max_pop_diff = max_pop_Diff/2 ;Get entity ent=myshape->IDLffShape::GetEntity(x) ;Plot entity color = bytscl(half_max_pop_diff+pop_diff,min=0,max=max_pop_diff,top=!COLOUR.TOP) !P.COLOR = color lon_centre = ((ent.bounds(4) - ent.bounds(0)) / 2.0) + ent.bounds(0) lat_centre = ((ABS(ent.bounds(1)) - ABS( ent.bounds(5))) / 2.0) * (-1) + $ ent.bounds(5) POLYFILL, (*ent.vertices)[0,*], (*ent.vertices)[1,*] ;Clean-up of pointers myshape->IDLffShape::DestroyEntity, ent ENDFOR ;Close the Shapefile OBJ_DESTROY, myshape !P.COLOR = !COLOUR.BLACK ;Color_scale, $ ; MINVAL= min_pop_diff, $ ; INTERVAL=2000, $ ; TITLE='Change in Population from 2001 to 2006',$ ; XPOS=100,YPOS=80,BAR_LENGTH=300,$; ; /HORIZONTAL, $ ; MAJOR_TICKS = (max_pop_Diff-min_pop_diff)/ 2000 ,$ ; LABEL_COLOR= !COLOUR.BLACK,$; ; MAX_USEABLE_COL=!COLOUR.TOP Color_scale, $ MINVAL= -4000, $ INTERVAL=1000, $ TITLE='Change in Population from 2001 to 2006',$ XPOS=100,YPOS=80,BAR_LENGTH=300,$ /HORIZONTAL, $ /NOMINOR, $ MAJOR_TICKS = 8 ,$ LABEL_COLOR= !COLOUR.BLACK,$ MAX_USEABLE_COL=!COLOUR.TOP,$ CHARSIZE=0.8 XYOUTS, 250,10,'A.D. Cool July 2007',/DEVICE,ALIGN=0.5 END