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

refactor(crs): provide support without pyproj, other deprecations #1850

Merged
merged 2 commits into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 15 additions & 18 deletions .docs/Notebooks/modelgrid_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@

# set reference infromation
modelgrid1.set_coord_info(
xoff=xoff, yoff=yoff, angrot=angrot, epsg=epsg, proj4=proj4
xoff=xoff, yoff=yoff, angrot=angrot, crs=epsg
)

print("After: {}".format(modelgrid1))
Expand Down Expand Up @@ -213,9 +213,8 @@
# - `botm` : Array of layer Botm elevations
# - `idomain` : An ibound or idomain array that specifies active and inactive cells
# - `lenuni` : Model length unit integer
# - `epsg` : epsg code of model coordinate system
# - `proj4` : proj4 str describining model coordinate system
# - `prj` : path to ".prj" projection file that describes the model coordinate system
# - `crs` : either an epsg integer code of model coordinate system, a proj4 string or pyproj CRS instance
# - `prjfile` : path to ".prj" projection file that describes the model coordinate system
# - `xoff` : x-coordinate of the lower-left corner of the modelgrid
# - `yoff` : y-coordinate of the lower-left corner of the modelgrid
# - `angrot` : model grid rotation
Expand Down Expand Up @@ -358,9 +357,8 @@
# - `botm` : Array of layer Botm elevations
# - `idomain` : An ibound or idomain array that specifies active and inactive cells
# - `lenuni` : Model length unit integer
# - `epsg` : epsg code of model coordinate system
# - `proj4` : proj4 str describining model coordinate system
# - `prj` : path to ".prj" projection file that describes the model coordinate system
# - `crs` : either an epsg integer code of model coordinate system, a proj4 string or pyproj CRS instance
# - `prjfile` : path to ".prj" projection file that describes the model coordinate system
# - `xoff` : x-coordinate of the lower-left corner of the modelgrid
# - `yoff` : y-coordinate of the lower-left corner of the modelgrid
# - `angrot` : model grid rotation
Expand Down Expand Up @@ -476,9 +474,8 @@ def load_iverts(fname):
# - `idomain` : An ibound or idomain array that specifies active and inactive cells
# - `lenuni` : Model length unit integer
# - `ncpl` : one dimensional array of number of cells per model layer
# - `epsg` : epsg code of model coordinate system
# - `proj4` : proj4 str describining model coordinate system
# - `prj` : path to ".prj" projection file that describes the model coordinate system
# - `crs` : either an epsg integer code of model coordinate system, a proj4 string or pyproj CRS instance
# - `prjfile` : path to ".prj" projection file that describes the model coordinate system
# - `xoff` : x-coordinate of the lower-left corner of the modelgrid
# - `yoff` : y-coordinate of the lower-left corner of the modelgrid
# - `angrot` : model grid rotation
Expand Down Expand Up @@ -579,7 +576,7 @@ def load_iverts(fname):
xoff=622241.1904510253,
yoff=3343617.741737109,
angrot=15.0,
proj4="+proj=utm +zone=14 +ellps=WGS84 +datum=WGS84 +units=m +no_defs",
crs="+proj=utm +zone=14 +ellps=WGS84 +datum=WGS84 +units=m +no_defs",
)
# -

Expand Down Expand Up @@ -620,7 +617,7 @@ def load_iverts(fname):
# - `angrot_radians` : returns the angle of rotation of the modelgrid in radians
# - `epsg` : returns the modelgrid epsg code if it is set
# - `proj4` : returns the modelgrid proj4 string if it is set
# - `prj` : returns the path to the modelgrid projection file if it is set
# - `prjfile` : returns the path to the modelgrid projection file if it is set

