当前位置: 首页>>代码示例>>Python>>正文


Python fiona.collection方法代码示例

本文整理汇总了Python中fiona.collection方法的典型用法代码示例。如果您正苦于以下问题:Python fiona.collection方法的具体用法?Python fiona.collection怎么用?Python fiona.collection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在fiona的用法示例。


在下文中一共展示了fiona.collection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: latlon_to_shp

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def latlon_to_shp(lon, lat, shapefile):

    shapefile = str(shapefile)

    schema = {'geometry': 'Point',
              'properties': {'id': 'str'}}

    wkt = loads('POINT ({} {})'.format(lon, lat))

    with collection(shapefile, "w",
                    crs=from_epsg(4326),
                    driver="ESRI Shapefile",
                    schema=schema) as output:

        output.write({'geometry': mapping(wkt),
                      'properties': {'id': '1'}}) 
开发者ID:ESA-PhiLab,项目名称:OpenSarToolkit,代码行数:18,代码来源:vector.py

示例2: buffer_shape

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def buffer_shape(infile, outfile, buffer=None):

    with collection(infile, "r") as in_shape:
        # schema = in_shape.schema.copy()
        schema = {'geometry': 'Polygon', 'properties': {'id': 'int'}}
        crs = in_shape.crs
        with collection(
                outfile, "w", "ESRI Shapefile", schema, crs=crs) as output:

            for i, point in enumerate(in_shape):
                output.write({
                    'properties': {
                        'id': i
                    },
                    'geometry': mapping(
                        shape(point['geometry']).buffer(buffer))
                }) 
开发者ID:ESA-PhiLab,项目名称:OpenSarToolkit,代码行数:19,代码来源:vector.py

示例3: check_file

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def check_file(filename):
    with collection(filename, 'r') as features:
        for feature in features:
            try:
                shape = asShape(feature['geometry'])
                if not shape.is_valid:
                    geometry = json.dumps(feature, indent=2)
                    print "Invalid geometry:\n"
                    print geometry
                    print '\n'
            except:
                print "Error parsing:\n"
                print json.dumps(feature, indent=2) 
开发者ID:osmlab,项目名称:labuildings,代码行数:15,代码来源:check_shp.py

示例4: chunk

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def chunk(featureFileName, sectionFileName, pattern, key = None):

    # Load and index
    with collection(featureFileName, "r") as featureFile:
        featureIdx = index.Index()
        features = []
        for feature in featureFile:
            try:
                shape = asShape(feature['geometry'])
                features.append(feature)
                featureIdx.add(len(features) - 1, shape.bounds)
            except ValueError:
                print "Error parsing feature"
                pprint(feature)

        # Break up by sections and export
        with collection(sectionFileName, "r") as sectionFile:
            i = 0
            for section in sectionFile:
                fileName = pattern % i
                if key:
                    fileName = pattern % section['properties'][key]
                    properties = {}
                    try:
                        with collection(fileName, 'w', 'ESRI Shapefile',
                                schema = featureFile.schema,
                                crs = featureFile.crs) as output:
                            sectionShape = asShape(section['geometry'])
                            for j in featureIdx.intersection(sectionShape.bounds):
                                if asShape(features[j]['geometry']).intersects(sectionShape):
                                    properties = features[j]['properties']
                                    output.write(features[j])
                            print "Exported %s" % fileName
                            i = i + 1
                    except ValueError:
                        print "Error exporting " + fileName
                        pprint(properties)
                        pprint(featureFile.schema) 
开发者ID:osmlab,项目名称:labuildings,代码行数:40,代码来源:chunk.py

