GIS 4653/5653: Spatial Programming and GIS
GIS 4653/5653: Spatial Programming and GIS
Now what?
Looking at headers
Which field number is the FULLNAME field?
Make sure …
http://pcjericks.github.io/py-gdalogr-cookbook/geometry.html
Desired output
We want this output
Circles of 420km radius centered around each radar in
Oklahoma
Writing a shapefile from scratch
To write a shapefile from scratch using OGR:
Get driver
Create datasource
Create layer
Create fields (you need at least one field)
For each polygon:
Make polygon (or whatever geometry)
Create a feature and set the fields and geometry on it
Provide the feature to the layer
Destroy the feature
When done, destroy the datasource
Also create a .prj file
Preliminaries
Datasource, layer, field definition
Circles
Shapefiles do not have circle support
Only points, lines and polygons
How would you get a circle?
Approximating a circle
Can approximate a circle by a polygon with lots of sides
A polygon consists of 1 or more linear rings (to account for
holes)
Each ring needs to be closed
Location of point given bearing
The location of a point given a bearing and distance is:
http://www.movable-type.co.uk/scripts/latlong.html
In Python, remember to convert angles to radians:
Writing the shapefile
Spatial reference
Full code
The full code is at writeradars.py
Buffering
To buffer a geometry, simply call the Buffer() function
Let us buffer all the named lakes
Steps:
Read input file containing all the water bodies
Open output file with same geometry type as input
Copy the field definitions from the input to the output
For each feature in the input that has a name and is not a river
Buffer by 0.0005 (the units are units of the input file, so degrees)
Write out buffered geometry into output file
Clean up
Reading input
Should be familiar:
Creating output
Should also be familiar: