當前位置: 首頁>>代碼示例>>Python>>正文


Python shp_cabinet.ShpCabinet類代碼示例

本文整理匯總了Python中ocgis.util.shp_cabinet.ShpCabinet的典型用法代碼示例。如果您正苦於以下問題:Python ShpCabinet類的具體用法?Python ShpCabinet怎麽用?Python ShpCabinet使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了ShpCabinet類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _write_

 def _write_(self):
     gid_file = OrderedDict()
     build = True
     is_aggregated = self.ops.aggregate
     with open(self.path,'w') as f:
         ocgis_lh(msg='opened csv file: {0}'.format(self.path),level=logging.DEBUG,
                  logger='conv.csv+')
         writer = csv.writer(f,dialect=OcgDialect)
         for coll in self:
             ocgis_lh('writing collection','conv.csv+',level=logging.DEBUG)
             if build:
                 ocgis_lh('starting build','conv.csv+',level=logging.DEBUG)
                 headers = coll.get_headers(upper=True)
                 if env.WRITE_TO_REFERENCE_PROJECTION:
                     projection = env.REFERENCE_PROJECTION
                 else:
                     projection = coll._archetype.spatial.projection
                 writer.writerow(headers)
                 build = False
                 ocgis_lh(msg='build finished'.format(self.path),level=logging.DEBUG,
                  logger='conv.csv+')
             for geom,row,geom_ids in coll.get_iter(with_geometry_ids=True):
                 if not is_aggregated:
                     ugid = geom_ids['ugid']
                     did = geom_ids['did']
                     gid = geom_ids['gid']
                     if ugid not in gid_file:
                         gid_file[ugid] = OrderedDict()
                     if did not in gid_file[ugid]:
                         gid_file[ugid][did] = OrderedDict()
                     gid_file[ugid][did][gid] = geom
                 writer.writerow(row)
             ocgis_lh('finished writing collection','conv.csv+',level=logging.DEBUG)
     
     if is_aggregated is True:
         ocgis_lh('creating a UGID-GID shapefile is not necessary for aggregated data. use UGID shapefile.',
                  'conv.csv+',
                  logging.WARN)
     else:
         ocgis_lh('writing UGID-GID shapefile','conv.csv+',logging.DEBUG)
         sc = ShpCabinet()
         shp_dir = os.path.join(self.outdir,'shp')
         try:
             os.mkdir(shp_dir)
         ## catch if the directory exists
         except OSError:
             if os.path.exists(shp_dir):
                 pass
             else:
                 raise
         shp_path = os.path.join(shp_dir,self.prefix+'_gid.shp')
         
         def iter_gid_file():
             for ugid,did_gid in gid_file.iteritems():
                 for did,gid_geom in did_gid.iteritems():
                     for gid,geom in gid_geom.iteritems():
                         yield({'geom':geom,'DID':did,
                                'UGID':ugid,'GID':gid})
         
         sc.write(iter_gid_file(),shp_path,sr=projection.sr)
開發者ID:imclab,項目名稱:ocgis,代碼行數:60,代碼來源:csv_.py

示例2: get_shp

def get_shp(request,key=None):
    query = helpers.parse_qs(request.META['QUERY_STRING'])
    
    select_ugid = SelectUgid()
    select_ugid.parse_query(query)
    
    prefix = Prefix()
    prefix.parse_query(query)
    
    unwrap = Unwrap()
    unwrap.parse_query(query)
    
    pm = PrimeMeridian()
    pm.parse_query(query)
    
    sc = ShpCabinet()
    geom_dict = sc.get_geom_dict(key,attr_filter=select_ugid.value)
    
    ## unwrap coordinates if requested
    if unwrap.value:
        unwrap_geoms(geom_dict,pm.value)
    
    dir_path = get_temp_path(nest=True,only_dir=True,wd=env.DIR_OUTPUT)
    if prefix.value is None:
        out_name = key
    else:
        out_name = prefix.value
    filename = '{0}.shp'.format(out_name)
    path = os.path.join(dir_path,filename)
    path = sc.write(geom_dict,path)
    path = os.path.split(path)[0]
    
    resp = helpers._zip_response_(path,filename=filename.replace('shp','zip'))
    return(resp)
開發者ID:aashish24,項目名稱:ocgis,代碼行數:34,代碼來源:views.py

示例3: test_sql_subset

 def test_sql_subset(self):
     sc = ShpCabinet()
     path = sc.get_shp_path('state_boundaries')
     ds = ogr.Open(path)
     ret = ds.ExecuteSQL('select * from state_boundaries where state_name = "New Jersey"')
     ret.ResetReading()
     self.assertEqual(len(ret),1)
開發者ID:tatarinova,項目名稱:ocgis,代碼行數:7,代碼來源:test_shp_cabinet.py

示例4: write

 def write(self,path):
     geoms = []
     uid = self.spatial.uid
     for ii,geom in iter_array(self.spatial.geom,return_value=True):
         geoms.append({'geom':geom,'ugid':uid[ii]})
     sc = ShpCabinet()
     sc.write(geoms,path,sr=self.spatial.projection.sr)