示例5: export_tree_locations

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def export_tree_locations(self, loc='top'):
        """ Convert tree top raster indices to georeferenced 3D point shapefile

        Parameters
        ----------
        loc :     str, optional
                  tree seed position: `top` or `top_cor`
        """
        outfile = self.outpath / f'tree_location_{loc}.shp'
        outfile.parent.mkdir(parents=True, exist_ok=True)

        if outfile.exists():
            outfile.unlink()

        schema = {
            'geometry': '3D Point',
            'properties': {'DN': 'int', 'TH': 'float', 'COR': 'int'}
        }
        with fiona.collection(
            str(outfile), 'w', 'ESRI Shapefile', schema, crs=self.srs
        ) as output:
            for tidx in range(len(self.trees)):
                feat = {}
                tree = self.trees.iloc[tidx]
                feat['geometry'] = mapping(
                    Point(tree[loc].x, tree[loc].y, tree[f'{loc}_elevation'])
                )
                feat['properties'] = {'DN': tidx,
                                      'TH': float(tree[f'{loc}_height']),
                                      'COR': int(tree.tt_corrected)}
                output.write(feat) 
开发者ID:manaakiwhenua,项目名称:pycrown,代码行数:33,代码来源:pycrown.py

示例6: export_tree_crowns

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def export_tree_crowns(self, crowntype='crown_poly_smooth'):
        """ Convert tree crown raster to georeferenced polygon shapefile

        Parameters
        ----------
        crowntype :   str, optional
                      choose whether the raster of smoothed version should be
                      exported: `crown_poly_smooth` or `crown_poly_raster`
        """
        outfile = self.outpath / f'tree_{crowntype}.shp'
        outfile.parent.mkdir(parents=True, exist_ok=True)

        if outfile.exists():
            outfile.unlink()

        schema = {
            'geometry': 'Polygon',
            'properties': {'DN': 'int', 'TTH': 'float', 'TCH': 'float'}
        }
        with fiona.collection(
            str(outfile), 'w', 'ESRI Shapefile',
            schema, crs=self.srs
        ) as output:
            for tidx in range(len(self.trees)):
                feat = {}
                tree = self.trees.iloc[tidx]
                feat['geometry'] = mapping(tree[crowntype])
                feat['properties'] = {
                    'DN': tidx,
                    'TTH': float(tree.top_height),
                    'TCH': float(tree.top_cor_height)
                }
                output.write(feat) 
开发者ID:manaakiwhenua,项目名称:pycrown,代码行数:35,代码来源:pycrown.py

示例7: extract_shapefile

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
    
    for feature in collection(shapefile, "r"):
        
        geometry = feature["geometry"]
        properties = feature["properties"]
        
        #calculate centroid
        geom_obj = asShape(geometry)

        try:
            centroid = [geom_obj.centroid.x , geom_obj.centroid.y]    
        except AttributeError:
            print "Error: ", feature
            continue
        borough = ""
        boros = {"1":"Manhattan", "2": "Bronx", "3":"Brooklyn", "4": "Queens", "5": "Staten Island"}
        if properties.get("BORO"):
            borough = boros[properties["BORO"]] + ", "
        
        block = ""
        if properties.get("BLOCK"):
            block = "Block " + str(properties["BLOCK"]) +", "
        name = borough + block + "Lot " + str(properties["LOT"])

        bbl = properties.get("BBL")  #stored with uris
        
        #feature code mapping
        feature_code = "ADM7"
                
        source = properties  #keep all fields anyhow
        
        # unique URI which internally gets converted to the place id
        # Must be unique!
        uri = uri_name  + bbl
        uri_bbl = "bbl:"+bbl
         
        timeframe = {}
       
        updated = datetime.datetime.utcnow().replace(second=0, microsecond=0).isoformat()

        place = {
            "name":name,
            "centroid":centroid,
            "feature_code": feature_code,
            "geometry":geometry,
            "is_primary": True,
            "source": source,
            "alternate": [],
            "updated": updated,
            "uris":[uri, uri_bbl],
            "relationships": [],
            "timeframe":timeframe,
            "admin":[]

        }
        #print place
        dump.write(uri, place) 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:60,代码来源:nyc_tax_lot.py

