Tuesday, June 24, 2025

Module 6: Geometries

 Module 6: Geometries

This weeks lab was about how to use geometries within Python and ArcGIS Pro. We wrote a script that creates a TXT file and write to it the coordinates and object IDs for vertices in a shapefile. This lab had us use two for loop statements. It was more difficult to understand how to make two for loop statements. Working with geometries is very time consuming but we learned about how to use geometry tokens. Geometry tokens provide shortcuts to specific geometry properties of individual features in a feature class. Another important factor we learned was when reading geometry types (polygons and polylines) requires extra code because an array of point objects is returned for each feature. As a result, an extra iteration is required to interact with the array first before you can get to the points that make up the array. This is where the for loop statements came in and made it easier to get all the information we may need. So that we did not have to do another for loop statement we did the getPart() method. The getPart() method returns a single point object for one single-part feature. If it is a polyline or polygon, it returns an array of point objects of the different features you are trying to get. In short, the getPart() method allows you to access and look through the different parts within a single geometry object. The hardest part I had was getting the information to print in the textfile and I remembered using the Try statements so that I could do the except and finally statements so that I could get the information to print. Being able to use those statements were important because it could show me where the issue was happening before things printed into the text file. Lastly, my other issue was figuring out the .write() statement so the information did actually write into the textfile. That is when I created the line I wanted to write and then put it the parentheses. The image below shows a portion of the information into the textfile.

This image below is the flowchart of how I created the script for the information I wanted for the rivers shapefile. Once again it was difficult to show the for loops and how they were being represented.

This module was probably the most difficult one because of the two for loop statements and getting the information to write into the textfile. Once I remembered the try statement I was able to make sure I got all the information correctly into the textfile.

Tuesday, June 17, 2025

Module 5: Explore and Manipulate Data

 Module 5: Explore and Manipulate Data

In this weeks module the focus was on how we can explore and manipulate data that are within ArcGIS Pro. The script creates a new file geodatabase, copy feature class data to the new file geodatabase, create a Search Cursor for the cities feature class, and create a new dictionary.

First we needed to create a new file geodatabase that goes into the results folder. It is important to note that before any of this can begin you need to make sure you import arcpy and import env. Also, to make sure you can create the geodatabase more than once you need to have the overwrite output to True. If you are getting an error message if trying it again it is because ArcGIS Pro is open and it needs to be closed before running it in Python IDLE. If you run it in the Notebook portion in ArcGIS Pro you do not seem to have that problem. The image below shows the outcome of the script that was written.

The next portion of the script was creating a feature class list and copying that into the new geodatabase that was previously created. When making sure the data gets copied you need to use the Describe() function. Also, to get all the data copied you need to make sure to the script as the following arcpy.CopyFeatures_management(fc, outputEnv + "/ejd31.gdb/" + fcdesc.basename). This piece of code makes sure everything gets copied and that the basename of the feature shows up when it gets copied. In the image below shows that each feature got copied and how long it took to get the information to copy into the new file geodatabase.

After that I needed to create a Search Cursor that only printed the Name, Feature, and Pop_2000 only for the county seat within the cities shapefile. I knew how to write the code for one row in the attribute table but was not sure for three. I made the fields code as fields = [“NAME”, “FEATURE”, “POP_2000”] and the sqlQuery = “FEATURE = ‘County Seat’”.  I used the arcpy.da.SearchCursor because I did not want to change the table but to just find the specific rows and print them. Also, you need to make sure to use a for loop statement to make sure only the specific rows get printed and not the other ones in the attribute table. The image below shows all the features that were only County Seat with the name and population of those features.
     

The last portion of the script was creating a new dictionary based off the information from the cities shapefile attribute table. The dictionary needs to focus on the name and population of the county seat features. Another issue I was having was trying to get the for loop statement to create a dictionary for an empty dictionary. I knew how to make the dictionary but was not sure how to make the statement work. I did try different versions and none were working for me. I think asked the discussions page and Serenity helped me with the script needed to have another line of code saying with arcpy.da.SearchCursor(fc, fields, sqlQuery) as cursor: The information in the parentheses is based off the previous script above. The difference is that I needed to add the specific row numbers for the keys and values that I wanted represented in the dictionary. Lastly, I chose the dictionary variable[keys] = variables which was county_seats[name] = population. The image below shows the new dictionary with just the information of the Name and Population of the county seats in the cities shapefile

