GEOG 485:
GIS Programming and Software Development

Lesson 4 Practice Exercise A

PrintPrint

This practice exercise is designed to give you some experience writing geometries to a shapefile. You have been provided two things:

  • A text file MysteryStatePoints.txt containing the coordinates of a state boundary.
  • An empty polygon shapefile that uses a geographic coordinate system.

The objective

Your job is to write a script that reads the text file and creates a state boundary polygon out of the coordinates. When you successfully complete this exercise, you should be able to preview the shapefile in Pro and see the state boundary.

Tips

If you're up for the challenge of this script, go ahead and start coding. But if you're not sure how to get started, here are some tips:

  • In this script, there is no header line to read. You are allowed to use the values of 0 and 1 directly in your code to refer to the longitude and latitude, respectively. This should actually make the file easier to process.
  • Before you start looping through the coordinates, create an empty list (or Array object) to hold all the (x,y) tuples (or Point objects) of your polygon.
  • Loop through the coordinates and create a (x,y) tuple (or Point object) from each coordinate pair. Then add the tuple (or Point object) to your list (or Array object).
  • Once you're done looping, create an insert cursor on your shapefile. Go to the first row and assign your list (or Array) to the SHAPE field.