州の郡を地域に結合するカンザス州には 105 の郡があり、それらは 16 の健康準備地域に統合されています。 US-County-Name.jmp と関連する XY ファイルを使用してこれを行うにはどうすればよいですか?
カンザスの 16 地域は、次のリンクで定義されています。 https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246
どんな助けでも大歓迎です。
グラフィックRe: 州の郡をリージョンに結合する誰かがもっと簡単な方法を持っているかもしれませんが、私はこのようなことをして、多少の努力は必要ですがうまくいくことを知っています.最初に、あなたがリンクした地域テーブルをダウンロードし、コンマを区切り文字として使用して郡を区切ります (JMP でも実行できますが、通常、この段階では Excel を使用します)。次に、2 つの列が存在するように郡を積み重ねて、そのテーブルを再構築します。1 つは地域を示し、もう 1 つは各地域に関連付けられた郡を (ただし 1 つの列として) 表示します。次に、US-County-Name.jmp ファイルの郡名の形式が、作成したファイルと同じであることを確認します (郡名に「County」という単語を追加するなど)。郡名は地図ファイルを参照してください)。次に、作成した County 列にマップ ロールを割り当て、そのファイル内の正しい名前の列を使用して US-County-Name.jmp ファイルにリンクします。新しいファイルには地域の列があるため、グラフ ビルダーでそれを使用して、地図上の地域を重ねたり、色を付けたりできます。
私はこれが労働集約的であることを知っていますが、これは私が過去にこれを行った唯一の方法です.
Re: 州の郡をリージョンに結合するこんにちは@jkeighley 、
以下に、デバッグが必要なコードをいくつか示しますが、ここから始めるのが確実です。 以下のスクリプトを改善できる他のスクリプターはいますか?私は多くの改善が必要だと確信しています!
- 開くUS-郡名.jmp & p州と郡を新しい列に分割することにより、後で検索するための担当者
- 上記でリンクした PDF をダウンロードして開き、最初のページに表をインポートします
- 注 - ローカル マシンで実行する前に、必ずスクリプトを確認してください。 このスクリプトは、インターネットから PDF をダウンロードします。15 行目、URL() 引数の URL 文字列を確認してください
- Assigns は、地域内の地域 (キー) と郡 (値) の連想配列 (AA) を作成します<-- ループが機能しない
- 私は正規表現の初心者なので、正規表現が壊れています
- 郡のリストは単一の文字列として返されます。これは、正規表現によって分解されるはずです
- 郡文字列の例: 「Barton, McPherson, Pawnee, Rice, Saline, Stafford」
- 文字列のリストである必要があります: { "Barton", "McPherson", "Pawnee", "Rice", "Saline", "Stafford" }
- US-郡名.jmp...
- State = KS およびその他の条件の行を見つけるために、いくつかのネストされたループを使用します
- 州 = KS の行で国を確認し、AA を検索して対応する地域を見つけ、郡 (値) が割り当てられている地域 (キー) を割り当てます。
- 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" );
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" );