# Access and print some of these properties
print(
Expand Down Expand Up @@ -723,8 +720,8 @@ def load_iverts(fname):
# - `xoff` : lower-left corner of modelgrid x-coordinate location
# - `yoff` : lower-left corner of modelgrid y-coordinate location
# - `angrot` : rotation of model grid in degrees
# - `epsg` : epsg code for model grid projection
# - `proj4` : proj4 string describing the model grid projection
# - `crs` : either an epsg integer code of model coordinate system, a proj4 string or pyproj CRS instance
# - `prjfile` : path to ".prj" projection file that describes the model coordinate system
# - `merge_coord_info` : boolean flag to either merge changes with the existing coordinate info or clear existing coordinate info before applying changes.

# +
Expand Down Expand Up @@ -900,15 +897,15 @@ def load_iverts(fname):
# Method to write a shapefile of the grid with just the cellid attributes. Input parameters include:
#
# - `filename` : shapefile name
# - `epsg` : optional epsg code of the coordinate system projection
# - `prj` : optional, input projection file to be used to define the coordinate system projection
# - `crs` : either an epsg integer code of model coordinate system, a proj4 string or pyproj CRS instance
# - `prjfile` : path to ".prj" projection file that describes the model coordinate system

# +
# write a shapefile
shp_name = os.path.join(gridgen_ws, "freyberg-6_grid.shp")
epsg = "32614"
epsg = 32614

ml.modelgrid.write_shapefile(shp_name, epsg)
ml.modelgrid.write_shapefile(shp_name, crs=epsg)
# -

try:
Expand Down
10 changes: 5 additions & 5 deletions .docs/Notebooks/shapefile_export_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
# the coordinate information where the grid is located in a projected coordinate system (e.g. UTM)

grid = m.modelgrid
grid.set_coord_info(xoff=273170, yoff=5088657, epsg=26916)
grid.set_coord_info(xoff=273170, yoff=5088657, crs=26916)

grid.extent

Expand Down Expand Up @@ -142,7 +142,7 @@
# ##### write the shapefile

fname = "{}/bcs.shp".format(outdir)
recarray2shp(spd.to_records(), geoms=polygons, shpname=fname, epsg=grid.epsg)
recarray2shp(spd.to_records(), geoms=polygons, shpname=fname, crs=grid.epsg)

ax = plt.subplot(1, 1, 1, aspect="equal")
extents = grid.extent
Expand Down Expand Up @@ -172,7 +172,7 @@
geoms = [Point(x, y) for x, y in zip(welldata.x_utm, welldata.y_utm)]

fname = "{}/wel_data.shp".format(outdir)
recarray2shp(welldata.to_records(), geoms=geoms, shpname=fname, epsg=grid.epsg)
recarray2shp(welldata.to_records(), geoms=geoms, shpname=fname, crs=grid.epsg)
# -

ax = plt.subplot(1, 1, 1, aspect="equal")
Expand Down Expand Up @@ -206,7 +206,7 @@
rivdata.to_records(index=False),
geoms=lines,
shpname=lines_shapefile,
epsg=grid.epsg,
crs=grid.epsg,
)
# -

Expand Down Expand Up @@ -241,7 +241,7 @@
linesdata.drop("geometry", axis=1).to_records(),
geoms=linesdata.geometry.values,
shpname=lines_shapefile,
epsg=grid.epsg,
crs=grid.epsg,
)

ax = plt.subplot(1, 1, 1, aspect="equal")
Expand Down
8 changes: 6 additions & 2 deletions autotest/test_export.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,8 +328,12 @@ def test_write_gridlines_shapefile(function_tmpdir):
outshp = function_tmpdir / "gridlines.shp"
write_gridlines_shapefile(outshp, sg)

for suffix in [".dbf", ".prj", ".shp", ".shx"]:
for suffix in [".dbf", ".shp", ".shx"]:
assert outshp.with_suffix(suffix).exists()
if has_pkg("pyproj"):
assert outshp.with_suffix(".prj").exists()
else:
assert not outshp.with_suffix(".prj").exists()

with shapefile.Reader(str(outshp)) as sf:
assert sf.shapeType == shapefile.POLYLINE
Expand Down Expand Up @@ -991,7 +995,7 @@ def test_polygon_from_ij_with_epsg(function_tmpdir):
fpth2 = os.path.join(ws, "26715.prj")
shutil.copy(fpth, fpth2)
fpth = os.path.join(ws, "test.shp")
recarray2shp(recarray, geoms, fpth, prj=fpth2)
recarray2shp(recarray, geoms, fpth, prjfile=fpth2)

# test_dtypes
fpth = os.path.join(ws, "test.shp")
Expand Down
Loading