Combina le contee statali alle regioniIl Kansas ha 105 contee che sono combinate in 16 regioni di preparazione sanitaria. Come posso farlo utilizzando US-County-Name.jmp e il file XY associato?
Le 16 regioni per il Kansas sono definite al seguente link: https://www.kdhe.ks.gov/ArchiveCenter/ViewFile/Item/1246
Qualsiasi aiuto sarebbe apprezzato.
GraficaRi: Unire le contee statali alle regioniQualcuno potrebbe avere un modo più semplice, ma ho fatto cose come questa e so che funzionerà anche se richiede un certo sforzo.Innanzitutto, scaricherei la tabella delle regioni che hai collegato e poi separerei le contee usando la virgola come delimitatore (di solito uso Excel per questa fase, anche se può essere fatto in JMP).Quindi ristrutturerei quella tabella impilando le contee in modo che ci siano 2 colonne, una con la regione e l'altra che mostra le contee associate a ciascuna regione (ma come un'unica colonna).Quindi puoi assicurarti che il file US-County-Name.jmp abbia lo stesso formato per i nomi delle contee del file che hai creato (ad esempio aggiungendo la parola "County" al nome della contea - assicurati che corrisponda esattamente al modo in cui i nomi delle contee cercano nel map file).Quindi assegna il ruolo della mappa alla colonna County che hai creato, collegandola al file US-County-Name.jmp utilizzando la colonna denominata corretta in quel file.Poiché il tuo nuovo file avrà una colonna per Regione, puoi utilizzarla in Graph Builder per sovrapporre o colorare le regioni sulla mappa.
So che è laborioso, ma è l'unico modo in cui l'ho fatto in passato.
Ri: Unire le contee statali alle regioniCiao @jkeighley ,
Di seguito ho del codice che necessita di debug, ma dovrebbe essere un buon punto di partenza. Qualche altro scripter che potrebbe migliorare lo script qui sotto?Sono sicuro che c'è molto miglioramento necessario!
- Si apre US-County-Name.jmp & p ripetizioni per la ricerca successiva, suddividendo lo stato e la contea in nuove colonne
- Scarica e apre il PDF che hai collegato sopra, quindi importa la tabella nella prima pagina
- Nota: rivedi sempre lo script prima di eseguirlo sul tuo computer locale! Questo script scarica un PDF da Internet.Controlla la riga 15, la stringa URL nell'argomento URL()
- Assigns crea un array associativo (AA) di regioni (chiavi) e contee (valori) all'interno della regione <-- ciclo non funzionante
- Sono un principiante con le espressioni regolari, quindi l'espressione regex è rotta
- L'elenco delle contee ritorna come una singola stringa, che regex dovrebbe spezzare
- Esempio di stringa della contea: "Barton, McPherson, Pawnee, Rice, Saline, Stafford"
- Deve essere un elenco di stringhe: { "Barton", "McPherson", "Pawnee", "Rice", "Saline", "Stafford" }
- In US-County-Name.jmp...
- Utilizza alcuni cicli nidificati per trovare le righe in cui State = KS e altre condizioni
- Quando una riga in cui Stato = KS, guarda il paese, quindi trova a quale regione corrisponde effettuando una ricerca nell'AA e quindi assegnando la regione (chiave) a cui è assegnata la contea (valore)
- Salva la regione (chiave) nella colonna regione della riga
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" );
Ri: Unire le contee statali alle regioni@jkeighley
Ho ottenuto lo script qui sotto per aggiornare correttamente le regioni in US-County-Name.jmp. Si noti che lo script seguente non salva questo file o modifica il file XY associato.
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" );