示例8: extract_shapefile

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
    
    for feature in collection(shapefile, "r"):
        
        geometry = feature["geometry"]
        properties = feature["properties"]
        
        #calculate centroid
        geom_obj = asShape(geometry)

        try:
            centroid = [geom_obj.centroid.x , geom_obj.centroid.y]    
        except AttributeError:
            print "Error: ", feature
            continue

       
        if properties["NAME"]:
            name = properties["NAME"]
        else:
            continue
        
        #feature code mapping
        feature_code = "ADM3"
        if properties["LSAD"] == "Resvn":
            feature_code = "RESV"
   
        area = properties["CENSUSAREA"]
                
        source = properties  #keep all fields anyhow
        
        # unique URI which internally gets converted to the place id
        # Must be unique!
        uri = uri_name + "." + properties["GEO_ID"] + "."+ feature["id"]
         
        timeframe = {}
        timeframe = {"start": "2000-01-01","start_range":0, "end": "2010-01-01", "end_range":0}
        
        updated = "2012-01-31"

        place = {
            "name":name,
            "centroid":centroid,
            "feature_code": feature_code,
            "geometry":geometry,
            "is_primary": True,
            "source": source,
            "alternate": [],
            "updated": updated,
            "area": area,
            "uris":[uri],
            "relationships": [],
            "timeframe":timeframe,
            "admin":[]

        }
        #print place
        dump.write(uri, place) 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:60,代码来源:nyc_township_shapefile_2010.py

示例9: extract_shapefile

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
    
    for feature in collection(shapefile, "r"):
        
        geometry = feature["geometry"]
        properties = feature["properties"]
        #calculate centroid
        geom_obj = asShape(geometry)
        if simplify_tolerance:
            geom_obj = geom_obj.simplify(simplify_tolerance)
        
        try:
            centroid = [geom_obj.centroid.x , geom_obj.centroid.y]    
        except AttributeError:
            print "Error: ", feature
            continue
        geometry = mapping(geom_obj)

            
        if properties["FULL_NAME"]:
            name = properties["FULL_NAME"]
                    
        #feature code mapping
        feature_code = "ADM1H"
                
        source = properties  #keep all fields anyhow
        
        # unique URI which internally gets converted to the place id
        # Must be unique!
        uri = uri_name + "." + properties["ID"] + "."+ str(properties["VERSION"])
        
        #1766/07/02  to 1766-01-01
        timeframe = {"start": properties["START_DATE"].replace('/','-'), "start_range":0, 
                     "end": properties["END_DATE"].replace('/','-'), "end_range":0}
        
        #TODO admin? for counties?
        
        updated = "2011-10-01"
        
        
        area = properties["AREA_SQMI"]
        place = {
            "name":name,
            "centroid":centroid,
            "feature_code": feature_code,
            "geometry":geometry,
            "is_primary": True,
            "source": source,
            "updated": updated,
            "uris":[uri],
            "relationships": [],
            "timeframe":timeframe,
            "admin":[],
            "area": area
            
        }
        
        dump.write(uri, place) 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:60,代码来源:nyc_hist_states_shapefile.py

示例10: extract_shapefile

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
    
    for feature in collection(shapefile, "r"):
        
        geometry = feature["geometry"]
        properties = feature["properties"]
        
        #calculate centroid
        geom_obj = asShape(geometry)

        try:
            centroid = [geom_obj.centroid.x , geom_obj.centroid.y]    
        except AttributeError:
            print "Error: ", feature
            continue

       
        if properties["NAME"]:
            name = properties["NAME"]
        else:
            continue
        
        #feature code mapping
        feature_code = "ADM3"
        if properties["LSAD_TRANS"] == "Reservation":
            feature_code = "RESV"
                
        source = properties  #keep all fields anyhow
        
        # unique URI which internally gets converted to the place id
        # Must be unique!
        uri = uri_name + "." + properties["COUSUBFP"] + "."+ feature["id"]
         
        timeframe = {}
        timeframe = {"start": "1990-01-01", "start_range":0, "end": "2000-01-01", "end_range":0}
        
        updated = "2012-01-31"

        place = {
            "name":name,
            "centroid":centroid,
            "feature_code": feature_code,
            "geometry":geometry,
            "is_primary": True,
            "source": source,
            "alternate": [],
            "updated": updated,
            "uris":[uri],
            "relationships": [],
            "timeframe":timeframe,
            "admin":[]

        }
        #print place
        dump.write(uri, place) 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:57,代码来源:nyc_township_shapefile_2000.py

