SlideShare a Scribd company logo
1 of 8
Lance Duncan
Geog 375, Spring 2014
Prof. Nathan Jennings
Creation of a Map through Python
Executive Summary
This Project resulted in a script which allowed a user to input a county in order to generate a
map with all the hospitals in that county selected and labeled. In working though this project there
were some difficulties which caused me to try a different method in completing the script. In my first
attempt at generating the script, I ran into issues with select by location, which later resolved
themselves. What ultimately led to my reevaluation of my methods was editing a map document.
Because I could not create a script which successfully modified the map in a desired way, I took a step
back and decided to try a different approach to the whole project. In my second script I performed a
join, so there was only on selection set. Also in this approach I found what I had done wrong in my
first attempt at modifiying the map and was able to complete the edits to the map layout and
dataframe. This project was a major learnig experience for me, teaching me to think about the best
method to complete a task and I gained critical experience with the mapping module.
Purpose
The goal of this project was first of all to fulfill the requirements for a final proect and
demonstrate my knowledge and proficiency with python for ArcGIS. With that in mind I decided to
write a script that would involve most of what I learned this semester. Looking at what data I had
easily available I chose to work with Hospitals from the Esri Data and Maps package. The final
objective I decided on was to write a script which would allow the user to input a county and a map
showing all the hospitals in that county would be generated. I also contemplated developing a GUI,
but procrastinated the construction of that and did not complete it.
Tasks
On writing this script I ran into many roadblocks and ended up creating two different scripts
because my first approach was not successful. I will examine my first approach and its failures, and
then detail what I did differently the second time around.
ATTEMPT 1:
My first objective was to search for a specific county, so to do this I created a search query on
a feature class containing counties.
Next, I had to select the hospitals within a certain county. So I used select by attribute
followed by a select by location. At first this wasn't working, the select by location would return all the
hospitals in the feature class and not just the ones in the county. So as a work around I used select by
attribute to select the hospital based on the fips code returned from the search cursor. When I came
back to the code a few days later and tried the select by location a second tiem, it worked perfectly,
so I scrapped the workaround. Following the selection I performed another search cursor meant to
return the names of the selected hospitals. This was based on the fips code, as a result the user would
either have to know the fips code of the desired county or run the script up to a point to find the fips
code. This complication is not something I desired in the script, and which I was able to work past in
myy second attempt.
This next step is where I ran into serious problems and decided to try a different approach. I
wanted to label the hospitals which were selected, zoom to the selected county, and change some
layout elements. I could not get any of these processes to work. Looking at a comparison of my final
script and my first attempt, I suspect I could fix it now. It seems that the issues may have arisen form
improper indentation and other syntax. What is shown below is the jumbeled mess of the different
methods I tried to implement to make the script produce a result. In running it, I would use the # to
block certain sections so only the desired element ran, but despite my best efforts I couldn't
accomplish any of the tasks.
ATTEMPT 2:
After giving up on my original script, I determined that it might be easier to accomplish my
goal by using a single feature class to select from. So I decided to perform a join of the counties
feature calss and the hospitals feature class. Before I performed the join I thought it might be a good
idea to index the feature classes, and this immensely improved the processing time of the join.
Once the join was complete, I exported the joined features to a new feature class.
Once the new feature class was created, I made a feature layer for it and used select by
attribute to select all the hospitals within a specific county.
Once the selectin was complete I used a search cursor to list the names of all the selected
hospitals. Having a joined feature overcame the previuos problem of needing to know the fips code,
the query used for the selection set could also be used in this search cursor.
After a lot of trial and error I discovered I needed to add the joined feature class to the map
document because in the process of creating the feature class, any previously constructed feature
classes were destroyed and thus removed from the map, so I had to add it back to the map in order to
change the map document properties.
Also through research I discovered I had to name the layout elements I wanted to change in
the map. Once I had done that; I labeled the hospitals using proper indentation, and zoomed to the
selected features, and changed the desired Layout Elements.
Once all this was completed I saved the changes to a new map document and exported that to
a PDF so the resulting map could be viewed by non ArcMap users as well as edited by someone who
could use ArcMap.
Conclusions
Working through this project I learned and discovered many things about using python with
ArcGIS. An important lesson that can be taken away from this project is that the first or most obvious
approach might not be the best approach. My second script shows this, it is much simpler in copncept
and more elegant in implementation. I definitely had more direction when developing the second
script as one task naturally led to another. There was not nearly as much guesswork involved.
Another lesson can be seen in my dificulties with editing a map document. Despite the fact
that I had completed the exercise and written my own version of the demos for chapter nine, I was
still not proficient at using the mapping module. There were many simple things that I did not realize
the importance of until I grew extremely frustrated. I had to take a step back and give myself time to
think about the methods I was using. I also had to reread the entire chapter on the mapping module
to really understand what I was doing wrong.
In the end the script works perfectly and writing it was a great learning experience. As I
mentioned in the beginning, I had planned on developing a GUI to accompany the script, but ran out
of time due to my own procrastination. After reading the chapter on developing the interface with
ArcMap, I can clearly envision how I would go about converting the script, I would just need some
time to complete it, and now I also question the usefulness of even making a GUI for this script, as it is
very specific in what it does. In order to make a useful toolbox script I might have to modify the script
to be more general purpose.
The end results of the script turned out as I desired, not the best cartographic work, but
certainly useful. Including a streets feature class may be useful for real world appilcation.