An important note is that to get the copying features to print separately the code is print(f”Copying: {fc} \n”). This was able to help me get them to print one at a time instead of all of them at once over and over again. Knwoing how to get the information to print properly will help know what is being copied in the first place. The script creates a new file geodatabase, copy feature class data to the new file geodatabase, create a Search Cursor for the cities feature class, and create a new dictionary. The image is of the flowchart that I used for the script that was written. 



Monday, June 9, 2025

Module 4: Geoprocessing

 Module 4: Geoprocessing

In this weeks module the focus was on geoprocessing tools, creating our own ModelBuilder and toolboxes. The first portion of the assignment was using the ModelBuilder to clip sols within the basin shapefile, select a specific attribute within the soils shapefile, and erase the "Not prime farmland" within the soils shapefile. Within the ModelBuilder the you can drag in your data and geoprocessing tools. These tools are similar as ones that I have used within the maps. The ModelBuilder is important because you can create what you want done all at once instead of each step separately. In the image below it shows how I added the basin and soils shape file. Next added in the clip analysis tool where I said I wanted the soils only within the basin shapefile. Which creates the shapefile which I called soil_Clip. Then to erase the "Not prime farmland" portion I needed to add the Select analysis tool which I created a script. Lastly, this created Soils_Selected.shp.


This image below shows what the ModelBuilder produced which was all the areas that were not apart of the "Not prime farmland" shapefiles.


The next portion of this module was writing script that adds XY coordinates, creates a 1000 meter buffer, and dissolve the buffers into a single feature for the hospitals shapefile. When designing the script that adds the XY coordinates, buffers, and dissolve the hospital shapefile I needed to make sure there is arcpy and env workspace. The workspace is the location of where the data is coming from to add the information to the shapefile. Next, I made sure to overwrite the output features so the code could be done repeatedly. The first portion of the code was the XY coordinates on the shapefile by creating the shapefile as the in_features. To make sure the shapefile gets the XY coordinates the code needs to be “arcpy.management.AddXY(in_features)”. For the buffer portion I needed to write “arcpy.Buffer_analysis” Within this code I need to make sure to put in the buffer zone and where I want the shapefile to go which was the results tab in Module. Lastly, for the dissolving portion it is the same code as the buffer analysis, but I needed to make sure to add two open string portions and one that says ‘ALL’. This will make sure all the areas that overlap dissolve and create a whole new shapefile. If I did not want to create a new shapefile, I could name it the same shapefile as above. Another thing that needed to be added was the GetMessages() function so you can see the start time and if the script was successful in running. I put this in after the the other print option. The code was written as "print(arcpy.GetMessages())". Within ArcGIS Pro you do not necessarily need to add arcpy but I still added “import arcpy” in case the script runs in IDLE. Also, to make sure things are overwritten you need to make sure the box in clicked in the options tab under geoprocessing and write the code “env.overwriteOutput = True”. Lastly, to make a space within your script you can use “\n” within the print portion of the script. The image below is the result of the script that I wrote to add the XY coordinates, 1000 meter buffer, and dissolve the buffer for the hospitals shapefile.

This weeks module was very useful because it is able to learn how to use ModelBuilder to make shapefiles all at once instead of one at a time. Also, I learned how to do Batch processing that can help me do a lot of data all at once. Lastly, I was able to learn how to create a script that can add XY coordinates, add a buffer, and dissolve that buffer instead of doing it through the geoprocessing tools individually.

Monday, June 2, 2025

Module 3: Debugging and Error Handling

 Module 3: Debugging and Error Handling

In this weeks module the focus was on how to debug code and understand what the error messages are saying to the person writing or using scripts. There are different errors that can be seen when writing script. The first common error message is syntax error as known as the "grammar" of the code. This includes the spelling, punctuation, and indentation. On the other hand there are run-time errors that come up after the code gets run. Some examples are NameError, TypeError, and LicenseError. When doing this week we did three different scripts that we either fixed or did a try-except statment.

In the first script we had to look for two errors that were within the code. When trying to figure out the errors you can either click the "Run Module" or "Check Module" within IDLE. For me the easiest one was to save the script and clicking "Run Module". Then it comes out saying what the error is and what line it is located on. The first error was a NameError that within Line 5 the name 'fc' is not defined. When looking at the rest of the code it showed that the name 'fc' needed to be capitalized. The second error was another NameError in Line 8 where the name 'field' was not defined. Once again looking at the rest of the script I was able to notice I needed to add an 's' to the end to match other portions of the script. The picture below is the output of the script that was written.


