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

I´m a beginner at python programming and wanted to start with a litte and hopefully simple project. I tried to read float values out of a textfile and write them into a shapefile.

The program is working fine until the writing in the shapefile. Following error occurs:

TypeError: value #0 - unsupported type: list
TypeError: sequence size must match size of the row

I tried different styles (last lines in the code) but i could´t work it out. So my question is: What is my error and what could i do to solve this Problem?

Example of the Textfile ("test.txt"):

2500000.00 5600000.00 10
2500001.00 5600010.00 20

Script

import fileinput
import string
import os

# Declaration
env.overwriteOutput=True
env.workspace= outpath

x = []
y = []
z = []

newfc="newfc.shp" 
outpath="c:/tmp/"


# Create new Shapefile and add FIELDS
arcpy.CreateFeatureclass_management(outpath, newfc, "Point")
arcpy.AddField_management(newfc, "X", "FLOAT", field_length = 50)
arcpy.AddField_management(newfc, "Y", "FLOAT", field_length = 50)
arcpy.AddField_management(newfc, "Z", "FLOAT", field_length = 50)

# Reference Cursors
cursorX=arcpy.da.InsertCursor(newfc,"X")
cursorY=arcpy.da.InsertCursor(newfc,"Y")
cursorZ=arcpy.da.InsertCursor(newfc,"Z")

# Read File 
a = open("c:/tmp/test.txt","r")
inputF = a.readlines()

for line in inputF:
        xCoordinate, yCoordinate, zValue = line.split()
        x.append(float(xCoordinate))
        y.append(float(yCoodrinate))
        z.append(float(zValue))
    
print([x]) # [[2500000.0, 2500001.0]]
print([y]) # [[5600000.0, 5600010.0]]
print([z]) # [[10.0, 20.0]]

# Copy Arrays into the Field
cursorX.insertRow(x) # TypeError: value #0 - unsupported type: list
cursorY.insertRow((y)) # TypeError: sequence size must match size of the row
cursorZ.insertRow(z)

I´m thankful for every hint =)

I´m a beginner at python programming and wanted to start with a litte and hopefully simple project. I tried to read float values out of a textfile and write them into a shapefile.

The program is working fine until the writing in the shapefile. Following error occurs:

TypeError: value #0 - unsupported type: list
TypeError: sequence size must match size of the row

I tried different styles (last lines in the code) but i could´t work it out. So my question is: What is my error and what could i do to solve this Problem?

Example of the Textfile ("test.txt"):

2500000.00 5600000.00 10
2500001.00 5600010.00 20

Script

import fileinput
import string
import os

# Declaration
env.overwriteOutput=True
env.workspace= outpath

x = []
y = []
z = []

newfc="newfc.shp" 
outpath="c:/tmp/"


# Create new Shapefile and add FIELDS
arcpy.CreateFeatureclass_management(outpath, newfc, "Point")
arcpy.AddField_management(newfc, "X", "FLOAT", field_length = 50)
arcpy.AddField_management(newfc, "Y", "FLOAT", field_length = 50)
arcpy.AddField_management(newfc, "Z", "FLOAT", field_length = 50)

# Reference Cursors
cursorX=arcpy.da.InsertCursor(newfc,"X")
cursorY=arcpy.da.InsertCursor(newfc,"Y")
cursorZ=arcpy.da.InsertCursor(newfc,"Z")

# Read File 
a = open("c:/tmp/test.txt","r")
inputF = a.readlines()

for line in inputF:
        xCoordinate, yCoordinate, zValue = line.split()
        x.append(float(xCoordinate))
        y.append(float(yCoodrinate))
        z.append(float(zValue))
    
print([x]) # [[2500000.0, 2500001.0]]
print([y]) # [[5600000.0, 5600010.0]]
print([z]) # [[10.0, 20.0]]

# Copy Arrays into the Field
cursorX.insertRow(x) # TypeError: value #0 - unsupported type: list
cursorY.insertRow((y)) # TypeError: sequence size must match size of the row
cursorZ.insertRow(z)

I´m thankful for every hint =)