示例11: extract_shapefile

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
    
    for feature in collection(shapefile, "r"):
        
        geometry = feature["geometry"]
        properties = feature["properties"]
        
        #calculate centroid
        geom_obj = asShape(geometry)

        try:
            centroid = [geom_obj.centroid.x , geom_obj.centroid.y]    
        except AttributeError:
            print "Error: ", feature
            continue

        boros = {"1":"Manhattan", "2": "Bronx", "3":"Brooklyn", "4": "Queens", "5": "Staten Island"}
        name = "Block "+str(properties["BLOCK"])
        if properties.get("BORO"):
            borough = boros[properties["BORO"]]
            name = borough + ", Block "+ str(properties["BLOCK"])
                
        
        #feature code mapping
        feature_code = "ADM6"
                
        source = properties  #keep all fields anyhow
        
        # unique URI which internally gets converted to the place id
        # Must be unique!
        
        bb = str(properties.get("BORO"))+str(properties["BLOCK"])
        
        uri = uri_name + bb +"/"+feature["id"]
        uri_bb = "bb:"+bb
        timeframe = {}
       
        updated = datetime.datetime.utcnow().replace(second=0, microsecond=0).isoformat()

        place = {
            "name":name,
            "centroid":centroid,
            "feature_code": feature_code,
            "geometry":geometry,
            "is_primary": True,
            "source": source,
            "alternate": [],
            "updated": updated,
            "uris":[uri,uri_bb],
            "relationships": [],
            "timeframe":timeframe,
            "admin":[]

        }
        #print place
        dump.write(uri, place) 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:58,代码来源:nyc_tax_block.py

示例12: extract_shapefile

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
    
    for feature in collection(shapefile, "r"):
        
        geometry = feature["geometry"]
        properties = feature["properties"]
        
        #calculate centroid
        geom_obj = asShape(geometry)
        if simplify_tolerance:
            geom_obj = geom_obj.simplify(simplify_tolerance)
        
        try:
            centroid = [geom_obj.centroid.x , geom_obj.centroid.y]    
        except AttributeError:
            print "Error: ", feature
            continue
        geometry = mapping(geom_obj)

            
        if properties["FULL_NAME"]:
            name = properties["FULL_NAME"]
                    
        #feature code mapping
        feature_code = "ADM2H" #default code (building)
                
        source = properties  #keep all fields anyhow
        
        # unique URI which internally gets converted to the place id
        # Must be unique!
        uri = uri_name + "." + properties["ID"] + "."+ str(properties["VERSION"])
    
        #1766/07/02  to 1766-01-01
        timeframe = {"start": properties["START_DATE"].replace('/','-'), "start_range":0, 
                     "end": properties["END_DATE"].replace('/','-'), "end_range":0}
        
        #TODO admin? for counties?
        
        updated = "2010-02-12"
        
        
        area = properties["AREA_SQMI"]
        place = {
            "name":name,
            "centroid":centroid,
            "feature_code": feature_code,
            "geometry":geometry,
            "is_primary": True,
            "source": source,
            "updated": updated,
            "uris":[uri],
            "relationships": [],
            "timeframe":timeframe,
            "admin":[],
            "area": area
            
        }
        
        dump.write(uri, place) 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:61,代码来源:nyc_hist_counties_shapefile.py

示例13: extract_shapefile

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
    
    for feature in collection(shapefile, "r"):
        
        geometry = feature["geometry"]
        properties = feature["properties"]
        
        #calculate centroid
        geom_obj = asShape(geometry)

        try:
            centroid = [geom_obj.centroid.x , geom_obj.centroid.y]    
        except AttributeError:
            print "Error: ", feature
            continue

        name = properties.get("NAME")

        #feature code mapping
        feature_code = "HSTS"
                
        source = properties  #keep all fields anyhow
        
        # unique URI which internally gets converted to the place id
        # Must be unique!
        
        
        uri = uri_name + properties["LP_Number"]

        timeframe = {}
       
        updated = datetime.datetime.utcnow().replace(second=0, microsecond=0).isoformat()

        place = {
            "name":name,
            "centroid":centroid,
            "feature_code": feature_code,
            "geometry":geometry,
            "is_primary": True,
            "source": source,
            "alternate": [],
            "updated": updated,
            "uris":[uri],
            "relationships": [],
            "timeframe":timeframe,
            "admin":[]

        }

        dump.write(uri, place) 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:52,代码来源:nyc_landmarks_polygons.py

