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


Python ogr.wkbPoint方法代碼示例

本文整理匯總了Python中ogr.wkbPoint方法的典型用法代碼示例。如果您正苦於以下問題:Python ogr.wkbPoint方法的具體用法?Python ogr.wkbPoint怎麽用?Python ogr.wkbPoint使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在ogr的用法示例。


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

示例1: saveToShape

# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import wkbPoint [as 別名]
def saveToShape(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
    import ogr
    outDriver = ogr.GetDriverByName('ESRI Shapefile')

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

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

    # create the spatial reference, WGS84

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

    for i, f in enumerate(fields):
        field_name = ogr.FieldDefn(f, array[1].GetFieldDefnRef(i).GetType())
        field_name.SetWidth(array[1].GetFieldDefnRef(i).GetWidth())
        lyrout.CreateField(field_name)

    for k in array:
        lyrout.CreateFeature(k)

    # Save and close the data source
    ds = None 
開發者ID:nkarasiak,項目名稱:dzetsaka,代碼行數:33,代碼來源:function_vector.py

示例2: gettingMetadata

# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import wkbPoint [as 別名]
def gettingMetadata(fn,lyrName):
    ds=ogr.Open(fn,0)
    if ds is None:
        sys.exit('Could not open{0}'.format(fn))
    lyr=ds.GetLayer(lyrName)    
    print("extent:",lyr.GetExtent()) #(min_x,max_x, min_y, max_y)
    print("GeomType:",lyr.GetGeomType(),"wkbPoint?",lyr.GetGeomType()==ogr.wkbPoint) #返回索引,根據索引查找對應的數據類型
    feat=lyr.GetFeature(0)
    print("GeomTypeByfeature:",feat.geometry().GetGeometryName())
    print("spatialRef:",lyr.GetSpatialRef())  #空間坐標
    print("fieldAttri:",[(field.name,field.GetTypeName()) for field in lyr.schema])
    lyrName=lyrName+".shp"
    pb.print_attributes(os.path.join(fn,lyrName), 3, ["NAME","KIND"]) 
開發者ID:richieBao,項目名稱:python-urbanPlanning,代碼行數:15,代碼來源:xa_gdal.py

示例3: save_point_list_to_shapefile

# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import wkbPoint [as 別名]
def save_point_list_to_shapefile(class_sample_point_dict, out_path, geotransform, projection_wkt, produce_csv=False):
    """Saves a list of points to a shapefile at out_path. Need the gt and projection of the raster.
    GT is needed to move each point to the centre of the pixel. Can also produce a .csv file for CoolEarth"""
    log = logging.getLogger(__name__)
    log.info("Saving point list to shapefile")
    log.debug("GT: {}\nProjection: {}".format(geotransform, projection_wkt))
    driver = ogr.GetDriverByName("ESRI Shapefile")
    data_source = driver.CreateDataSource(out_path)
    srs = osr.SpatialReference()
    srs.ImportFromWkt(projection_wkt)
    layer = data_source.CreateLayer("validation_points", srs, ogr.wkbPoint)
    class_field = ogr.FieldDefn("class", ogr.OFTString)
    class_field.SetWidth(24)
    layer.CreateField(class_field)

    for map_class, point_list in class_sample_point_dict.items():
        for point in point_list:
            feature = ogr.Feature(layer.GetLayerDefn())
            coord = pyeo.coordinate_manipulation.pixel_to_point_coordinates(point, geotransform)
            offset = geotransform[1]/2   # Adds half a pixel offset so points end up in the center of pixels
            wkt = "POINT({} {})".format(coord[0]+offset, coord[1]-offset) # Never forget about negative y values in gts.
            new_point = ogr.CreateGeometryFromWkt(wkt)
            feature.SetGeometry(new_point)
            feature.SetField("class", map_class)
            layer.CreateFeature(feature)
            feature = None

    layer = None
    data_source = None

    if produce_csv:
        csv_out_path = out_path.rsplit('.')[0] + ".csv"
        with open(csv_out_path, "w") as csv_file:
            writer = csv.writer(csv_file)
            writer.writerow(["id", "yCoordinate", "xCoordinate"])

            # Join all points create single dimesional list of points (and revise the '*' operator)
            for id,  point in enumerate(itertools.chain(*class_sample_point_dict.values())):
                coord = pyeo.coordinate_manipulation.pixel_to_point_coordinates(point, geotransform)
                offset = geotransform[1] / 2  # Adds half a pixel offset so points end up in the center of pixels
                lat = coord[0] + offset
                lon = coord[1] - offset
                writer.writerow([id, lon, lat])
        log.info("CSV out at: {}".format(csv_out_path)) 
開發者ID:clcr,項目名稱:pyeo,代碼行數:46,代碼來源:validation.py

示例4: pointWriting

# 需要導入模塊: import ogr [as 別名]
# 或者: from ogr import wkbPoint [as 別名]
def pointWriting(fn,pt_lyrName_w,ref_lyr=False):
    ds=ogr.Open(fn,1)
    
    '''參考層,用於空間坐標投影,字段屬性等參照'''
    ref_lyr=ds.GetLayer(ref_lyr)
    ref_sr=ref_lyr.GetSpatialRef()
    print(ref_sr)
    ref_schema=ref_lyr.schema #查看屬性表字段名和類型
    for field in ref_schema:
        print(field.name,field.GetTypeName())   
 
    '''建立新的datasource數據源'''
    sf_driver=ogr.GetDriverByName('ESRI Shapefile')
    sfDS=os.path.join(fn,r'sf')
    if os.path.exists(sfDS):
        sf_driver.DeleteDataSource(sfDS)
    pt_ds=sf_driver.CreateDataSource(sfDS)
    if pt_ds is None:
        sys.exit('Could not open{0}'.format(sfDS))
        
    '''建立新layer層'''    
    if pt_ds.GetLayer(pt_lyrName_w):
        pt_ds.DeleteLayer(pt_lyrName_w)    
    pt_lyr=pt_ds.CreateLayer(pt_lyrName_w,ref_sr,ogr.wkbPoint)
    
    '''配置字段,名稱以及類型和相關參數'''
    pt_lyr.CreateFields(ref_schema)
    LatFd=ogr.FieldDefn("origiLat",ogr.OFTReal)
    LatFd.SetWidth(8)
    LatFd.SetPrecision(3)
    pt_lyr.CreateField(LatFd)
    LatFd.SetName("Lat")
    pt_lyr.CreateField(LatFd)
     
    '''建立feature空特征和設置geometry幾何類型'''
    print(pt_lyr.GetLayerDefn())
    pt_feat=ogr.Feature(pt_lyr.GetLayerDefn())    
    
    for feat in ref_lyr:  #循環feature
        '''設置幾何體'''
        pt_ref=feat.geometry().Clone()
        wkt="POINT(%f %f)" %  (float(pt_ref.GetX()+0.01) , float(pt_ref.GetY()+0.01))
        newPt=ogr.CreateGeometryFromWkt(wkt) #使用wkt的方法建立點
        pt_feat.SetGeometry(newPt)
        '''設置字段值'''
        for i_field in range(feat.GetFieldCount()):
            pt_feat.SetField(i_field,feat.GetField(i_field))
        pt_feat.SetField("origiLat",pt_ref.GetX())
        pt_feat.SetField("Lat",pt_ref.GetX()+0.01)
        '''根據設置的幾何體和字段值,建立feature。循環建立多個feature特征'''
        pt_lyr.CreateFeature(pt_feat)    
    del ds 
開發者ID:richieBao,項目名稱:python-urbanPlanning,代碼行數:54,代碼來源:xa_gdal.py


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