Select to view content in your preferred language

converting contours to points

8286
16
Jump to solution
01-13-2015 02:13 PM
KONPETROV
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?

16 Replies
XanderBakker
Esri Esteemed Contributor

Good question. At first I thought that this should be available as standard tool in ArcGIS, but that seems not to be the case. Maybe it is because you can string the Densify and Feature Vertices to Points tools together and get the result, but this is not for all licenses available.

KONPETROV
Occasional Contributor III

in which line i can change the code to do the procession for points every 3 meter  for example.

and in which point i can define to run the procession for contour >1000 meters also.

That's my last question, you helped me a lot, thank you very much. 

0 Kudos
XanderBakker
Esri Esteemed Contributor

The code would look like the code below. Notice the following changes:

  • Line 6 holds the interval, I changed it from 1 to 3, so now it picks points every 3 meters on each contour line.
  • Line 14 contains a where clause that filters the contour lines with Contour > 1000
  • Line 21 applies the where clause

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 = 3 # pick points every x meter on every contour line

# 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)

# create a where clause
where = "{0} > {1}".format(arcpy.AddFieldDelimiters(fc_in, fld_contour), 1000)

# add field with contour value to output fc
arcpy.AddField_management(fc_out, fld_contour, "DOUBLE")

cnt = 0
with arcpy.da.InsertCursor(fc_out, ("SHAPE@", fld_contour)) as curs_out:
    with arcpy.da.SearchCursor(fc_in, ("SHAPE@", fld_contour), where_clause=where) 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
0 Kudos
DanPatterson_Retired
MVP Emeritus

It works fine with shapefiles in folders...geodatabases aren't supported

ShahriarRahman
New Contributor III

Hi Xander,


Can it be done for the polygons?

https://community.esri.com/thread/262214-arcpy-script-to-write-same-record-in-another-feature-layer If it can be done for polygons, then it will answer my query.


Thanks in advance.


Kind regards,


Shahriar

0 Kudos
XanderBakker
Esri Esteemed Contributor

Hi Shahriar Rahman 

The original questions extracts points from polylines (contours), but you want to extract points from a polygon? This is possible, but how should these points be distributed? Extract points from the outline of the polygon, generate random points inside the polygon, generate points at a certain distance inside the polygon?

0 Kudos
DanPatterson_Retired
MVP Emeritus

If you have ArcMap 10.2.x at the Advanced level try the Densify tool or try this version for lower license levels, then convert to points