Select to view content in your preferred language

# converting contours to points

8190
16
01-13-2015 02:13 PM
Occasional Contributor III

Hello i have a mosaic dem and i have extracted contours wit interval = 2 meters. Now i want to convert contours to points xyz with distance of 1 meter from one point to another at the same contour line for each contour, any suggestion?

Tags (4)
1 Solution

Accepted Solutions
Esri Esteemed Contributor

You can use some python to obtain the points you want:

```import arcpy, os

fc_in = r"C:\Forum\Pasture\gdb\Contours.gdb\contours2"
fc_out = r"C:\Forum\Pasture\gdb\Contours.gdb\contour_pnts03"
fld_contour = "Contour"
interval = 1

# create empty output featureclass
sr = arcpy.Describe(fc_in).spatialReference
out_ws, out_name = os.path.split(fc_out)
arcpy.CreateFeatureclass_management(out_ws, out_name, "POINT", fc_in, "DISABLED", "DISABLED", sr)

# add field with contour value to output fc

cnt = 0
with arcpy.da.InsertCursor(fc_out, ("SHAPE@", fld_contour)) as curs_out:
with arcpy.da.SearchCursor(fc_in, ("SHAPE@", fld_contour)) as curs_in:
for row_in in curs_in:
polyline = row_in[0]
contour = row_in[1]
max_len = polyline.length
d = 0
while d < max_len:
pnt = polyline.positionAlongLine(d, False)
curs_out.insertRow((pnt.firstPoint, contour, ))
cnt += 1
if cnt % 100 == 0:
print "Processing point: {0}".format(cnt)
# pnt.firstPoint
d += interval
curs_out.insertRow((polyline.lastPoint, contour, ))
cnt += 1```

Change the lines 3 and 4 to point to your input featureclass and the output you want to create.

16 Replies
Esri Esteemed Contributor

You can use some python to obtain the points you want:

```import arcpy, os

fc_in = r"C:\Forum\Pasture\gdb\Contours.gdb\contours2"
fc_out = r"C:\Forum\Pasture\gdb\Contours.gdb\contour_pnts03"
fld_contour = "Contour"
interval = 1

# create empty output featureclass
sr = arcpy.Describe(fc_in).spatialReference
out_ws, out_name = os.path.split(fc_out)
arcpy.CreateFeatureclass_management(out_ws, out_name, "POINT", fc_in, "DISABLED", "DISABLED", sr)

# add field with contour value to output fc

cnt = 0
with arcpy.da.InsertCursor(fc_out, ("SHAPE@", fld_contour)) as curs_out:
with arcpy.da.SearchCursor(fc_in, ("SHAPE@", fld_contour)) as curs_in:
for row_in in curs_in:
polyline = row_in[0]
contour = row_in[1]
max_len = polyline.length
d = 0
while d < max_len:
pnt = polyline.positionAlongLine(d, False)
curs_out.insertRow((pnt.firstPoint, contour, ))
cnt += 1
if cnt % 100 == 0:
print "Processing point: {0}".format(cnt)
# pnt.firstPoint
d += interval
curs_out.insertRow((polyline.lastPoint, contour, ))
cnt += 1```

Change the lines 3 and 4 to point to your input featureclass and the output you want to create.

Occasional Contributor III

thanks a lot for your help. I tried your code and i only change the path for my files (line 3 & 4) but when i run the code i get that message.

Runtime error

Traceback (most recent call last):

File "<string>", line 8, in <module>

NameError: name 'os' is not defined

What should i do? Isn't there any solution without code?

Occasional Contributor III

i corrected it and now i get

Parsing error Indentation Error: expected an indented block (line 18)

Occasional Contributor III

now an error 000732 for some reason

MVP Emeritus

the file and/or its path is not supported from the help topic Error 000732 either something is wrong with your file type, you incorrectly specified the path and/or you copied and pasted the code incorrectly

Esri Esteemed Contributor

Can you show what you specified for lines 3 and 4 (your input and output featureclass)? Did you try Dan Patterson‌ suggestion?

Occasional Contributor III

Mr Xander Bakker thanks again, I tried again your code for an area of 10^2 km to find points with distance of 1 meter /contour / 2240 contours and it keeps running for over 6 hours by now. It has calculated already 15.000.000 points. I think is working fine, i haven't already see the result, but  i will post it. On the other hand  I tried both Dan Patterson suggestions (Densify & installation of tool for lower lic. levels) but i get a script error with that tool, or after the procession of densify i cannot see the file of contour on my worrkspace and on attribute table nothing is changed. I haven't figure it out until now what is wrong with densify.

! There is a toll (Station Points) at ET Geowizard but is not free.

! There is also construction points of Editor but you must do it manually for each polyline.

Any other suggestion for tools Arc already has? thank you both

Esri Esteemed Contributor

I am glad it is working, and yes it can be a long process depending on the number of points that need to be generated.

If you can use the standard Densify tool as Dan suggested, you could use the Feature Vertices to Points tool. This tool can convert a line into points, but will only convert the existing vertices (not create any new ones)

Occasional Contributor III

Thank you Mr Baker, but there isn't any tool available in gis specific for that task? I only found ET Geowizard's tool (station points) and nothing else. How can that be?