The second script there were several errors or exceptions. Once again it was easy to save the script and click "Run Module" to find the first error. The first error was a NameError in Line 6 that indicated 'Filepath' is not defined. When looking in the rest of the code you can see it needed to be 'filepath' in the parenthesis. Next was an OSError which indicates that the file path in Line 6 is not connected to anything on the computer. I fixed the OSError to filepath ="S:/GISProgramming/Module3/Data/ Mod3_Data/TravisCountyAustinTX.aprx". The next error was a NameError in Line 8 saying 'arcp' is not defined and I noticed it was the dataset 'arcpy' that needed to fixed. Afterwards there was another OSError found in Line 7 and noticed one of the slashes were in the wrong way and that I needed to add more to the dataset file path. Then the next error was AttributeError that says 'spatialRefernce" does not exist. All I had to do was spell it correctly as "spatialReference." The next error was a TypeError that says 'type' object is not iterable in Line 13 and all I needed to do is add a 's' to the end of map. After fixing all the errors and exceptions it finally produced the outcome of the spatial reference and the four shapefiles within the ArcGIS Pro map which is seen in the picture below.


The third and final script that was written had errors but we needed to do a try-except statement. This statement allows a script to run successfully which helps with seeing the exceptions within the code and “trap” it so the code can continue run. When including the try-except statement you want to run the code to see what the error is that is stopping the code from running. First you want to put “try” statement before the code that has the error(s). Next you want to then put the “except” statement below the error and handles the error. Then you will run the code again to see if there are any other errors in the code. If there is another error, you can include in the current “except” statement or make another. Lastly, when you have all the errors it should be able to run the code and explain to someone why there were some errors as well as where they were located. I have included the output of both the parts and a flow chart of how to do Part A of the try-except statement.


In this module it was very helpful to learn about the different errors so that in the future my script runs without issues. Also, if I do run into issues I can fix it easily by being able to read what the errors and fixing them. Lastly, learning how to do the try-except statement lets the code run even if there are some errors that you might not necessarily know how to fix at the moment.

Tuesday, May 27, 2025

Module 2: Python Fundamentals

 Module 2: Python Fundamentals

This weeks module was focused on the fundamentals of how to use Python within ArcGIS Pro. The focus was on using strings or text to write our names, fixing code that was previously written, writing loop statements, and removing numbers from previous generated code.

When doing string code it is important to put quotation marks around the words that you want to print. Also, when using string we tried indexing, where is the system of numbering a sequence of characters and can be used to fetch elements within a string. we are able to do this either through words in double quotation marks or lists with single quotation marks. Lists can be either be text or numbers. Lastly, I needed to just get my last name out of the list which is splicing. For this code the best way was to put -1 to get the last name out.

Next part of the module was fixing code that was already given to us. There were two errors that needed to be fixed and to start you want to run the code to see where the first problem was located. The first part that came up was that randint did not have the correct input. This code is considered a conditional statement and before it can run you need to import random before using random.randint. The second error was in the print portion of the code. It said that you cannot have both integers and strings in the print portion. So I needed to either make them all string or all integers. I had to do all string because the last portion could not be an integer. I had to put the integers in str() to get the code to work properly. After fixing that portion of the code it worked and showed the statement for each of the players.

The next portion of the code was creating a while loop statement. We were supposed to create a loop that creates 20 random numbers between 0-10. This code is similar to the one that was given to us but we needed to make sure the statement was empty and that the counter is 0. The while loop is based off a condition that was given to the code which was less than 20. Once again I needed to import random so that I could create random.randint (0, 10). In order to get the random numbers printed I needed to use the code .append(). Also, to make sure the code does not do it continuously and actually produces the numbers you need to add break before the print portion of the code.

Lastly, the last portion of the code was to chose a number that was going to be removed from the previous list that was generated. I used a for loop statement so I could get the if-else statement to determine if the number was in the generated list. Lastly, in this portion I had to use .remove() to get the number taken out of the generated list. It is important to note that the numbers are taken out of the list is done one at a time. The picture below shows the answers for all the code that was written.


Throughout all the different portions of the code there were some things that I learned which were make sure before running the loop structures code that you have a stop (break) statement. I did not have that and it caused ArcGIS Pro to crash and I had to close out of everything before I could get the code to run again. Also, make sure to do the exercise before anything and take notes that you can reference when doing the module. When doing steps 3 and 4 I needed to make sure that step 4 linked back to step 3 so that the numbers were connected. Lastly, when the numbers are being removed it is done one at a time. I think if you wanted all the numbers to be taken away at once it would be good to use the delete function.

This is the flowchart of the script that was written.



Saturday, May 17, 2025

