将州县合并到地区堪萨斯州有 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" );