I´m a beginner at python programming and wanted to start with a litte and hopefully simple project. I tried to read float values out of a textfile and write them into a shapefile.

The program is working fine until the writing in the shapefile. Following error occurs:

TypeError: value #0 - unsupported type: list
TypeError: sequence size must match size of the row

I tried different styles (last lines in the code) but i could´t work it out. So my question is: What is my error and what could i do to solve this Problem?

Example of the Textfile ("test.txt"):

2500000.00 5600000.00 10
2500001.00 5600010.00 20

Script

import fileinput
import string
import os

# Declaration
env.overwriteOutput=True
env.workspace= outpath

x = []
y = []
z = []

newfc="newfc.shp" 
outpath="c:/tmp/"


# Create new Shapefile and add FIELDS
arcpy.CreateFeatureclass_management(outpath, newfc, "Point")
arcpy.AddField_management(newfc, "X", "FLOAT", field_length = 50)
arcpy.AddField_management(newfc, "Y", "FLOAT", field_length = 50)
arcpy.AddField_management(newfc, "Z", "FLOAT", field_length = 50)

# Reference Cursors
cursorX=arcpy.da.InsertCursor(newfc,"X")
cursorY=arcpy.da.InsertCursor(newfc,"Y")
cursorZ=arcpy.da.InsertCursor(newfc,"Z")

# Read File 
a = open("c:/tmp/test.txt","r")
inputF = a.readlines()

for line in inputF:
        xCoordinate, yCoordinate, zValue = line.split()
        x.append(float(xCoordinate))
        y.append(float(yCoodrinate))
        z.append(float(zValue))
    
print([x]) # [[2500000.0, 2500001.0]]
print([y]) # [[5600000.0, 5600010.0]]
print([z]) # [[10.0, 20.0]]

# Copy Arrays into the Field
cursorX.insertRow(x) # TypeError: value #0 - unsupported type: list
cursorY.insertRow((y)) # TypeError: sequence size must match size of the row
cursorZ.insertRow(z)
Source Link
Andriel
  • 21
  • 1
  • 3

(Arcpy) read values from a txt file and convert the data into a shapefile

I´m a beginner at python programming and wanted to start with a litte and hopefully simple project. I tried to read float values out of a textfile and write them into a shapefile.

The program is working fine until the writing in the shapefile. Following error occurs:

TypeError: value #0 - unsupported type: list
TypeError: sequence size must match size of the row

I tried different styles (last lines in the code) but i could´t work it out. So my question is: What is my error and what could i do to solve this Problem?

Example of the Textfile ("test.txt"):

2500000.00 5600000.00 10
2500001.00 5600010.00 20

Script

import fileinput
import string
import os

# Declaration
env.overwriteOutput=True
env.workspace= outpath

x = []
y = []
z = []

newfc="newfc.shp" 
outpath="c:/tmp/"


# Create new Shapefile and add FIELDS
arcpy.CreateFeatureclass_management(outpath, newfc, "Point")
arcpy.AddField_management(newfc, "X", "FLOAT", field_length = 50)
arcpy.AddField_management(newfc, "Y", "FLOAT", field_length = 50)
arcpy.AddField_management(newfc, "Z", "FLOAT", field_length = 50)

# Reference Cursors
cursorX=arcpy.da.InsertCursor(newfc,"X")
cursorY=arcpy.da.InsertCursor(newfc,"Y")
cursorZ=arcpy.da.InsertCursor(newfc,"Z")

# Read File 
a = open("c:/tmp/test.txt","r")
inputF = a.readlines()

for line in inputF:
        xCoordinate, yCoordinate, zValue = line.split()
        x.append(float(xCoordinate))
        y.append(float(yCoodrinate))
        z.append(float(zValue))
    
print([x]) # [[2500000.0, 2500001.0]]
print([y]) # [[5600000.0, 5600010.0]]
print([z]) # [[10.0, 20.0]]

# Copy Arrays into the Field
cursorX.insertRow(x) # TypeError: value #0 - unsupported type: list
cursorY.insertRow((y)) # TypeError: sequence size must match size of the row
cursorZ.insertRow(z)

I´m thankful for every hint =)