コード例 #1
0
    def ingestShapefiles( self ):
		''' 
            Ingest any shapefiles in the coverage directory.
            
            Store in a dict keyed by dataset name and use this data instead of .vp files.
		'''
		for root, dirs, files in os.walk( self.version_location ):
			for aFile in files:
				if aFile.find( ".shp" ) < 0:
					continue
					
				try:
					LOG.debug( " ingestShapefiles %s " % ( os.path.join( root, aFile ) ) )
					objShapeReader	= shapefile.Reader( os.path.join( root, aFile ) )
			
					shapeRecs 		= objShapeReader.shapeRecords()
					
					LOG.debug( " ingestShapefiles %s shape record count is %0d" % ( os.path.join( root, aFile ), len( shapeRecs ) ) )
					
					for aShapeRec in shapeRecs:
						if not self.dictDatasets.has_key( aShapeRec.record[0] ):
							objDataset = MQDataSet( aShapeRec.record[0], 90.0, -180.0, -90.0, 180.0, 0, 100000000, {} )
							self.dictDatasets[ aShapeRec.record[0] ] = objDataset
						else:
							objDataset = self.dictDatasets[ aShapeRec.record[0] ]

						objDataset.importShapefileRecord( self.version_location, aShapeRec )
						
				except:
					LOG.debug( "Exception in importShapefile " + traceback.format_exc() )
					return False
    		
		return True					
コード例 #2
0
    def process_coverage_data(self, xml_data, coord_base_path):
        ''' 
            Processes coverage datasets by iterating through the entries in the XML file.
            XML file is the main controller file that will be used to read the .vp files.
            Only files listed in the xml will be read during processing
        '''
        self.coverage = []
        for priority in xml_data.findall('priorityEntries/priorityEntry'):
            region_name = priority.get('validRegionName')
            data_set_name = ''
        
            # Valid region
            for valid_region in xml_data.findall('validRegions/validRegion'):
                if (0 == cmp(valid_region.get('name'), region_name)):
                    data_set_name = valid_region.get('dataSetName')
                    break
        
            # DataSet
            bnd_ul_lat = 0
            bnd_ul_lng = 0
            bnd_lr_lat = 0
            bnd_lr_lng = 0
        
            # Scale
            scale_lo = 0
            scale_hi = 0
            dictScale = {}
            
            for data_set in xml_data.findall('dataSets/dataSet'):
                
                if (0 == cmp(data_set.get('name'), data_set_name)):
                    ds_name = data_set.get('name')
                    lllist = data_set.findall('latLongBoundingRectangle')
                    #Bounding info
                    if (0 < len(lllist)):
                        for element in lllist:
                            bnd_ul_lat = float(element.get('ul_lat'))
                            bnd_ul_lng = float(element.get('ul_long'))
                            bnd_lr_lat = float(element.get('lr_lat'))
                            bnd_lr_lng = float(element.get('lr_long'))
                    else:
                        bnd_ul_lat = 0
                        bnd_ul_lng = 0
                        bnd_lr_lat = 0
                        bnd_lr_lng = 0
        
                    scalelist = data_set.findall('scaleRange')
                    # scale
                    if (0 < len(scalelist)):
                        for element in scalelist:
                            try:
                            	dictScale[ element.get('proj') ] = { "lo" : int(element.get('lo')), "hi" : int(element.get('hi')) }
                            	scale_lo = int(element.get('lo'))
                            	scale_hi = int(element.get('hi'))
                            except:
                            	scale_lo = int(element.get('lo'))
                            	scale_hi = int(element.get('hi'))
                    else:
                        scale_lo = 0
                        scale_hi = 0
                    break
            
            if (bnd_ul_lat == 0 and bnd_ul_lng == 0 and bnd_lr_lat == 0 and bnd_lr_lng == 0) :
                continue
#
#  Preferentially use the shapefile created dict of datasets as opposed to .vp files
#
            if self.dictDatasets.has_key( ds_name ):
                mq_data_set = self.dictDatasets[ ds_name ]
                LOG.debug( "Pulling ds %s info from shapefile dict, poly count is %s " % ( ds_name, len( mq_data_set.getPolygons() ) ) )
                mq_data_set.setBoundingBox( bnd_ul_lat, bnd_ul_lng, bnd_lr_lat, bnd_lr_lng )
                mq_data_set.setScales( scale_lo, scale_hi, dictScale )
            else:    
                LOG.debug( "Constructing ds %s info " % ( ds_name ) )
                mq_data_set = MQDataSet(ds_name, bnd_ul_lat, bnd_ul_lng, bnd_lr_lat, bnd_lr_lng, scale_lo, scale_hi, dictScale)
                mq_data_set.load_coord_set_list( coord_base_path )
                
            self.coverage.append( mq_data_set )