def hasPath(self, i, j): i # watchvar i j # watchvar j n, m = len(self.matrix), len(self.matrix[0]) helper.dbg(self.dp + [i, j]) # Function call to debug if i >= n or i < 0 or j >= m or j < 0: # Out of bounds return False if self.matrix[i][j] == 0: self.dp[i][j] = 3 return False if self.dp[i][j] == 1: # Gray return False if self.dp[i][j] == 3: return False if self.dp[i][j] == 4: return True ans = False self.dp[i][j] = 1 right = self.hasPath(i + 1, j) left = self.hasPath(i - 1, j) up = self.hasPath(i, j + 1) down = self.hasPath(i, j - 1) ans = right or left or down or up self.dp[i][j] = 4 if ans else 3 return ans
def mapserver(params,mapfile): """ Function implementing mapserver functionality. params: dictionary of query string of a mapserver GET request mapfile: path to mapfile returns: tuple with content type and response body """ helper.dbg("creating map for: " + mapfile) request = mapscript.OWSRequest() #request.loadParams() for k in params: #helper.dbg( "%s : %s" % (k,params[k])) request.setParameter(k,params[k]) # change the style INSPIRE:DEFAULT back to an empty string otherwise Mapserver will complain styles = request.getValueByName('STYLES') if (styles is not None and styles.count(default_style) > 0): styles = styles.replace(default_style, "") request.setParameter("STYLES", styles) style = request.getValueByName('STYLE') if style == default_style: request.setParameter("STYLE", "") map = mapscript.mapObj( mapfile ) mapscript.msIO_installStdoutToBuffer() map.OWSDispatch( request ) content_type = mapscript.msIO_stripStdoutBufferContentType() content = mapscript.msIO_getStdoutBufferBytes() operation = request.getValueByName('REQUEST') version = request.getValueByName('VERSION') if (version == '1.3.0' or version is None) and operation.upper() == 'GETCAPABILITIES': content = altercapabilities(content, namespace, prefix, schemaLocation, language) #response = 'Content-type: %s\n%s' % (content_type,content) return [content_type, content]
def _savefile( self ): """ save the user supplied file under the data directory """ # create uuid-based directory helper.dbg("Creating dir: " + self.extractdir) os.mkdir(self.extractdir, 0770) # save zipfile under that dir f = open ( self.zfilepath, "w" ) f.write(self.zfiledata.read()) f.close()
def savemap( self, wms_url ): """ Generate a mapfile based on user data. The mapfile's name is based on the uuid associated to the request pdata: list of dictionaries returned from from ogrprobe returns: path to mapfile relative to mapfile_base_dir in config.ini """ mapfileStr = helper.createMapfile( wmsname = self.zfilename, wmsurl = wms_url, extent= self.wms_md["extent"], units = 'METERS', wms = self) self.mapfile = os.path.join(configuration.getMapfileDir() , self.uuid + ".map") f = open(self.mapfile, "w") f.write(mapfileStr) f.close() helper.dbg("Wrote Mapfile: " + self.mapfile)
def saveconf( self ): if ( (self.rasters == None) and (self.vectors == None) ): raise IOError("Trying to save null data!") metadata_file = open(os.path.join ( self.extractdir, 'metadata.json' ), 'w') metadata={} metadata["rasters"] = self.rasters metadata["vectors"] = self.vectors metadata["ip"] = self.ip metadata["datasetname"] = self.datasetname metadata["zfilename"] = self.zfilename metadata["time"] = self.time metadata["protected"] = self.protected metadata["wms_md"] = self.wms_md json.dump(metadata, metadata_file) metadata_file.close() helper.dbg("saved metadata")
def loadFromFile(self, uuid): """ Create a wms based on saved configuration. uuid: the uuid corresponding to the saved wms instance @exceptions: file does not exist, parse error """ self.uuid = uuid self.extractdir = os.path.join (configuration.getDataDir(), self.uuid) helper.dbg("loading saved uuid: " + self.uuid) metadata_file = open(os.path.join ( self.extractdir, 'metadata.json' ), 'r') metadata = json.load( metadata_file ) metadata_file.close() if metadata == None: raise ValueError("Cannot parse metadata.json for uuid: " + uuid) self.rasters = metadata["rasters"] self.vectors = metadata["vectors"] self.layers = self.rasters + self.vectors self._addlayersid() self.ip = metadata["ip"] self.datasetname = metadata["datasetname"] self.zfilename = metadata["zfilename"] self.zfilepath = os.path.join (self.extractdir, self.zfilename) self.time = metadata["time"] self.protected = metadata["protected"] self.wms_md = metadata["wms_md"] helper.dbg("Loaded RASTERS: " + `self.rasters`) helper.dbg("Loaded VECTORS: " + `self.vectors`)
def loadFromWeb(self, ip, uploadFilename, uploadFile): """ Create a wms based on a uploaded zip file. ip: remote address uploadFilename: upload user name of file (string) uploadFile: uploaded user file (file pointer made available by WSGI server) """ helper.dbg("Filename was: " + uploadFilename ) self.ip = ip self.uuid = uuid.uuid4().hex self.zfilename = uploadFilename self.zfiledata = uploadFile self.extractdir = os.path.join (configuration.getDataDir(), self.uuid) self.zfilepath = os.path.join (self.extractdir, self.zfilename) self.time = time.strftime('%d%m%y-%H:%M:%S') self._savefile() self.rasters = [] # list of probe results for rasters self.vectors = [] # list of probe results for vectors f = geozip.GeoZip(self.zfilepath) if f.check_integrity() == False: raise IOError("Checksum error: zipfile is corrupted") #extract all files under extractdir f.extract(self.extractdir) #group by name f.group_files() #probe all the properties of geotiffs self.rasters = [ helper.probedata(x) for x in f.getGeoTiffFiles() ] self.vectors = [ helper.probedata(x) for x in f.getShapeFiles() ] helper.dbg("Extracted RASTERS: " + `self.rasters`) helper.dbg("Extracted VECTORS: " + `self.vectors`) self.datasetname = helper.getBaseName(self.zfilename) self.layers = self.rasters + self.vectors self._addlayersid() self.wms_md = { "title": self.datasetname , "Language" : "ENG", "Keywords":"IGIBS, View Service", "Fees": "N/A", "protected": self.protected, "extent": [ -7.55645, 49.76688, 3.6342, 61.465701 ], "projection" : "epsg:4326" } helper.dbg("DatasetName: " + `self.datasetname`) helper.dbg("zfilename: " + `self.zfilename`)