1 / 6

ABT 182 / HYD 182 Environmental Analysis using GIS Week 8-2

ABT 182 / HYD 182 Environmental Analysis using GIS Week 8-2. OOP Object Oriented Programming. import numpy class Extent: def __init__(self, xmn =0, xmx =1, ymn =0, ymx =1): self.xmin = xmn self.xmax = xmx self.ymin = ymn self.ymax = ymx

vivian
Télécharger la présentation

ABT 182 / HYD 182 Environmental Analysis using GIS Week 8-2

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ABT 182 / HYD 182 Environmental Analysis using GIS Week 8-2 OOP Object Oriented Programming

  2. import numpy class Extent: def __init__(self, xmn=0, xmx=1, ymn=0, ymx=1): self.xmin = xmn self.xmax = xmx self.ymin = ymn self.ymax = ymx def setExtent(self, xmn, xmx, ymn, ymx): if xmn >= xmx | ymn >= ymx: print('error; invalid extent') else: self.xmin = xmn self.xmax = xmx self.ymin = ymn self.ymax = ymx def get(self): return( [self.xmin, self.xmax, self.ymin, self.ymax] )

  3. class Spatial(Extent): def __init__(self, xmn=0, xmx=1, ymn=0, ymx=1, crs=None ): self.extent = Extent(xmn, xmx, ymn, ymx) self.crs = crs def extent(self, extent): self.extent = extent def setCRS(self, crs): self.crs = crs def show(self): print 'Extent: ', self.extent.get() print 'Coordinate reference system: ', self.crs

  4. class Raster(Spatial): def __init__(self, xmn=-180, xmx=180, ymn=-90, ymx=90,ncols=1, nrows=1, crs="+proj=longlat +datum=WGS84"): self.spatial = Spatial(xmn, xmx, ymn, ymx, crs) self.crs = crs self.ncol = ncols self.nrow = nrows self.data = None self.cells = self.ncells() self.values = numpy.zeros(cells) def show(self): self.spatial.show() print 'ncols: ', self.ncol print 'nrows: ', self.nrow print 'ncells: ', self.ncells() def ncells(self): return( self.nrow * self.ncol) .. continued on next page ..

  5. def setValues(self, v): if len(v) == self.ncells(): self.values = v else: print 'not good' def add(self, x): self.values += x

  6. r = Raster() r.show() r = Raster(ncols=10, nrows=10) r.show() r.setValues(numpy.zeros(r.cells)) #r.setValues(numpy.arange(100)) print r.sumCells() r.add(10) print r.sumCells()

More Related