More Related Content

Viewers also liked

A Arte de Olbinski
A Arte de OlbinskiA Arte de Olbinski
A Arte de Olbinski
BiaEsteves
 
Cidades Iluminadas
Cidades IluminadasCidades Iluminadas
Cidades Iluminadas
BiaEsteves
 
Lake Malawi-Moçambique
Lake Malawi-MoçambiqueLake Malawi-Moçambique
Lake Malawi-Moçambique
BiaEsteves
 
Capela de Gaudi
Capela de GaudiCapela de Gaudi
Capela de Gaudi
BiaEsteves
 
Frascos Jponeses Pintados à Mão
Frascos Jponeses Pintados à MãoFrascos Jponeses Pintados à Mão
Frascos Jponeses Pintados à Mão
BiaEsteves
 
Arte de Sergei Yaralov
Arte de Sergei Yaralov Arte de Sergei Yaralov
Arte de Sergei Yaralov
BiaEsteves
 

Viewers also liked (20)

Borboletas
Borboletas Borboletas
Borboletas
 
A Arte de Olbinski
A Arte de OlbinskiA Arte de Olbinski
A Arte de Olbinski
 
I Need To Go To The Rock Star Teacher Camp
I Need To Go To The Rock Star Teacher CampI Need To Go To The Rock Star Teacher Camp
I Need To Go To The Rock Star Teacher Camp
 
Elf 2011 Chris Jansen Appreciative Inquiry In Action
Elf 2011 Chris Jansen Appreciative Inquiry In ActionElf 2011 Chris Jansen Appreciative Inquiry In Action
Elf 2011 Chris Jansen Appreciative Inquiry In Action
 
Cidades Iluminadas
Cidades IluminadasCidades Iluminadas
Cidades Iluminadas
 
HR and Communications: Essential Business Catalysts
HR and Communications:  Essential Business CatalystsHR and Communications:  Essential Business Catalysts
HR and Communications: Essential Business Catalysts
 
India
IndiaIndia
India
 
Lake Malawi-Moçambique
Lake Malawi-MoçambiqueLake Malawi-Moçambique
Lake Malawi-Moçambique
 
Kithira
KithiraKithira
Kithira
 
Dr Katie Pickles, Associate Professor, University of Canterbury - presentatio...
Dr Katie Pickles, Associate Professor, University of Canterbury - presentatio...Dr Katie Pickles, Associate Professor, University of Canterbury - presentatio...
Dr Katie Pickles, Associate Professor, University of Canterbury - presentatio...
 
Lisboa
Lisboa Lisboa
Lisboa
 
Capela de Gaudi
Capela de GaudiCapela de Gaudi
Capela de Gaudi
 
Arab Youth Survey 2013
Arab Youth Survey 2013 Arab Youth Survey 2013
Arab Youth Survey 2013
 
Aves Chinesas
Aves ChinesasAves Chinesas
Aves Chinesas
 
Underwater
UnderwaterUnderwater
Underwater
 
Aveiro
AveiroAveiro
Aveiro
 
Frascos Jponeses Pintados à Mão
Frascos Jponeses Pintados à MãoFrascos Jponeses Pintados à Mão
Frascos Jponeses Pintados à Mão
 
Educational Review: Lorraine Moss Case Manager, Greater Christchurch Educatio...
Educational Review: Lorraine Moss Case Manager, Greater Christchurch Educatio...Educational Review: Lorraine Moss Case Manager, Greater Christchurch Educatio...
Educational Review: Lorraine Moss Case Manager, Greater Christchurch Educatio...
 
Arte de Sergei Yaralov
Arte de Sergei Yaralov Arte de Sergei Yaralov
Arte de Sergei Yaralov
 
Joanna Norris, Editor, The Press - presentation at Seismics and the City 2013
Joanna Norris, Editor, The Press - presentation at Seismics and the City 2013Joanna Norris, Editor, The Press - presentation at Seismics and the City 2013
Joanna Norris, Editor, The Press - presentation at Seismics and the City 2013
 

Similar to Duncan_doc

