Hello everyone,
How can I create a point feature in a feature class with ArcPy the same way I do it with vb.net
I need to convert this vb.net code into Python code.
Dim workspaceEdit As IWorkspaceEdit = CType(myTargetIWorkspace, IWorkspaceEdit)
'' Start an edit session. An undo/redo stack isn't necessary in this case.
workspaceEdit.StartEditing(False)
''/ Start an edit operation.
workspaceEdit.StartEditOperation()
Dim feature As IFeature = pFeatureClass.CreateFeature()
feature.Shape = pPoint
feature.Value(feature.Fields.FindField("ID")) = IncidentID
feature.Value(feature.Fields.FindField("ADDRESS")) = Address
feature.Value(feature.Fields.FindField("XCOORD")) = pPoint.X
feature.Value(feature.Fields.FindField("YCOORD")) = pPoint.Y
feature.Value(feature.Fields.FindField("PROBDESC")) = ProblemDescription
feature.Value(feature.Fields.FindField("REQSTDATE")) = DateTime.Parse(RequestedDate.ToString)
feature.Store()
''// Save the edit operation. To cancel an edit operation, the AbortEditOperation
''// method can be used.
workspaceEdit.StopEditOperation()
''// Stop the edit session. The saveEdits parameter indicates the edit session
''// will be committed.
workspaceEdit.StopEditing(True)
Does this help? Create Feature Class—Help | ArcGIS Desktop
I am looking for a sample code to create a record in the feature class, not a feature class.
Oops. My bad. Sorry about that!
how about this: https://www.e-education.psu.edu/geog485/node/142
insert cursors: InsertCursor—Help | ArcGIS Desktop
Then you want an UpdateCursor or an InsertCursor and you can follow some of the code samples in the arcpy section of the help files... for example
There are loads of other examples, and even on geonet, code samples abound and I am sure that the exact snippet has been written to suit your case, but the arcpy help is a good reference location
An exact snippet!!! this is what I am looking for 🙂
I thought the links above provided samples. Here is some code I use to create a rectangular polygon based on screen map extent. Note that it's only an 'in memory' feature class that I use and toss....
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd)[0]
frameExtent = df.extent
#
XMAX = frameExtent.XMax
XMIN = frameExtent.XMin
YMAX = frameExtent.YMax
YMIN = frameExtent.YMin
#
pnt1 = arcpy.Point(XMIN, YMIN)
pnt2 = arcpy.Point(XMIN, YMAX)
pnt3 = arcpy.Point(XMAX, YMAX)
pnt4 = arcpy.Point(XMAX, YMIN)
#
array = arcpy.Array()
array.add(pnt1)
array.add(pnt2)
array.add(pnt3)
array.add(pnt4)
array.add(pnt1)
#
Mypolygon = arcpy.Polygon(array)
arcpy.CopyFeatures_management(Mypolygon,"in_memory\\ExtentPoly")
in_poly_layer = arcpy.mapping.ListLayers(mxd,"ExtentPoly",df)[0]
poly_symbology_layer = arcpy.mapping.Layer(r"C:\LayerFiles\EmptyRedPolygon.lyr")
arcpy.ApplySymbologyFromLayer_management(in_poly_layer,poly_symbology_layer)
Perhaps the link isn't exactly what you need... just replace what isn't needed with stuff in the example.
import arcpy
fc = "c:/data/gdb.gdb/roads"
cursor = arcpy.da.InsertCursor(fc, ["SHAPE@"])
array = arcpy.Array([arcpy.Point(5997611.48964, 2069897.7022),
arcpy.Point(5997577.46097, 2069905.81145)])
spatial_reference = arcpy.SpatialReference(4326)
polyline = arcpy.Polyline(array, spatial_reference)
cursor.insertRow([polyline])
There are other examples in the link I sent, just like the one above