示例14: extract_shapefile

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def extract_shapefile(shapefile, uri_name, simplify_tolerance=None):
    
    for feature in collection(shapefile, "r"):
        
        geometry = feature["geometry"]
        properties = feature["properties"]
        
        #calculate centroid
        geom_obj = asShape(geometry)

        try:
            centroid = [geom_obj.centroid.x , geom_obj.centroid.y]    
        except AttributeError:
            print "Error: ", feature
            continue

       
        if properties["NAME"]:
            name = properties["NAME"]
        else:
            continue
        
        #feature code mapping
        feature_code = "ADM3"
       
        area = properties["AREATOT"]
                
        source = properties  #keep all fields anyhow
        
        # unique URI which internally gets converted to the place id
        # Must be unique!
        uri = uri_name + "." + properties["GEOID"] + "."+ feature["id"]
         
        timeframe = {}
        timeframe = {"start": "1980-01-01", "start_range": 0, "end": "1990-01-01", "end_range":0}
        
        updated = "2012-01-31"

        place = {
            "name":name,
            "centroid":centroid,
            "feature_code": feature_code,
            "geometry":geometry,
            "is_primary": True,
            "source": source,
            "alternate": [],
            "updated": updated,
            "area": area,
            "uris":[uri],
            "relationships": [],
            "timeframe":timeframe,
            "admin":[]

        }
        #print place
        dump.write(uri, place) 
开发者ID:LibraryOfCongress,项目名称:gazetteer,代码行数:58,代码来源:nyc_township_shapefile_1990.py

示例15: wkt_to_gdf

# 需要导入模块: import fiona [as 别名]
# 或者: from fiona import collection [as 别名]
def wkt_to_gdf(wkt):
    
    geometry = loads(wkt)
    # point wkt
    if geometry.geom_type == 'Point':
        data = {'id': ['1'],
                'geometry': loads(wkt).buffer(0.05).envelope}
        gdf = gpd.GeoDataFrame(data)
    
    # polygon wkt
    elif geometry.geom_type == 'Polygon':
        data = {'id': ['1'],
                'geometry': loads(wkt)}
        gdf = gpd.GeoDataFrame(data)

    # geometry collection of single multiploygon
    elif geometry.geom_type == 'GeometryCollection' and len(geometry) == 1 and 'MULTIPOLYGON' in str(geometry):

        data = {'id': ['1'],
                'geometry': geometry}
        gdf = gpd.GeoDataFrame(data, crs = {'init': 'epsg:4326',  'no_defs': True})
        
        ids, feats =[], []
        for i, feat in enumerate(gdf.geometry.values[0]):
            ids.append(i)
            feats.append(feat)

        gdf = gpd.GeoDataFrame({'id': ids,
                                'geometry': feats}, 
                                 geometry='geometry', 
                                 crs = gdf.crs
                                  )
    
    # geometry collection of single polygon
    elif geometry.geom_type == 'GeometryCollection' and len(geometry) == 1:
        
        data = {'id': ['1'],
                'geometry': geometry}
        gdf = gpd.GeoDataFrame(data, crs = {'init': 'epsg:4326',  'no_defs': True})

    # everything else (hopefully)
    else:

        i, ids, geoms = 1, [], []
        for geom in geometry:
            ids.append(i)
            geoms.append(geom)
            i += 1

        gdf = gpd.GeoDataFrame({'id': ids,
                                'geometry': geoms},
                                crs = {'init': 'epsg:4326',  'no_defs': True}
              )
    
    return gdf 
开发者ID:ESA-PhiLab,项目名称:OpenSarToolkit,代码行数:57,代码来源:vector.py


注:本文中的fiona.collection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。