將州縣合併到地區堪薩斯州有 105 個縣,這些縣被合併為 16 個衛生準備區域。 我如何使用 US-County-Name.jmp 和關聯的 XY 文件執行此操作?
堪薩斯州的 16 個地區在以下鏈接中定義: https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246
任何幫助,將不勝感激。
圖形回复:將州縣與地區合併有人可能有更簡單的方法,但我已經做過這樣的事情並且知道它會起作用,儘管它需要一些努力。首先,我會下載您鏈接的那個區域表,然後使用逗號作為分隔符分隔縣(我通常在這個階段使用 Excel,儘管它可以在 JMP 中完成)。然後我將通過堆疊縣來重組該表,以便有 2 列,一列與區域相關,另一列顯示與每個區域相關的縣(但作為單個列)。然後您可以確保 US-County-Name.jmp 文件具有與您創建的文件相同的縣名格式(例如在縣名中添加“County”一詞 - 確保它與縣名在地圖文件中查找)。然後將地圖角色分配給您創建的 County 列,使用該文件中正確命名的列將其鏈接到 US-County-Name.jmp 文件。由於您的新文件將有一個 Region 列,您可以在 Graph Builder 中使用它來覆蓋或著色地圖上的區域。
我知道這是勞動密集型的,但這是我過去這樣做的唯一方法。
回复:將州縣與地區合併你好@jkeighley ,
下面我有一些代碼需要調試,但應該是一個可靠的起點。 任何其他可以改進以下腳本的腳本編寫者?我敢肯定還有很多需要改進的地方!
- 打開美國縣名.jmp & p稍後搜索的代表,將州和縣分成新的列
- 下載並打開上面鏈接的 PDF,然後導入第一頁上的表格
- 注意 - 在本地機器上運行之前一定要檢查腳本! 此腳本從 Internet 下載 PDF。檢查第 15 行,URL() 參數中的 URL 字符串
- Assigns 創建區域內區域(鍵)和縣(值)的關聯數組 (AA) <-- 循環不工作
- 我是正則表達式的初學者,所以正則表達式被破壞了
- 縣列表作為單個字符串返回,正則表達式應該分開
- 縣字符串示例:“Barton, McPherson, Pawnee, Rice, Saline, Stafford”
- 需要是字符串列表:{ "Barton", "McPherson", "Pawnee", "Rice", "Saline", "Stafford" }
- 在 US-County-Name.jmp 中...
- 使用一些嵌套循環來查找 State = KS 和其他條件的行
- 當State = KS的一行,查看country,然後通過搜索AA找到它對應的region,然後將county(value)賦值給region(key)
- 將 Region(鍵)保存到行的 Region 列
names default to here(1);
clear log();
/* This block opens & readies US-County-Name.jmp */
countylist = open( "C:/Program Files/SAS/JMP/17/Maps/US-County-Name.jmp" );
countylist << New column( "County", formula( Word( 1, :Full Name Short, " " ) ) );
countylist << New column( "Region", Character );
countylist << New column( "State", formula( Word( -1, :Full Name Short, " " ) ) );
/* This block DOWNLOADS & opens the downloaded PDF & imports first page table */
request = New HTTP Request(
URL(
"https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246"
),
Method( "Get" )
);
file = request << Download( "$TEMP/Kansas Health Preparedness Regions.pdf", "replace", "show_progress" );
dt = Open( file,
PDF Tables(
Table(
table name(
"Kansas Health Preparedness Regions and Map Page(1) Table(1)"
),
add rows( page( 1 ), Rect( 0.4789, 1.0156, 10.5211, 7.8894 ) )
)
)
);
// For some reason, dt imports as a 1 item list of data tables
// Reassigns dt to a "Table" data type for further processing
dt = dt[1];
// Deletes empty rows in imported PDF table
dt << Select where( Is Missing( :Region ) ) << Delete Rows;
// Starting AA for data storage
region = Associative array();
// Stores region / county list data in AA
for( i = 1, i <= N Rows( dt ), i++,
templist = {};
temphold = dt:Counties Included[i];
tempitems = N Items( words( dt:Counties Included[i], "," ) );
show(tempitems);
// Breaks apart country string into individual counties and adds them to templist
for( n = 1, n <= tempitems, n++,
iteration = eval( eval expr( expr( eval insert( "\^n^" ) ) ) );
// Fix me! This is broken
insert into( templist, regex( "^\!"(\w*),*\!"$", iteration ) );
);
// Save the list as the value pair (county list, list of strings) to the respective key
region[ dt:region[i] ] = templist
);
// The region & county list is now stored in an AA!
//print( region );
/* This block will use data in AA to assign region to respective county in US-County-Name.jmp */
for( k = 1, k <= N rows( countylist ), k++,
// Condition where state = Kansas
try( if( countylist:State[k] == "KS",
// Iterates through AA keys (regions)
for( m = 1, m <= N Items( kskeys ), m++,
// Creates list of counties within m region
tempvals = region[m];
// Checks if Count present, then assigns region to dt
if( contains( tempvals, countylist:County[k] ), // County is in m list
countylist:Region[k] = kskeys[m]
);
);
) ); // try --> if county not found in PDF stated counties, no region will be assigned
);
// Closes out pdf table, if needed
close( dt, "No Save" );
回复:將州縣與地區合併@jkeighley
我得到了下面的腳本來成功地將區域更新為美國縣名.jmp。 請注意,下面的腳本不會保存此文件,也不會修改關聯的 XY 文件。
names default to here(1);
clear log();
/* This block opens & readies US-County-Name.jmp */
countylist = open( "C:/Program Files/SAS/JMP/17/Maps/US-County-Name.jmp" );
countylist << New column( "County", formula( Word( 1, :Full Name Short, " " ) ) );
countylist << New column( "Region", Character );
countylist << New column( "State", formula( Word( -1, :Full Name Short, " " ) ) );
/* This block opens the downloaded PDF */
// Opens downloaded PDF & imports the first table
request = New HTTP Request(
URL(
"https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246"
),
Method( "Get" )
);
file = request << Download( "$TEMP/Kansas Health Preparedness Regions.pdf", "replace", "show_progress" );
dt = Open( file,
PDF Tables(
Table(
table name(
"Kansas Health Preparedness Regions and Map Page(1) Table(1)"
),
add rows( page( 1 ), Rect( 0.4789, 1.0156, 10.5211, 7.8894 ) )
)
)
);
// For some reason, if the below command doesn't re-assign dt to the data table,
// dt isn't the correct data type for the operation to continue
dt = dt[1];
// Deletes empty rows in imported PDF table
dt << Select where( Is Missing( :Region ) ) << Delete Rows;
// Starting AA for data storage
region = Associative array();
// Stores region / county list data in AA
for( i = 1, i <= N Rows( dt ), i++,
// Save the list as the value pair (county list, list of strings) to the respective key
region[ dt:region[i] ] = words( dt:Counties Included[i], ", " );
);
// The region & county list is now stored in an AA!
//print( region );
kskeys = region << Get keys;
/* This block will use data in AA to assign region to respective county in US-County-Name.jmp */
for( k = 1, k <= N rows( countylist ), k++,
// Condition where state = Kansas
try( if( countylist:State[k] == "KS",
// Iterates through AA keys (regions)
for( m = 1, m <= N Items( kskeys ), m++,
// Checks if Count present, then assigns region to dt
if( contains( region[ kskeys[m] ], countylist:County[k] ), // County is in m list
countylist:Region[k] = kskeys[m]
);
);
) ); // try --> if county not found in PDF stated counties, no region will be assigned
);
// Closes out pdf table, if needed
close( dt, "No Save" );