/[thuban]/branches/WIP-pyshapelib-bramz/libraries/pyshapelib/pytest.py
ViewVC logotype

Diff of /branches/WIP-pyshapelib-bramz/libraries/pyshapelib/pytest.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/thuban/libraries/pyshapelib/pytest.py revision 1611 by jan, Tue Aug 19 21:24:20 2003 UTC branches/WIP-pyshapelib-bramz/libraries/pyshapelib/pytest.py revision 2734 by bramz, Thu Mar 1 12:42:59 2007 UTC
# Line 5  import shapelib, dbflib, shptree Line 5  import shapelib, dbflib, shptree
5  #  #
6    
7  def make_shapefile(filename):  def make_shapefile(filename):
8        # Create a shapefile with polygons
9        outfile = shapelib.create(filename, shapelib.SHPT_POLYGON)
10    
11        # Create one very simple polygon and write it to the shapefile.  The
12        # vertices should be given in clockwise order to comply with the
13        # shapefile specification.
14      obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, 1,      obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, 1,
15                               [[(10, 10), (20, 10), (20, 20), (10, 10)]])                               [[(10, 10), (10, 20), (20, 20), (10, 10)]])
16      print obj.extents()      print obj.extents()
17      print obj.vertices()      print obj.vertices()
     outfile = shapelib.create(filename, shapelib.SHPT_POLYGON)  
18      outfile.write_object(-1, obj)      outfile.write_object(-1, obj)
19      del outfile  
20        # Create a polygon with a hole.  Note that according to the
21        # shapefile specification, the vertices of the outer ring have to be
22        # in clockwise order and the inner rings have to be in counter
23        # clockwise order.
24        #
25        # There's an optional fourth parameter which when given must be a
26        # list of part types, one for each part of the shape.  For polygons,
27        # the part type is always shapelib.SHPP_RING, though.  The part
28        # types are only relevant for SHPT_MULTIPATCH shapefiles.
29        obj = shapelib.SHPObject(shapelib.SHPT_POLYGON, 1,
30                                 [[(0, 0), (0, 40), (40, 40), (40, 0), (0, 0)],
31                                  [(10, 10), (20, 10), (20, 20), (10, 20),(10, 10)],
32                                  ])
33        print obj.extents()
34        print obj.vertices()
35        outfile.write_object(-1, obj)
36    
37        # close the file.
38        outfile.close()
39    
40  def read_shapefile(filename):  def read_shapefile(filename):
41      # open the shapefile      # open the shapefile

Legend:
Removed from v.1611  
changed lines
  Added in v.2734

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26