Skip to content

Commit 745f869

Browse files
committed
Update readboundaries to use the format that basemap expects
Previously, only readboundaries_shp.py actually wrote data in a format that basemap could read. It looks like readboundaries.py has not actually been used to produce boundary data in a _very_ long time. Instead, it's been produced from the GSHHS shapefiles.
1 parent d7c981a commit 745f869

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

utils/readboundaries.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,14 @@ def get_coast_polygons(coastfile):
2525
polymeta = []; polybounds = []
2626
lats = []; lons = []
2727
for line in open(coastfile):
28-
if line.startswith('#'): continue
29-
linesplit = line.split()
30-
if line.startswith('P'):
31-
area = float(linesplit[5])
32-
west,east,south,north = float(linesplit[6]),float(linesplit[7]),float(linesplit[8]),float(linesplit[9])
33-
typ = int(linesplit[3])
34-
polymeta.append((typ,area,south,north))
28+
if line.startswith('#'):
29+
continue
30+
linesplit = line.strip().split()
31+
if line.startswith('>'):
32+
area, west, east, south, north = map(float, linesplit[5:10])
33+
poly_id = linesplit[-1]
34+
level = linesplit[3]
35+
polymeta.append([level,area,south,north,poly_id])
3536
if lons:
3637
#lons.append(lons[0]); lats.append(lats[0])
3738
b = numpy.empty((len(lons),2),numpy.float32)
@@ -41,8 +42,8 @@ def get_coast_polygons(coastfile):
4142
polybounds.append(b)
4243
lats = []; lons = []
4344
continue
44-
lon = float(line[1:10])
45-
lat = float(line[10:20])
45+
lon = float(linesplit[0])
46+
lat = float(linesplit[1])
4647
lons.append(lon); lats.append(lat)
4748
#lons.append(lons[0]); lats.append(lats[0])
4849
b = numpy.empty((len(lons),2),numpy.float32)
@@ -53,7 +54,7 @@ def get_coast_polygons(coastfile):
5354
polymeta2 = []
5455
for meta,bounds in zip(polymeta,polybounds):
5556
npts = bounds.shape[0]
56-
polymeta2.append(meta+(npts,))
57+
polymeta2.append(meta[:-1] + [npts] + [meta[-1]])
5758
return polybounds, polymeta2
5859

5960
def get_boundary_lines(bdatfile):
@@ -106,7 +107,8 @@ def get_boundary_lines(bdatfile):
106107
bstring = p.tostring()
107108
f.write(bstring)
108109
typ = pm[0]; area = pm[1]; south = pm[2]; north = pm[3]; npts = pm[4]
109-
f2.write('%s %s %s %9.5f %9.5f %s %s\n' % (typ, area, npts, south, north, offset, len(bstring)))
110+
poly_id = pm[5]
111+
f2.write('%s %s %s %9.5f %9.5f %s %s %s\n' % (typ, area, npts, south, north, offset, len(bstring), poly_id))
110112
offset = offset + len(bstring)
111113
f.close()
112114
f2.close()

0 commit comments

Comments
 (0)