Skip to main content
edited tags; edited title
Link
Saeed
  • 79
  • 6

How to attachadd attribute table to new shapefile using OGR?

deleted 36 characters in body; edited tags; edited title
Source Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to attach attribute table to the new shape fileshapefile using OGR?

i have made a new shape fileshapefile from the original shape fileshapefile , and now i want to copy the attribute table from the original shape fileshapefile to the new select shape fileshapefile , but i don't know how to do that , if any one can help me. thanks?

import ogr,os,sys,ogr

Datasource_Parks = 'ArcCR500_v32/ChranenaUzemi.shp'

Direction_Result_Shp = 'ArcCR500_v32/Result.shp'
Direction_Result_Dbf="ArcCR500_v32/Table.dbf"


Open_Parks = ogr.Open(Datasource_Parks)
layer_park = Open_Parks.GetLayer(0)

SQL = "NAZEV_ASCI = 'Krkonossky narodni park'"

layer_park.SetAttributeFilter(SQL)

Number_Of_Park = layer_park.GetFeatureCount()

Driver = ogr.GetDriverByName("ESRI shapefile")

if os.path.exists(Direction_Result_Shp):
    Driver.DeleteDataSource(Direction_Result_Shp)

Dataset = Driver.CreateDataSource(Direction_Result_Shp)

New_Layer = Dataset.CreateLayer(Direction_Result_Shp, geom_type= ogr.wkbPolygon)

number = 0
for i in range(0, Number_Of_Park):
    H = layer_park.GetNextFeature()
    H_geometry = H.GetGeometryRef()

    New_Layer.CreateFeature(H)

Dataset.Destroy()

attribute table form the original shape file,"ChranenaUzemni.shp

New shape file with no attribute table

How to attach attribute table to the new shape file?

i have made a new shape file from the original shape file , and now i want to copy the attribute table from the original shape file to the new select shape file , but i don't know how to do that , if any one can help me. thanks

import ogr,os,sys,ogr

Datasource_Parks = 'ArcCR500_v32/ChranenaUzemi.shp'

Direction_Result_Shp = 'ArcCR500_v32/Result.shp'
Direction_Result_Dbf="ArcCR500_v32/Table.dbf"


Open_Parks = ogr.Open(Datasource_Parks)
layer_park = Open_Parks.GetLayer(0)

SQL = "NAZEV_ASCI = 'Krkonossky narodni park'"

layer_park.SetAttributeFilter(SQL)

Number_Of_Park = layer_park.GetFeatureCount()

Driver = ogr.GetDriverByName("ESRI shapefile")

if os.path.exists(Direction_Result_Shp):
    Driver.DeleteDataSource(Direction_Result_Shp)

Dataset = Driver.CreateDataSource(Direction_Result_Shp)

New_Layer = Dataset.CreateLayer(Direction_Result_Shp, geom_type= ogr.wkbPolygon)

number = 0
for i in range(0, Number_Of_Park):
    H = layer_park.GetNextFeature()
    H_geometry = H.GetGeometryRef()

    New_Layer.CreateFeature(H)

Dataset.Destroy()

attribute table form the original shape file,"ChranenaUzemni.shp

New shape file with no attribute table

How to attach attribute table to new shapefile using OGR?

i have made a new shapefile from the original shapefile , and now i want to copy the attribute table from the original shapefile to the new select shapefile , but i don't know how to do that?

import ogr,os,sys,ogr

Datasource_Parks = 'ArcCR500_v32/ChranenaUzemi.shp'

Direction_Result_Shp = 'ArcCR500_v32/Result.shp'
Direction_Result_Dbf="ArcCR500_v32/Table.dbf"


Open_Parks = ogr.Open(Datasource_Parks)
layer_park = Open_Parks.GetLayer(0)

SQL = "NAZEV_ASCI = 'Krkonossky narodni park'"

layer_park.SetAttributeFilter(SQL)

Number_Of_Park = layer_park.GetFeatureCount()

Driver = ogr.GetDriverByName("ESRI shapefile")

if os.path.exists(Direction_Result_Shp):
    Driver.DeleteDataSource(Direction_Result_Shp)

Dataset = Driver.CreateDataSource(Direction_Result_Shp)

New_Layer = Dataset.CreateLayer(Direction_Result_Shp, geom_type= ogr.wkbPolygon)

number = 0
for i in range(0, Number_Of_Park):
    H = layer_park.GetNextFeature()
    H_geometry = H.GetGeometryRef()

    New_Layer.CreateFeature(H)

Dataset.Destroy()

attribute table form the original shape file,"ChranenaUzemni.shp

New shape file with no attribute table

Source Link
Saeed
  • 79
  • 6
Loading