開發者ID:imclab,項目名稱:ocgis,代碼行數:7,代碼來源:geometry.py

示例5: test_calculation_iteration

 def test_calculation_iteration(self):
     field = self.get_field(with_value=True,month_count=2)
     field.variables.add_variable(Variable(value=field.variables['tmax'].value+5,
                                           name='tmin',alias='tmin'))
     field.temporal.name_uid = 'tid'
     field.level.name_uid = 'lid'
     field.spatial.geom.name_uid = 'gid'
     
     grouping = ['month']
     tgd = field.temporal.get_grouping(grouping)
     mu = Mean(field=field,tgd=tgd,alias='my_mean')
     ret = mu.execute()
     
     kwds = copy(field.__dict__)
     kwds.pop('_raw')
     kwds.pop('_variables')
     kwds['temporal'] = tgd
     kwds['variables'] = ret
     cfield = DerivedField(**kwds)
     cfield.temporal.name_uid = 'tid'
     cfield.temporal.name_value = 'time'
     cfield.spatial.name_uid = 'gid'
                     
     sc = ShpCabinet()
     meta = sc.get_meta('state_boundaries')
     sp = SpatialCollection(meta=meta,key='state_boundaries',headers=constants.calc_headers)
     for row in sc.iter_geoms('state_boundaries'):
         sp.add_field(row['properties']['UGID'],row['geom'],cfield.variables.keys()[0],
                      cfield,properties=row['properties'])
     for ii,row in enumerate(sp.get_iter_dict()):
         if ii == 0:
             self.assertEqual(row[0].bounds,(-100.5, 39.5, -99.5, 40.5))
             self.assertDictEqual(row[1],{'lid': 1, 'ugid': 1, 'vid': 1, 'cid': 1, 'did': 1, 'year': 2000, 'time': datetime.datetime(2000, 1, 16, 0, 0), 'calc_alias': 'my_mean_tmax', 'value': 0.44808476666433006, 'month': 1, 'alias': 'tmax', 'variable': 'tmax', 'gid': 1, 'calc_key': 'mean', 'tid': 1, 'level': 50, 'day': 16})
         self.assertEqual(len(row),2)
         self.assertEqual(len(row[1]),len(constants.calc_headers))
開發者ID:UV-CDAT,項目名稱:ocgis,代碼行數:35,代碼來源:test_collection.py

示例6: test_multivariate_iteration

    def test_multivariate_iteration(self):
        field = self.get_field(with_value=True, month_count=1)
        field.variables.add_variable(Variable(value=field.variables['tmax'].value + 5,
                                              name='tmin', alias='tmin'))
        field.temporal.name_uid = 'tid'
        field.level.name_uid = 'lid'
        field.spatial.geom.name_uid = 'gid'

        div = Divide(field=field, parms={'arr1': 'tmin', 'arr2': 'tmax'}, alias='some_division',
                     dtype=np.float64)
        ret = div.execute()

        cfield = DerivedMultivariateField(variables=ret, realization=field.realization, temporal=field.temporal,
                                          level=field.level,
                                          spatial=field.spatial, meta=field.meta, uid=field.uid)
        cfield.spatial.name_uid = 'gid'

        sc = ShpCabinet()
        meta = sc.get_meta('state_boundaries')
        sp = SpatialCollection(meta=meta, key='state_boundaries', headers=constants.HEADERS_MULTI)
        for row in sc.iter_geoms('state_boundaries', as_spatial_dimension=True):
            sp.add_field(cfield, ugeom=row)

        for ii, row in enumerate(sp.get_iter_dict(melted=True)):
            if ii == 0:
                self.assertDictEqual(row[1], {'lid': 1, 'ugid': 1, 'cid': 1, 'did': None, 'year': 2000,
                                              'time': datetime.datetime(2000, 1, 1, 12, 0),
                                              'calc_alias': 'some_division', 'value': 12.989774984574424, 'month': 1,
                                              'gid': 1, 'calc_key': 'divide', 'tid': 1, 'level': 50, 'day': 1})
        self.assertEqual(ii + 1, 2 * 31 * 2 * 3 * 4 * 51)
開發者ID:HydroLogic,項目名稱:ocgis,代碼行數:30,代碼來源:test_collection.py

示例7: test_shp

 def test_shp(self):
     sc = ShpCabinet()
     keys = sc.keys()
     for key in keys:
         url = '/shp/{0}'.format(key)
         resp = self.c.get(url)
         self.assertTrue(len(resp.content) > 100)
開發者ID:aashish24,項目名稱:ocgis,代碼行數:7,代碼來源:tests.py

示例8: test_iter_all

 def test_iter_all(self):
     raise(SkipTest('dev - long'))
     sc = ShpCabinet()
     for key in sc.keys():
         print key
         for geom in sc.iter_geoms(key):
             self.assertTrue(True)
