Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SFR exports shapefile incorrectly #816

Closed
andyrich opened this issue Feb 26, 2020 · 3 comments
Closed

SFR exports shapefile incorrectly #816

andyrich opened this issue Feb 26, 2020 · 3 comments

Comments

@andyrich
Copy link

andyrich commented Feb 26, 2020

When trying to export sfr, the locations of the cells do not overlap model grid. The dis grid retains the modelgrid coordinates but the sfr grid does not.

`
from flopy.utils.reference import SpatialReference
from flopy.discretization.structuredgrid import StructuredGrid
import flopy
from platform import python_version
print(f'python version: {python_version()}')

print(f'flopy version: {flopy.version}')
delr, delc = np.ones((157))*660, np.ones((168))*660
xul = 6306015.91393092
yul = 1982413.68616024
sr = SpatialReference(delr=delr, delc=delc, xul=xul, yul=yul, units='feet',
proj4_str='EPSG:2226', rotation=0 , lenuni = 1, length_multiplier = 1.0 )

#make strurctured grid from model grid above.
mg = StructuredGrid(delc=sr.delc, delr=sr.delr, xoff=sr.xll, yoff=sr.yll, angrot=0,
epsg=2226, lenuni=1)

ml = flopy.modflow.Modflow.load('SRP_mf.nam',load_only = ['DIS','BAS6','SFR'], model_ws=workspace,verbose =False)
ml.modelgrid = mg

print('exporting dis')
ml.dis.export('GIS\ml_dis.shp',epsg=2226)
print('exporting sfr')
ml.sfr.export('GIS\ml_sfr.shp',epsg=2226)

import geopandas as gpd
dis = gpd.read_file('GIS\ml_dis.shp')
ax = dis.plot()
ax.set_title('dis')
sf = gpd.read_file('GIS\ml_sfr.shp')
ax = sf.plot()
ax.set_title('sfr')

print(f'the total bounds for dis shapefile is: {dis.geometry.total_bounds}')
print(f'the total bounds for sfr shapefile is: {sf.geometry.total_bounds}')
`
image

inputs.zip

@jlarsen-usgs
Copy link
Contributor

@andyrich

I can take a look at this. It looks like modelgrid information is not getting passed properly to the export routine for sfr.

@jlarsen-usgs
Copy link
Contributor

@andyrich

Just submitted a PR to fix this issue.

If you'd like to avoid building a SpatialReference and then StructuredModelGrid object from scratch you could use this code snippet instead to set the coordinate info of the modelgrid that is automatically built when you load in your DIS and BAS file:

xul = 6306015.91393092
yul = 1982413.68616024

xll = ml.modelgrid._xul_to_xll(xul)
yll = ml.modelgrid._yul_to_yll(yul)
ml.modelgrid.set_coord_info(xoff=xll, yoff=yll, epsg=2226)

@andyrich
Copy link
Author

Thanks josh!
@jlarsen-usgs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants