From Open Foris Wiki

Jump to: navigation, search

This python creates shapefile polygons of text files.

Usage: python CsvToPolygon.py <input.csv> <output.shp>

E.g.: python CsvToPolygon.py combined.csv training_sites164064.shp

  • The program is modified form the one by Chris Garrard: http://www.gis.usu.edu/~chrisg/python/2009/lectures/ospy_hw2a.py
  • It takes as input a text file of the following format: Polygon id, land cover class, land cover subclass, tree cover class, resolution of the image in GE (Google Earth}, year and month of image in GE. After the ":" mark there are corner coordinates in WGS84 system.
  • This input data is output from another script, GExml2csv.bash and originally derives from a training data collection tool created for GE.


  • Get Example data set
  • For this exercise following tools are used: CsvToPolygon.py
  • Open your working directory using
cd /home/...

An example of the beginning of input data is following:

106,OWL,OWL_Open,2,Coarse,2002/1:-5.47450324983224 32.54081338469396,-5.47450324983224 32.5417154317423,-5.47540856036825 32.5417154317423,-5.47540856036825 32.54081338469396

107,Grassland,Grassland_Bushed,1,Coarse,2002/1:-5.47456561893842 32.63108751846197,-5.47456561893842 32.63198971163985,-5.47547080384603 32.63198971163985,-5.47547080384603 32.63108751846197

108,Bushland,Bushland_Thicket,2,Medium,2002/10:-5.47461439045748 32.72136258245697,-5.47461439045748 32.72226491949511,-5.47551944746972 32.72226491949511,-5.47551944746972 32.72136258245697

python CsvToPolygon.py inputdata.csv output.shp

Back to Open Foris Toolkit Main Page

Back to Tools & Exercises

Personal tools