Module 1: Python Environments and Flowcharts

 Module 1: Python Environments and Flowcharts

In this weeks lab we were learning about the basics of Python, Flowcharts, and create file paths for our work for the next 8 weeks.

Python is a programming language that is both simple and powerful. This is important because it makes it easy to learn compared to other programs, such as C++. Also, Python is considered interpreted which means that Python is interpreted or “interacted” during the time the script is being run. This is important because you can create the script you want, and it will immediately interact with Python. Also, it means it does not need compilation to binary code before you run it. Which means you can run the program directly from the source code. When using Python there are two ways you can write code that can interact with ArcGIS Pro, which are Integrated DeveLopment Environment (IDLE) and Notebooks. The difference between IDLE and ArcGIS Notebooks is that IDLE indirectly interacts with Python whereas ArcGIS Notebooks directly interacts with Python. Also, Notebooks can contain more than just code and can contain regular text, images, external links, and other elements. Whereas, IDLE contains only code and regular text that are comments. The two Python tools share in common are when you create and write script it will interact with the Python Command Prompt. Also, if you right-click on Python script you can edit IDLE within ArcGIS Pro which you can do with Notebooks.

Another aspect that we learned this week was Flowcharts, which uses symbols and shapes to represent an algorithm. This algorithm is created before it is put into Python to write the script. The symbols that are used for flowcharts comes from reading by Agarwal et al. (2010). Being able to know the common symbols is helpful because everyone will know what it being represented. This week we were supposed to make flowchart of a basic formula to convert radians to degrees, which is represented in the image below. This is important because it shows how you thought the script through before putting it into Python.



Lastly, in this weeks lab we were supposed to take an already written python script to create folders in our S: Drive for this class. First, I opened Python Command Prompt and typed in idle to open the idle interactive window. Second, within the IDLE window I opened CreateModFolders.py script. Third, it opened the script, but it did not immediately add the folders to my S Drive. I was confused at first and was not sure what to do next. That is when I went to the exercise and was able to figure out what I needed to do. Fourth, I went to the Run tab and clicked Run Module, and it opened that it was completed. Fifth, I opened the S Drive, and the folder was finally installed. Being able to work through the issues were important because I have not done Python before and it gave me an opportunity to learn more about the program.

Friday, May 2, 2025

Module 7: Google Earth

 Module 7: Google Earth

This weeks module is about using Google Earth and knowing how to show data through an interactive 3D map. One of the best things about Google Earth is that the data is free and can be used by everyone who is able to download the app on their computer. Much of the maps we created in this class are from ArcGIS Pro and using Google Earth is important to give data to the average person. 

It is important to note that the data that is used in Google Earth are KMZ/KML files. The data that is used in ArcGIS Pro are either feature classes or layers. The first step before using Google Earth is converting the data to KMZ/KML files. Once the data is converted it can be opened up in Google Earth. Also, in this module we learned how to use a png or jpeg file to image overlay the image onto the map. For this map it was a legend and we need to make sure the colors in the legend matched the colors on the map before getting converted to KMZ/KML files. The map below showed how all the data is able to be put within Google Earth and give it easily to other people who have Google Earth on their computer. The reason that is important is because ArcGIS Pro is expensive and people cannot always use that data to make maps in the future.


In the module we were able to learn how to create a Google Earth Tour to show all the information of the dot density map and the landscape. First we needed to create placemarks in dense areas in southern Florida, such as Miami, Fort Lauderdale, Tampa Bay, and St. Petersburg. To make the video we needed to turn off the names of the placemarks but could still use it for the 3D tour. A pro for using Google Earth is that there are some areas that were more photorealistic because there had been more data collected. An example is how Tampa looks more photorealistic because it is using LiDAR data whereas Fort Lauderdale was likely manually put in and does not look as realistic. In order to make the Tour you need to press the "Record a Tour" button and make sure to press the red record button. To zoom into the placemark areas you need to double-click the placemark and it will zoom into that area. When done you need to press the red record button again to stop the tour. When you save the tour you need to make sure to save as a kmz file so that it can be given to anyone with Google Earth on there computer.

This module is very important to learn because the data can be given to people who have Google Earth on their computer. Also, Google Earth is free and people are able to get a lot of information without having to pay a lot of money. Since ArcGIS Pro is very expensive, Google Earth is definitely a cheaper option.

Blog Post #5: GIS Portfolio

 Blog Post #5: GIS Portfolio In the final weeks for the GIS Internship we were given the task of creating a GIS portfolio either on paper or...