~meshing/meshing/urop

« back to all changes in this revision

Viewing changes to shape/shp-geo.py

  • Committer: Adam Candy
  • Date: 2012-07-06 15:30:52 UTC
  • Revision ID: adam.candy@imperial.ac.uk-20120706153052-63q7bbtir43ts2vp
Import of Varun's branch lp:~varun-verma11/+junk/gshhstoshp into the folder 'shape'.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Take in the shapefile given and convert to .geo file.
 
2
 
 
3
import shapefile
 
4
import matplotlib.pyplot as pyplot
 
5
 
 
6
# Read .shp file.
 
7
r = shapefile.Reader("large-area")
 
8
 
 
9
# Take in the shape info of the objects.
 
10
shapes = r.shapes()
 
11
print shapes[0].points
 
12
 
 
13
for j in range(len(shapes[0].parts)-1):
 
14
        x = []; y = []
 
15
        for i in range(shapes[0].parts[j], shapes[0].parts[j + 1]):
 
16
                x.append(shapes[0].points[i][0]);       y.append(shapes[0].points[i][1])
 
17
                pyplot.plot(x, y)
 
18
 
 
19
 
 
20
x = []; y = []
 
21
for i in range(shapes[0].parts[0], shapes[0].parts[1]):
 
22
        x.append(shapes[0].points[i][0]);       y.append(shapes[0].points[i][1])
 
23
        pyplot.plot(x, y)
 
24
 
 
25
pyplot.show()
 
26
 
 
27
 
 
28
"""
 
29
# Arbitrarily pick the 4th entry.
 
30
#Write the .geo file from the data read.
 
31
target = open("python.geo", "w") # Creates python.geo file to write to.
 
32
for i in range(len(shapes[3].points)):
 
33
        target.write('Point(%d) = {%.3f, %.3f, 0, %.3f};\n' %(i + 1, shapes[3].points[i][0], shapes[3].points[i][1], 1.0))
 
34
target.close()
 
35
"""