Marauders Map Production Diary.docx
Marauders Map Production Diary.docxMarauders Map Production Diary.docx
Marauders Map Production Diary.docx
alilyajaib
 
Unit66 production log_lewis
Unit66 production log_lewisUnit66 production log_lewis
Unit66 production log_lewis
LewisB2013
 
Final Question 2 evaluation
Final Question 2 evaluationFinal Question 2 evaluation
Final Question 2 evaluation
baldeep17_
 
Question 6
Question 6Question 6
Question 6
TCH4LK
 
What have you learnt about technologies from the john
What have you learnt about technologies from the johnWhat have you learnt about technologies from the john
What have you learnt about technologies from the john
carolinebirksatwork
 
Unit66 production log_060314
Unit66 production log_060314Unit66 production log_060314
Unit66 production log_060314
Deightonater
 

Similar to Duncan_doc (20)

Production Diary.pptx
Production Diary.pptxProduction Diary.pptx
Production Diary.pptx
 
4. production experiments(1)
4. production experiments(1)4. production experiments(1)
4. production experiments(1)
 
Marauders Map Production Diary.docx
Marauders Map Production Diary.docxMarauders Map Production Diary.docx
Marauders Map Production Diary.docx
 
Question 6
Question 6Question 6
Question 6
 
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
End to end testing Single Page Apps & APIs with Cucumber.js and Puppeteer (Em...
 
Unit66 production log_lewis
Unit66 production log_lewisUnit66 production log_lewis
Unit66 production log_lewis
 
Developed tools
Developed toolsDeveloped tools
Developed tools
 
xkcd viewer report
xkcd viewer reportxkcd viewer report
xkcd viewer report
 
FMP Problem Solving + Experiments.pptx
FMP Problem Solving + Experiments.pptxFMP Problem Solving + Experiments.pptx
FMP Problem Solving + Experiments.pptx
 
Production Log
Production LogProduction Log
Production Log
 
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and PuppeteerE2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
E2E testing Single Page Apps and APIs with Cucumber.js and Puppeteer
 
Question 6
Question 6Question 6
Question 6
 
Final Question 2 evaluation
Final Question 2 evaluationFinal Question 2 evaluation
Final Question 2 evaluation
 
Evaluation Question 6 - Final
Evaluation Question 6 - FinalEvaluation Question 6 - Final
Evaluation Question 6 - Final
 
Evaluation Question 6 - Final
Evaluation Question 6 - FinalEvaluation Question 6 - Final
Evaluation Question 6 - Final
 
Question 6
Question 6Question 6
Question 6
 
Evaluation
Evaluation Evaluation
Evaluation
 
What have you learnt about technologies from the john
What have you learnt about technologies from the johnWhat have you learnt about technologies from the john
What have you learnt about technologies from the john
 
Unit66 production log_060314
Unit66 production log_060314Unit66 production log_060314
Unit66 production log_060314
 
Question 6
Question 6Question 6
Question 6
 

More from Lance Duncan (15)

ERD_Diagram_Links V1
ERD_Diagram_Links V1ERD_Diagram_Links V1
ERD_Diagram_Links V1
 
Duncan_Bivariate
Duncan_BivariateDuncan_Bivariate
Duncan_Bivariate
 
Anchor9
Anchor9Anchor9
Anchor9
 
Anchor8
Anchor8Anchor8
Anchor8
 
Anchor7
Anchor7Anchor7
Anchor7
 
Anchor6
Anchor6Anchor6
Anchor6
 
Anchor5
Anchor5Anchor5
Anchor5
 
Anchor4
Anchor4Anchor4
Anchor4
 
Anchor1
Anchor1Anchor1
Anchor1
 
hsrColleges01122014
hsrColleges01122014hsrColleges01122014
hsrColleges01122014
 
SCE_MHI
SCE_MHISCE_MHI
SCE_MHI
 
CA_MHI
CA_MHICA_MHI
CA_MHI
 
mil_bases2
mil_bases2mil_bases2
mil_bases2
 
WCGH_08072014
WCGH_08072014WCGH_08072014
WCGH_08072014
 
GEOG498Journal
GEOG498JournalGEOG498Journal
GEOG498Journal
 

Duncan_doc

  • 1. Lance Duncan Geog 375, Spring 2014 Prof. Nathan Jennings Creation of a Map through Python Executive Summary This Project resulted in a script which allowed a user to input a county in order to generate a map with all the hospitals in that county selected and labeled. In working though this project there were some difficulties which caused me to try a different method in completing the script. In my first attempt at generating the script, I ran into issues with select by location, which later resolved themselves. What ultimately led to my reevaluation of my methods was editing a map document. Because I could not create a script which successfully modified the map in a desired way, I took a step back and decided to try a different approach to the whole project. In my second script I performed a join, so there was only on selection set. Also in this approach I found what I had done wrong in my first attempt at modifiying the map and was able to complete the edits to the map layout and dataframe. This project was a major learnig experience for me, teaching me to think about the best method to complete a task and I gained critical experience with the mapping module. Purpose The goal of this project was first of all to fulfill the requirements for a final proect and demonstrate my knowledge and proficiency with python for ArcGIS. With that in mind I decided to write a script that would involve most of what I learned this semester. Looking at what data I had easily available I chose to work with Hospitals from the Esri Data and Maps package. The final objective I decided on was to write a script which would allow the user to input a county and a map showing all the hospitals in that county would be generated. I also contemplated developing a GUI, but procrastinated the construction of that and did not complete it. Tasks On writing this script I ran into many roadblocks and ended up creating two different scripts because my first approach was not successful. I will examine my first approach and its failures, and then detail what I did differently the second time around.
  • 2. ATTEMPT 1: My first objective was to search for a specific county, so to do this I created a search query on a feature class containing counties.
  • 3. Next, I had to select the hospitals within a certain county. So I used select by attribute followed by a select by location. At first this wasn't working, the select by location would return all the hospitals in the feature class and not just the ones in the county. So as a work around I used select by attribute to select the hospital based on the fips code returned from the search cursor. When I came back to the code a few days later and tried the select by location a second tiem, it worked perfectly, so I scrapped the workaround. Following the selection I performed another search cursor meant to return the names of the selected hospitals. This was based on the fips code, as a result the user would either have to know the fips code of the desired county or run the script up to a point to find the fips code. This complication is not something I desired in the script, and which I was able to work past in myy second attempt.
  • 4. This next step is where I ran into serious problems and decided to try a different approach. I wanted to label the hospitals which were selected, zoom to the selected county, and change some layout elements. I could not get any of these processes to work. Looking at a comparison of my final script and my first attempt, I suspect I could fix it now. It seems that the issues may have arisen form improper indentation and other syntax. What is shown below is the jumbeled mess of the different methods I tried to implement to make the script produce a result. In running it, I would use the # to block certain sections so only the desired element ran, but despite my best efforts I couldn't accomplish any of the tasks.
  • 5. ATTEMPT 2: After giving up on my original script, I determined that it might be easier to accomplish my goal by using a single feature class to select from. So I decided to perform a join of the counties feature calss and the hospitals feature class. Before I performed the join I thought it might be a good idea to index the feature classes, and this immensely improved the processing time of the join. Once the join was complete, I exported the joined features to a new feature class.
  • 6. Once the new feature class was created, I made a feature layer for it and used select by attribute to select all the hospitals within a specific county. Once the selectin was complete I used a search cursor to list the names of all the selected hospitals. Having a joined feature overcame the previuos problem of needing to know the fips code, the query used for the selection set could also be used in this search cursor.
  • 7. After a lot of trial and error I discovered I needed to add the joined feature class to the map document because in the process of creating the feature class, any previously constructed feature classes were destroyed and thus removed from the map, so I had to add it back to the map in order to change the map document properties. Also through research I discovered I had to name the layout elements I wanted to change in the map. Once I had done that; I labeled the hospitals using proper indentation, and zoomed to the selected features, and changed the desired Layout Elements. Once all this was completed I saved the changes to a new map document and exported that to a PDF so the resulting map could be viewed by non ArcMap users as well as edited by someone who could use ArcMap.
  • 8. Conclusions Working through this project I learned and discovered many things about using python with ArcGIS. An important lesson that can be taken away from this project is that the first or most obvious approach might not be the best approach. My second script shows this, it is much simpler in copncept and more elegant in implementation. I definitely had more direction when developing the second script as one task naturally led to another. There was not nearly as much guesswork involved. Another lesson can be seen in my dificulties with editing a map document. Despite the fact that I had completed the exercise and written my own version of the demos for chapter nine, I was still not proficient at using the mapping module. There were many simple things that I did not realize the importance of until I grew extremely frustrated. I had to take a step back and give myself time to think about the methods I was using. I also had to reread the entire chapter on the mapping module to really understand what I was doing wrong. In the end the script works perfectly and writing it was a great learning experience. As I mentioned in the beginning, I had planned on developing a GUI to accompany the script, but ran out of time due to my own procrastination. After reading the chapter on developing the interface with ArcMap, I can clearly envision how I would go about converting the script, I would just need some time to complete it, and now I also question the usefulness of even making a GUI for this script, as it is very specific in what it does. In order to make a useful toolbox script I might have to modify the script to be more general purpose. The end results of the script turned out as I desired, not the best cartographic work, but certainly useful. Including a streets feature class may be useful for real world appilcation.