hey , i have the basic licence therere for i cant use Feature Vertices to Points tool.
i've found a code over the internet from this blog:
this is the code:
#feature vertices to points
import arcpy def VerticesToPoints (inFc, workspace, fcName): outFc = UniqueFileName(workspace, fcName) try: #let esri do it (advanced license) arcpy.FeatureVerticesToPoints_management (inFc, outFc) return outFc except: pass #no advanced license sr = arcpy.Describe (inFc).spatialReference outPath, outName = os.path.split (outFc) arcpy.CreateFeatureclass_management (outPath, outName, "POINT", spatial_reference = sr) with arcpy.da.InsertCursor (outFc, "SHAPE@") as iCurs: with arcpy.da.SearchCursor (inFc, "SHAPE@") as sCurs: for geom, in sCurs: for i in range (geom.partCount): part = geom.getPart (i) for pnt in part: if not pnt: continue row = (pnt,) iCurs.insertRow (row) del iCurs del sCurs return outFc
now, i tried to put my inputs in this code but it wont run..
my inputs are:
the existing polyine is called :'zpoints.shp'
and my output directory is :'c:/gis/project'
the new point layer to be created is called: 'test.shp'
where i need to write my inputs in the code?
thanks for the help!
Solved! Go to Solution.
As Luke said, you need to call the function AND you need to define the function UniqueFileName() - as this code calls it.
The code below adds a small function to do what I guess UniqueFileName() was trying to do, and shows you how to call VerticesToPoints() without having to create a script tool.
#feature vertices to points
import arcpy
def UniqueFileName(workspace, fcName):
return workspace + "\\" + fcName
def VerticesToPoints(inFc, workspace, fcName):
outFc = UniqueFileName(workspace, fcName)
try:
#let esri do it (advanced license)
arcpy.FeatureVerticesToPoints_management (inFc, outFc)
return outFc
except:
pass
#no advanced license
sr = arcpy.Describe (inFc).spatialReference
outPath, outName = os.path.split (outFc)
arcpy.CreateFeatureclass_management (outPath,
outName,
"POINT",
spatial_reference = sr)
with arcpy.da.InsertCursor (outFc, "SHAPE@") as iCurs:
with arcpy.da.SearchCursor (inFc, "SHAPE@") as sCurs:
for geom, in sCurs:
for i in range (geom.partCount):
part = geom.getPart (i)
for pnt in part:
if not pnt:
continue
row = (pnt,)
iCurs.insertRow (row)
del iCurs
del sCurs
return outFc
inFc = "tmp_ln" # input line feature class
workspace = r"C:\temp\Scratch.gdb" # GDB
fcName = "tmp_pt" # output point FC
VerticesToPoints(inFc, workspace, fcName)
It's a function. You need to call it:
VerticesToPoints ("C:/path/to/zpoints.shp", "c:/gis/project", "test.shp")
You could also research how to create a python script tool.
As Luke said, you need to call the function AND you need to define the function UniqueFileName() - as this code calls it.
The code below adds a small function to do what I guess UniqueFileName() was trying to do, and shows you how to call VerticesToPoints() without having to create a script tool.
#feature vertices to points
import arcpy
def UniqueFileName(workspace, fcName):
return workspace + "\\" + fcName
def VerticesToPoints(inFc, workspace, fcName):
outFc = UniqueFileName(workspace, fcName)
try:
#let esri do it (advanced license)
arcpy.FeatureVerticesToPoints_management (inFc, outFc)
return outFc
except:
pass
#no advanced license
sr = arcpy.Describe (inFc).spatialReference
outPath, outName = os.path.split (outFc)
arcpy.CreateFeatureclass_management (outPath,
outName,
"POINT",
spatial_reference = sr)
with arcpy.da.InsertCursor (outFc, "SHAPE@") as iCurs:
with arcpy.da.SearchCursor (inFc, "SHAPE@") as sCurs:
for geom, in sCurs:
for i in range (geom.partCount):
part = geom.getPart (i)
for pnt in part:
if not pnt:
continue
row = (pnt,)
iCurs.insertRow (row)
del iCurs
del sCurs
return outFc
inFc = "tmp_ln" # input line feature class
workspace = r"C:\temp\Scratch.gdb" # GDB
fcName = "tmp_pt" # output point FC
VerticesToPoints(inFc, workspace, fcName)
hey,
still dont work for me:
here is the data from Arcgis Pro:
what i did wrong?
The describe function fails because the path to 'zzpoints' does not exist. Note it takes it path relative to the currently active workspace: you could set the active workspace in your script before you access the feature class:
arcpy.env.workspace = r"C:\Users\sasim\Documents\ArcGIS\Projects\MyProjects\MyProject.gdb"
Exactly. Or provide a fully qualified path to the feature class:
inFc = r"C:\Users\sasim\Documents\ArcGIS\Projects\MyProject\MyProject.gdb\zpointss" # input line feature class
thank you very much! it works !!
@matu89, please mark some responses as accepted solution to close out this thread.