I am parsing an NMEA file to be able to import it into an ArcGIS with arcpy. I finalised the parsing part and also created a list with the appropriate form. But if I'm trying to insert the List into the Attribute Table via an InsertCursor, I continously get the following error:

line 127, in <module>
cursor.insertRow(a) TypeError: sequence size must match size of the row

I already figured out that there are quotation marks in the list that causes the problem, but I really don't know how to create a workaround here. I already tried to make an array, but unfortunately I to stick to float values for the Longitude and Latitude.

This is how my code looks like:

import arcpy
#arcpy.env.workspace = env_path = arcpy.GetParameterAsText(0)
arcpy.env.overwriteOutput = 1
#nmea = arcpy.GetParameterAsText(1)

data = open('C:/temp/NMEA.txt', 'r')
input = data.read()

GGA = list();

for lines in input2:
    if '$GPGGA' in lines:

GGA2 = ''.join(GGA)
GGA3 = GGA2.split(",")

UTC = list();
Latitude = list();
Comp1 = list();
Longitude = list();
Comp2 = list();
GPSQual = list();
SatVis = list();
HDOP = list();
AntAlt = list();
AntHeight = list();
GeoidalSep1 = list();
SeaLevel = list();
GeoidalSep2 = list();
Age = list();
DifRef = list();
Check = list();

for item in GGA3:

# NMEA Coordinate Format
#(d)dd + (mm.mmmm/60) (* -1 for W and S)

# Calculation Longitude
minLong = list();
degLong = list();
for x in Longitude:

minLongInt = map(float,minLong)
degLongInt = map(int,degLong)

minLongCalc = list();
for x in minLongInt:

LongCalc = [x +y for x,y in zip(degLongInt, minLongCalc)]

# Calculation Latitude
minLat = list();
degLat = list();
for x in Latitude:

minLatInt = map(float,minLat)
degLatInt = map(float,degLat)

minLatCalc = list();
for x in minLatInt:

LatCalc = [x +y for x,y in zip(degLatInt, minLatCalc)]

GPSQaulInt = map(float,GPSQual)
SatVisInt = map(float,SatVis)
HDOPInt = map(float,HDOP)
AntAltInt = map(float,AntAlt)

a = list();
for i in range(len(LatCalc)):

#Create NMEA Shape

NMEAFile = "C:/tmp/ParsedNMEA.shp"
arcpy.AddField_management(NMEAFile,"Y","DOUBLE", 23, 15, "", "", "NON_NULLABLE", "REQUIRED")
arcpy.AddField_management(NMEAFile,"GPSQuality","SHORT", 15, "", 10, "", "NULLABLE", "NON_REQUIRED")
arcpy.AddField_management(NMEAFile,"SatVis","TEXT", 15, "", 10, "", "NULLABLE", "NON_REQUIRED")
arcpy.AddField_management(NMEAFile,"HDOP","FLOAT", 5, 15, "", "", "NULLABLE", "NON_REQUIRED")
arcpy.AddField_management(NMEAFile,"AntHeight","DOUBLE", 20, 15, "", "", "NULLABLE", "NON_REQUIRED")

cursor = arcpy.da.InsertCursor(NMEAFile,("X","Y","GPSQuality","SatVis","HDOP","AntHeight","SHAPE@XY"))
for i in range(len(a)):

My approach is based on the example in ESRIs arcpy documentation:

import arcpy

# A list of values that will be used to construct new rows
row_values = [('Anderson', (1409934.4442000017, 1076766.8192000017)),
              ('Andrews', (752000.2489000037, 1128929.8114))]

# Open an InsertCursor
cursor = arcpy.da.InsertCursor('C:/data/texas.gdb/counties',
                               ['NAME', 'SHAPE@XY'])

# Insert new rows that include the county name and a x,y coordinate
#  pair that represents the county center
for row in row_values:

I am working with ArcGIS 10.4 and PythonWin (Python 2.7).

Output of my list looks like this:

["('47.78892519','13.0611603033','1','06','1.0','435.838',(47.78892519,13.0611603033),)", "('47.7889243533','13.061157485','1','06','1.0','436.367',(47.7889243533,13.061157485),)"]

Can anyone help me out with an workaround?

  • Your row _ values isn't formatted as an array of arrays or list of arrays, it's an array of lists,. – Vince Aug 26 '17 at 16:33
  • Exactly this is the interesting point here. But a) how can i create arrays of arrays with float values and b) don't I continuously end up with lists when I doing the formation of the data with .format? I already searched for a another way to create formatted lists but I didn't come up with a answer.... – GriffinMUC Aug 26 '17 at 16:55
  • If you structure your strings as JSON, you just need to convert the JSON. – Vince Aug 27 '17 at 0:42

I think you might be trying to do to much of the thinking for python - let it take care of the data types. I haven't created a test case for this, so I may have missed something...

I think you can simply initialize a as an empty list and then append each row as a tuple - as in the docs you reference. Only 'SatVis' should be different since it's datatype is a string.

Basically replace this:

a = list();
for i in range(len(LatCalc)):

with this:

a = []
for i in range(len(LatCalc)):

Your output should be a list of tuples not a list of strings which look like tuples!

| improve this answer | |
  • Thank's so much! This was the appropriate way to go and it worked!! – GriffinMUC Sep 11 '17 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.