Skip to content

Commit

Permalink
dummy projection bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
jonschwenk authored May 27, 2020
1 parent 021a73e commit 9f4b916
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
7 changes: 3 additions & 4 deletions rivgraph/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,24 +90,23 @@ def __init__(self, name, path_to_mask, results_folder=None, exit_sides=None, ver

# Get or create georeferencing info
self.mask_path = path_to_mask
self.gdobj = gdal.Open(self.mask_path)
self.gdobj = gdal.Open(self.mask_path, gdal.GA_Update)
self.imshape = (self.gdobj.RasterYSize, self.gdobj.RasterXSize)

if self.gdobj.GetProjection() == '':
print('Input mask is unprojected; assigning a dummy projection.')
# Creates a dummy projection in EPSG:4326 with UL coordinates (0,0)
# and pixel resolution = 1.
self.gt = (0, 1, 0, 0, 0, -1)
self.wkt = 'GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.01745329251994328,AUTHORITY["EPSG","9122"]],AUTHORITY["EPSG","4326"]]' # 4326
self.epsg = 4326
self.unit = 'pixel'
self.gdobj.SetProjection(self.wkt)
self.gdobj.SetGeoTransform(self.gt)
self.gdobj.SetGeoTransform((0, 1, 0, self.imshape[1], 0, -1))
else:
self.gt = self.gdobj.GetGeoTransform()
self.wkt = self.gdobj.GetProjection()
self.epsg = gu.get_EPSG(self.gdobj)
self.unit = gu.get_unit(self.epsg)
self.gt = self.gdobj.GetGeoTransform()

self.pixarea = abs(self.gt[1] * self.gt[5])
self.pixlen = abs(self.gt[1])
Expand Down
1 change: 0 additions & 1 deletion rivgraph/ln_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,6 @@ def links_to_gpd(links, gdobj):
# Append geometries
geoms = []
for i, lidx in enumerate(links['idx']):

coords = gu.idx_to_coords(lidx, gdobj)
geoms.append(shp.geometry.LineString(zip(coords[0], coords[1])))
links_gpd['geometry'] = geoms
Expand Down

0 comments on commit 9f4b916

Please sign in to comment.