python中如何使用gdal对轴马力读取,新建和更新

  介绍

这篇文章主要介绍了python中如何使用gdal对轴马力读取,新建和更新,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获、下面让小编带着大家一起了解一下。

<强> 1。读取轴马力文件

# - *安康;编码:cp936  - * -   试一试:   ,才能得到osgeo  import  gdal   ,才能得到osgeo  import  ogr   exceptImportError:   ,,import  gdal   ,,import  ogr   ,   defReadVectorFile ():   ,,#,为了支持中文路径,请添加下面这句代码   ,,gdal.SetConfigOption (“GDAL_FILENAME_IS_UTF8",“NO")   ,,#,为了使属性表字段支持中文,请添加下面这句   ,,gdal.SetConfigOption (“SHAPE_ENCODING",““)   ,   ,,strVectorFile =癊: \ \数据\ \ GDALCsTest \ \ \ \ beijing.shp"调试;   ,   ,,#,注册所有的驱动   ,,ogr.RegisterAll ()   ,   ,,#打开数据   ,,ds =, ogr.Open (strVectorFile, 0)   ,,if  ds ==,没有:   ,,,,印刷(“打开文件【% s】失败!“,,strVectorFile)   ,,,,回来   ,   ,才能打印(“打开文件【% s】成功!“,,strVectorFile)   ,   ,,#,获取该数据源中的图层个数,一般轴马力数据图层只有一个,如果是mdb, dxf等图层就会有多个   ,,iLayerCount =, ds.GetLayerCount ()   ,   ,,#,获取第一个图层   ,,oLayer =, ds.GetLayerByIndex (0)   ,,if  oLayer ==,没有:   ,,,,印刷(“获取第% d个图层失败! \ n",, 0)   ,,,,回来   ,   ,,#,对图层进行初始化,如果对图层进行了过滤操作,执行这句后,之前的过滤全部清空   ,,oLayer.ResetReading ()   ,   ,,#,通过属性表的SQL语句对图层中的要素进行筛选,这部分详细参考SQL查询章节内容   ,,oLayer.SetAttributeFilter (“\“NAME99 \“LIKE  \“北京市市辖区\““)   ,   ,,#,通过指定的几何对象对图层中的要素进行筛选   ,,# oLayer.SetSpatialFilter ()   ,   ,,#,通过指定的四至范围对图层中的要素进行筛选   ,,# oLayer.SetSpatialFilterRect ()   ,   ,,#,获取图层中的属性表表头并输出   ,才能打印(“属性表结构信息:“)   ,,oDefn =, oLayer.GetLayerDefn ()   ,,iFieldCount =, oDefn.GetFieldCount ()   ,,for  iAttr 拷贝范围(iFieldCount):   ,,,,oField =oDefn.GetFieldDefn (iAttr)   ,,,,print (,“% s: % s (% d % d)“, %, (\   ,,,,,,,,,oField.GetNameRef () \   ,,,,,,,,,oField.GetFieldTypeName (oField.GetType (),), \   ,,,,,,,,,oField.GetWidth () \   ,,,,,,,,,oField.GetPrecision ()))   ,   ,,#,输出图层中的要素个数   ,才能打印(“要素个数,=,% d",, oLayer.GetFeatureCount (0))   ,   ,,oFeature =, oLayer.GetNextFeature ()   ,,#,下面开始遍历图层中的要素   ,,while  oFeature  is  not 没有:   ,,,,印刷(“当前处理第% d个:,\ n属性值:“,,oFeature.GetFID ())   ,,,,#,获取要素中的属性表内容   ,,,,for  iField  inrange (iFieldCount):   ,,,,,,oFieldDefn =oDefn.GetFieldDefn (iField)   ,,,,,,line =,,, % s  (% s),=,,, %, (\   ,,,,,,,,,,,oFieldDefn.GetNameRef () \   ,,,,,,,,,,,ogr.GetFieldTypeName (oFieldDefn.GetType ()))   ,   ,,,,,,ifoFeature.IsFieldSet (, iField ):   ,,,,,,,,,line =, +,行“% s", %, (oFeature.GetFieldAsString (, iField ),)   ,,,,,,其他的:   ,,,,,,,,,line =, +行,“(null)“;   ,   ,,,,,,印刷(线)   ,,   ,,,,#,获取要素中的几何体   ,,,,oGeometry =oFeature.GetGeometryRef ()   ,   ,,,,#,为了演示,只输出一个要素信息   ,,,,休息   ,   ,才能打印(“数据集关闭!“)

<强> 2。新建轴马力文件

# - *安康;编码:cp936  - * -   试一试:   ,才能得到osgeo  import  gdal   ,才能得到osgeo  import  ogr   exceptImportError:   ,,import  gdal   ,,import  ogr   ,   defWriteVectorFile ():   ,,#,为了支持中文路径,请添加下面这句代码   ,,gdal.SetConfigOption (“GDAL_FILENAME_IS_UTF8",“NO")   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

python中如何使用gdal对轴马力读取,新建和更新