Skip to content

Commit

Permalink
Updated README.md and update boundary shapefile writer
Browse files Browse the repository at this point in the history
  • Loading branch information
jreniel committed Jan 25, 2020
1 parent 2e9b009 commit 4a557ca
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 7 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,10 @@ from pyschism.mesh import Hgrid
hgrid = Hgrid.open('hgrid.gr3')
hgrid.make_plot(show=True)
```
##### Example 2: Write boundaries to shapefile
```python
# open mesh as
from pyschism.mesh import Hgrid
hgrid = Hgrid.open('hgrid.gr3')
hgrid.write_boundaries("/path/to/output/dir", overwrite=True)
```
4 changes: 0 additions & 4 deletions pyschism/mesh/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -361,10 +361,6 @@ def geom_string(geom_type, geom):
f += f"{-self.values[i]:<.16E}\n"
return f

@property
def geom(self):
return self.pslg.geom

@property
@lru_cache
def grd(self):
Expand Down
6 changes: 5 additions & 1 deletion pyschism/mesh/gmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ def delete_boundary_data(self, ibtype, id):

def write_boundaries(self, path, overwrite=False):
path = pathlib.Path(path)
# print(path)
if path.exists() and not overwrite:
msg = "Destination path exists and overwrite=False"
raise IOError(msg)
with fiona.open(
path.name,
path.absolute(),
'w',
driver='ESRI Shapefile',
crs=self.crs.srs,
Expand Down
4 changes: 2 additions & 2 deletions tests/coverage.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions tests/mesh/test_gmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,5 +250,41 @@ def test_delete_boundary_data(self):
msh.set_boundary_data(None, 0, data)
msh.delete_boundary_data(None, 0)

def test_write_boundaries(self):
tmpdir = tempfile.TemporaryDirectory()
shp = pathlib.Path(tmpdir.name).absolute()
boundaries = {
None: {
0: {
'indexes':
[139510, 140443, 140461, 140462, 141993, 150761]
}
}
}
msh = Gmesh(
self.coords,
self.triangles,
crs="EPSG:3395",
boundaries=boundaries)
msh.write_boundaries(shp, overwrite=True)

def test_write_boundaries_raises(self):
tmpdir = tempfile.TemporaryDirectory()
shp = pathlib.Path(tmpdir.name).absolute()
boundaries = {
None: {
0: {
'indexes':
[139510, 140443, 140461, 140462, 141993, 150761]
}
}
}
msh = Gmesh(
self.coords,
self.triangles,
crs="EPSG:3395",
boundaries=boundaries)
self.assertRaises(IOError, msh.write_boundaries, shp)

if __name__ == '__main__':
unittest.main()

0 comments on commit 4a557ca

Please sign in to comment.