Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I want to programmatically add a layer to an MXD. The data for the layer is a list of tuples. From I what see, I need to create a feature class with this data (called invalidDataList) Below is what I have so far.
How do I do this? (This code is incoherent at the for loop)

# invalidDataList is a list of tuples, each having name,lat,lon,township,range,section
mxd_filename = r"D:\My Documents\ArcGIS\TownshipRange.mxd"
mxd_file = arcpy.mapping.MapDocument(mxd_filename)
dataframe = arcpy.mapping.ListDataFrames(mxd_file)[0]

featureClass = r"D:\My Documents\ArcGIS\invaliddata"
feature_class_name = "invaliddata"
arcpy.MakeFeatureLayer_management(feature_class, feature_class_name)

for invalidData in arcpy.da.SearchCursor((
        featureClass, 
        [NAME','LATITUDE','LONGITUDE','TOWNSHIP','RANGE','SECTION'']):
            featureClassData.append(invalidData.name,    
                                    invalidData.latitude,    
                                    invalidData.longitude,   
                                    invalidData.plssTownship,
                                    invalidData.plssRange,   
                                    invalidData.plssSection)

layer = arcpy.mapping.Layer(feature_class_name)
arcpy.mapping.AddLayer(dataframe, layer, "AUTO_ARRANGE")                    

Name: Smith Ranch latitude: 38.527444716 longitude: -107.637452472 plssTownship: 15S plssRange: 07W plssSection: 30
Name: Kinsley latitude: 39.34544716 longitude: -108.637452472 plssTownship: 5N plssRange: 01W plssSection: 3

Here is InvalidData class:

class InvalidData (object):

    def __init__(self, 
                 name = "", 
                 latitude = "",
                 longitude = "",
                 plssTownship = "",
                 plssRange = "",
                 plssSection = "",
                 ):

        self.mineName = name
        self.latitude = latitude
        self.longitude = longitude
        self.plssTownship = plssTownship
        self.plssRange = plssRange
        self.plssSection = plssSection
share|improve this question
    
You say "The data for the layer is a list of tuples" but do not show us an example of this data - just a list with two such tuples would be enough to provide considerably more context. –  PolyGeo Jan 29 at 21:40
    
added example data –  Al Lelopath Jan 29 at 21:49
    
I think you should start your script by setting a test data variable to an actual list of tuples with that data. To write your spatial data into a feature class take a look at arcpy.da.InsertCursor examples - SearchCursor is read-only. –  PolyGeo Jan 29 at 21:53
    
I'm not certain what you are saying. I already have an actual list of tuples with data. And yes, I now see I should use InsertCursor –  Al Lelopath Jan 29 at 21:59
1  
As you said list of tuples.Are your data is as [(Name: Smith Ranch latitude: 38.527444716 longitude: -107.637452472 plssTownship: 15S plssRange: 07W plssSection: 30 ),(Name: Kinsley latitude: 39.34544716 longitude: -108.637452472 plssTownship: 5N plssRange: 01W plssSection: 3)] care parentheses and brackets. Or tell what exactly the data are. –  SIslam Jan 30 at 6:06

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.