Creating point feature from dictionary in ArcPy? [closed]

I'm trying to create a multipoint feature in arcpy, with information in fields attached to the points. I get how to make a multipoint feature I think, but these are just points. How to add fields to these, in a way that I don't mess up the order of one of the two.

The code below creates a shapefile from a dictionary. How do I get the color and the number in the same dictionary added to the right coordinates?

import arcpy, arcinfo

points_dictionary = {'point1':((1,2),'blue',2),
'point2':((0,1), 'red',4),
'point3':((3,2), 'yellow',6)}
features = []

for key in points_dictionary:
features.append(
arcpy.Multipoint(
arcpy.Array([arcpy.Point(coords) for coords in points_dictionary[key][0]])
)
)

arcpy.CopyFeatures_management(features,"D:\\path\\to\\folder\\testfeature.shp")

• Your code will create two features / rows in the attribute table), is this what you want? You cant add three colors to two features – BERA Jul 12 '17 at 12:42
• My code creates a dictionary with extra info per point, and the shapefile that it creates only holds the location of the points, not the color and number that I added. The question is how to add this – ArnJac Jul 12 '17 at 13:50
• Like I said, your code is creating two multipoints. You cant add three colors to two multipoints. Are you sure it is multipoints you want? – BERA Jul 12 '17 at 19:15
• Your question is not clear - Are you wanting multi-point features, or multiple (more than 1) single-point features? Your dictionary is invalid as written above with two keys the same point2. What are the colours and the numbers about? Multipoint features have a single row, so a single value for each field. If you have a colour field, you can only have one value for each record. The "multi" from multipoint refers to the number of points for each record, not the number of records in the table. – Midavalo Jul 14 '17 at 21:31
• You are right. My question is unclear and incorrect. What I mean is exactly as you mention about creating a point feature with several points in it, from a dictionary (obviously with unique keys). I improved the question, I hope it is clear now. – ArnJac Jul 18 '17 at 11:38

Firstly I'm not sure to whether it's a typo or intentional that you have duplicate keys in your dictionary ('point2'). I believe it's a bad idea.

I'd use InsertCursor to add attributes to the features.

I would simply create a Point FC first, and use Dissolve tool to convert it to a Multipoint FC.

Since all of your attributes are unique, each multipoint features will contain a single point.

Please feel free to give it a try. I hope it helps,

import arcpy, arcinfo
from arcpy import env

sr = "" # change to the projection, your coordinates derive from

points_dictionary = {'point1':((1,2),'blue',2),'point2':((0,1), 'red',4),'point3':((3,2), 'yellow',6)}

temp_fc = arcpy.CreateFeatureclass_management("in_memory", "output_fc", "POINT","","","", sr)
arcpy.MakeFeatureLayer_management(temp_fc, "temp_layer")