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
Aucun commentaire:
Enregistrer un commentaire