function_vector.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:dzetsaka 作者: lennepkade 项目源码 文件源码
def saveToShape(self,array,srs,outShapeFile):
        # Parse a delimited text file of volcano data and create a shapefile
        # use a dictionary reader so we can access by field name
        # set up the shapefile driver
        outDriver = ogr.GetDriverByName( 'ESRI Shapefile' )

        # create the data source
        if os.path.exists(outShapeFile):
            outDriver.DeleteDataSource(outShapeFile)
        # Remove output shapefile if it already exists

        ds = outDriver.CreateDataSource(outShapeFile) #options = ['SPATIALITE=YES'])

        # create the spatial reference, WGS84

        lyrout = ds.CreateLayer('randomSubset',srs)
        fields = [array[1].GetFieldDefnRef(i).GetName() for i in range(array[1].GetFieldCount())]

        for f in fields:
            field_name = ogr.FieldDefn(f, ogr.OFTString)
            field_name.SetWidth(24)
            lyrout.CreateField(field_name)


        for k in array:
            lyrout.CreateFeature(k)

        # Save and close the data source
        ds = None
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号