주 카운티를 지역에 결합Kansas에는 16개의 보건 대비 지역으로 통합된 105개의 카운티가 있습니다. US-County-Name.jmp 및 관련 XY 파일을 사용하여 이 작업을 수행하려면 어떻게 해야 합니까?
Kansas의 16개 지역은 다음 링크에 정의되어 있습니다. https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246
도움을 주시면 감사하겠습니다.
제도법Re: 주 카운티를 지역으로 결합누군가는 더 쉬운 방법이 있을 수 있지만 저는 이와 같은 작업을 수행했으며 약간의 노력이 필요하지만 작동한다는 것을 알고 있습니다.먼저 연결한 지역 테이블을 다운로드한 다음 쉼표를 구분 기호로 사용하여 카운티를 구분합니다(JMP에서도 가능하지만 이 단계에서는 일반적으로 Excel을 사용합니다).그런 다음 카운티를 쌓아 해당 테이블을 재구성하여 2개의 열이 있도록 합니다. 하나는 지역이 있고 다른 하나는 각 지역과 연결된 카운티를 표시합니다(단일 열로).그런 다음 US-County-Name.jmp 파일의 카운티 이름 형식이 사용자가 만든 파일과 동일한지 확인할 수 있습니다(예: 카운티 이름에 "County"라는 단어 추가 - 카운티 이름은 지도 파일에서 찾습니다).그런 다음 생성한 카운티 열에 맵 역할을 할당하고 해당 파일의 올바른 명명된 열을 사용하여 US-County-Name.jmp 파일에 연결합니다.새 파일에는 지역에 대한 열이 있으므로 그래프 빌더에서 해당 열을 사용하여 지도에서 지역을 오버레이하거나 색상을 지정할 수 있습니다.
나는 이것이 노동 집약적이라는 것을 알고 있지만 과거에 내가 이것을 한 유일한 방법입니다.
Re: 주 카운티를 지역으로 결합안녕하세요 @jkeighley ,
아래에는 약간의 디버깅이 필요한 코드가 있지만 시작할 수 있는 견고한 위치여야 합니다. 아래 스크립트를 개선할 수 있는 다른 스크립터가 있습니까?많은 개선이 필요하다고 확신합니다!
- 열린다 US-County-Name.jmp & p 주와 카운티를 새 열로 분리하여 나중에 검색할 수 있도록 담당자
- 위에서 링크한 PDF를 다운로드하고 연 다음 첫 페이지의 표를 가져옵니다.
- 참고 - 로컬 컴퓨터에서 실행하기 전에 항상 스크립트를 검토하십시오! 이 스크립트는 인터넷에서 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를 검색하여 county(value)가 할당된 region(key)을 할당하여 해당하는 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" );
Re: 주 카운티를 지역으로 결합@jkeighley
지역을 성공적으로 업데이트하는 스크립트가 아래에 있습니다. US-County-Name.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" );