Skip to main content
edited title
Link
PolyGeo
  • 65.4k
  • 29
  • 114
  • 345

How to add Adding column in ato shapefile with Fiona?

Rollback to Revision 3
Source Link
Heinz
  • 1.6k
  • 5
  • 26
  • 42

Python: How to edit specific rows of attribute tableadd column in a line shapefile with Fiona?

I got a line shapefile tc_line with 166 rows (line segments), and the figure below was its atttribute table:

enter image description here

and with Fiona and networkx, I also got some edges in this shapefile (How to get lines and nodes around the confluence point in a network system (line shapefile)?):

LINESTRING (260586.2596740723 2736302.815605165, 260586.2596740723 2736273.931404115)
LINESTRING (260586.2596740723 2736302.815605165, 260586.2596740723 2736331.699806215)
LINESTRING (260586.2596740723 2736302.815605165, 260615.1438751221 2736302.815605165)

I want to:

1. Add a column (type:float) containing 1 in the attribute table of tc_line

2. In the table, find out rows (line segments), which contain edges listed above

3. Update value in the new-added column of selected rows

I think that to copy the original shapefile in a newly-created one to do tasks above would be better for me, so I wrote the script to copy a existing shapefile tc_line to a new file tc_pi, and it ran fine:

But now I am stuck in stage 1 described above, asNow I want to copy the existing file and add a new column (type: float) containing "1" to the attribute table (I would like the new-added column to be attached to the right of the existing columns in the attribute talle), so I edited the code above to this:

I am newbie to use Fiona and networkx, and howHow to solve this and achieve my objectives? I am gladobjective of 'copy the existing file and add a new column (type: float) containing "1" to receive some tips.the attribute table of new file'?

I am working with python 2.7.12, Fiona 1.7.0 and networkx 1.11 under Win10 64bits.

Python: How to edit specific rows of attribute table in a line shapefile?

I got a line shapefile tc_line with 166 rows (line segments), and the figure below was its atttribute table:

enter image description here

and with Fiona and networkx, I also got some edges in this shapefile (How to get lines and nodes around the confluence point in a network system (line shapefile)?):

LINESTRING (260586.2596740723 2736302.815605165, 260586.2596740723 2736273.931404115)
LINESTRING (260586.2596740723 2736302.815605165, 260586.2596740723 2736331.699806215)
LINESTRING (260586.2596740723 2736302.815605165, 260615.1438751221 2736302.815605165)

I want to:

1. Add a column (type:float) containing 1 in the attribute table of tc_line

2. In the table, find out rows (line segments), which contain edges listed above

3. Update value in the new-added column of selected rows

I think that to copy the original shapefile in a newly-created one to do tasks above would be better for me, so I wrote the script to copy a existing shapefile tc_line to a new file tc_pi, and it ran fine:

But now I am stuck in stage 1 described above, as I want to add a new column (type: float) containing "1" to the attribute table (I would like the new-added column to be attached to the right of the existing columns in the attribute talle):

I am newbie to use Fiona and networkx, and how to solve this and achieve my objectives? I am glad to receive some tips.

I am working with python 2.7.12, Fiona 1.7.0 and networkx 1.11 under Win10 64bits.

How to add column in a shapefile with Fiona?

I wrote the script to copy a existing shapefile tc_line to a new file tc_pi, and it ran fine:

Now I want to copy the existing file and add a new column (type: float) containing "1" to the attribute table (I would like the new-added column to be attached to the right of the existing columns in the attribute talle), so I edited the code above to this:

How to solve this and achieve my objective of 'copy the existing file and add a new column (type: float) containing "1" to the attribute table of new file'?

I am working with python 2.7.12, Fiona 1.7.0

edited title
Link
Heinz
  • 1.6k
  • 5
  • 26
  • 42

Python: How to edit specific rows of attribute table in a line shapefile?

added 1144 characters in body; edited tags; edited title
Source Link
Heinz
  • 1.6k
  • 5
  • 26
  • 42
Loading
edited title
Link
Heinz
  • 1.6k
  • 5
  • 26
  • 42
Loading
edited title
Link
Heinz
  • 1.6k
  • 5
  • 26
  • 42
Loading
Source Link
Heinz
  • 1.6k
  • 5
  • 26
  • 42
Loading