I am working on a Python script that receives a nightly tab delimited flat file. This flat file has Latitude and Longitude fields and the script loads the data using the gp tools Make XY Event Layer and Append management. The flat files sometime have missing Lat/Long values and when this occurs the script still successfully loads the feature class with the records even though they are missing Lat/Long.

The problem occurs if every record on the flat file is missing Lat/Long data. So it seems that as long as one record on the flat file has Lat/Long, the code works and loads the other records to the feature class as well.

Since receiving a flat file where all records have blank Lat/Long data is a realistic scenario, is there a different gp tool/approach that will allow me to load a full file of records to the existing feature class when all records are missing Lat/Long data?

  • 1
    Maybe you can just catch the exception by including your whole script in a try-except-statement? And then add proper handling in the except part of course.
    – Martin
    Sep 10, 2014 at 13:32
  • 1
    Just want to clarify something, when you say "...that will allow me to load a full file of records to the existing feature class when all records are missing Lat/Long data" are you asking if you can APPEND your text file creating NULL geometries but populate all the other fields? How many rows of "nothing" would you typically add and why would you want that?
    – Hornbydd
    Sep 10, 2014 at 13:52
  • I can certainly catch the exception, but the goal is to actually be able to load the data to the feature class even if it is missing the Lat/Long.
    – SNE1978
    Sep 10, 2014 at 14:49
  • Hornbydd - we want to append the records to the feature class even if they are missing a Lat/Long for QA/QC purposes (The records would contain many additional fields of data that are populated). There are some scenarios where capturing a Lat/Long for the point is not possible, but we still want to store that record of data. Does that make sense?
    – SNE1978
    Sep 10, 2014 at 14:51

1 Answer 1


I would incorporate a conditional statement to check for the problem. The following example checks the length of the lat/long field. If the value is > 0, do something.

import arcpy

table = r"C:\path\to\your\table.csv"

check = [x for x in arcpy.da.SearchCursor(table, "LatLongField")]

if len(check) > 0:
    # Do something
  • Aaron, So if the len(check) == 0, then how do I get the code to still load the record?
    – SNE1978
    Sep 10, 2014 at 14:53
  • @SNE1978 Could you expand on exactly what it is that goes wrong when you try? Error messages?
    – Martin
    Sep 11, 2014 at 5:38

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.