開發者ID:UV-CDAT,項目名稱:ocgis,代碼行數:7,代碼來源:test_shp_cabinet.py

示例9: test_attribute_flags

 def test_attribute_flags(self):
     attr_flags = ['none','all']
     for attr_flag in attr_flags:
         ## make temporary directory
         path = get_temp_path(only_dir=True,nest=True)
         try:
             ## the shapefile key to use
             key = 'state_boundaries'
             ## get path to shapefile and copy directory to temporary location
             sc = ShpCabinet()
             origin = os.path.split(sc.get_shp_path(key))[0]
             shutil.copytree(origin,os.path.join(path,key))
             ## remove original config file
             os.remove(os.path.join(path,key,key+'.cfg'))
             ## write config file
             config = ConfigParser.ConfigParser()
             config.add_section('mapping')
             config.set('mapping','ugid','none')
             config.set('mapping','attributes',attr_flag)
             with open(os.path.join(path,key,key+'.cfg'),'w') as f:
                 config.write(f)
             ## load data
             sc = ShpCabinet(path)
             geoms = sc.get_geoms(key)
             
             for geom in geoms:
                 if attr_flag == 'none':
                     self.assertEqual(set(['ugid','geom']),set(geom.keys()))
                 else:
                     self.assertEqual(set(['ugid', 'state_name', 'state_fips', 'geom', 'state_abbr', 'id']),
                                      set(geom.keys()))
         finally:
             shutil.rmtree(path)
開發者ID:aashish24,項目名稱:ocgis,代碼行數:33,代碼來源:test_ShpCabinet.py

示例10: test_iter_geoms_no_load_geoms

 def test_iter_geoms_no_load_geoms(self):
     sc = ShpCabinet()
     it = sc.iter_geoms('state_boundaries',load_geoms=False)
     geoms = list(it)
     self.assertEqual(len(geoms),51)
     self.assertEqual(geoms[12]['properties']['STATE_NAME'],'New Hampshire')
     for geom in geoms:
         self.assertNotIn('geom',geom)
開發者ID:tatarinova,項目名稱:ocgis,代碼行數:8,代碼來源:test_shp_cabinet.py

示例11: get_collection

 def get_collection(self):
     field = self.get_field(with_value=True)
     sc = ShpCabinet()
     meta = sc.get_meta('state_boundaries')
     sp = SpatialCollection(meta=meta, key='state_boundaries')
     for row in sc.iter_geoms('state_boundaries', as_spatial_dimension=True):
         sp.add_field(field, ugeom=row)
     return sp
開發者ID:HydroLogic,項目名稱:ocgis,代碼行數:8,代碼來源:test_collection.py

示例12: test_unwrap

 def test_unwrap(self):
     sc = ShpCabinet()
     _key = ['state_boundaries','world_countries']
     for key in _key:
         geoms = sc.get_geoms(key,unwrap=True)
         for geom in geoms:
             x = geom['geom'].centroid.x
             self.assertTrue(x > 0)
開發者ID:doutriaux1,項目名稱:ocgis,代碼行數:8,代碼來源:test_ShpCabinet.py

示例13: test_iter_geoms

 def test_iter_geoms(self):
     sc = ShpCabinet()
     it = sc.iter_geoms('state_boundaries')
     geoms = list(it)
     self.assertEqual(len(geoms),51)
     self.assertEqual(geoms[12]['properties']['STATE_NAME'],'New Hampshire')
     for geom in geoms:
         self.assertIn(type(geom['geom']),(Polygon,MultiPolygon))
開發者ID:tatarinova,項目名稱:ocgis,代碼行數:8,代碼來源:test_shp_cabinet.py

示例14: test_unwrap_pm

 def test_unwrap_pm(self):
     _pm = [-4.0,-10.0,-20.0,5.0]
     sc = ShpCabinet()
     for pm in _pm:
         geoms = sc.get_geoms('world_countries',unwrap=True,pm=pm)
         path = '/tmp/shp{0}.shp'.format(time.time())
         sc.write(geoms,path)
         for geom in geoms:
             bounds = geom['geom'].bounds
             self.assertTrue(bounds[0] >= pm)
開發者ID:doutriaux1,項目名稱:ocgis,代碼行數:10,代碼來源:test_ShpCabinet.py

示例15: write

 def write(self,path):
     geoms = []
     uid = self.spatial.uid
     attrs = self.spatial.attrs
     for ii,geom in iter_array(self.spatial.geom,return_value=True):
         dct = {'geom':geom,'UGID':uid[ii]}
         for k,v in attrs.iteritems():
             dct[k] = v[ii]
         geoms.append(dct)
     sc = ShpCabinet()
     sc.write(geoms,path,sr=self.spatial.projection.sr)
開發者ID:imclab,項目名稱:ocgis,代碼行數:11,代碼來源:shp.py


注:本文中的ocgis.util.shp_cabinet.ShpCabinet類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。