Get Maximum and Minimum Elevation Value.

3315
3
09-26-2015 01:16 AM
RajP
by
New Contributor

Hello,

I have Grid shape file and Point shape file. In the point Shape file there is the "Elevation value". I had updated the Gridno to the point shape file using Spatial join and named as "PointwithGridNo". I want to get the maximum and minimum elevation values of every GridNo in the "PointwithGridNo" using Python script. Can any one suggest me.

0 Kudos
3 Replies
DanPatterson_Retired
MVP Emeritus

What have you got so far as a script?  Can you do it manually? Because if you know how, then it can be scripted

XanderBakker
Esri Esteemed Contributor

I haven't tested this, but I assume that you could use something like this (although some sample data would be helpful):

def main():
    import arcpy

    # include path to PointwithGridNo
    fc = r"C:\Folder\SubFolder\yourFGDB.gdb\PointwithGridNo"

    # change names of fields according to your data
    fld_gridno = "GridNo"
    fld_elevation = "elevation"
    fld_min = "min_elevation"  # assuming this field already exists
    fld_max = "max_elevation"  # assuming this field already exists

    # create dictionary with min and max values per GridNo
    flds = (fld_gridno, fld_elevation)
    dct_minmax = {}
    with arcpy.da.SearchCursor(fc, flds) as curs:
        for row in curs:
            gridno = row[0]
            elevation = row[1]
            if gridno in dct_minmax:
                min_elev = dct_minmax[gridno]["min"] if dct_minmax[gridno]["min"] < elevation else elevation
                max_elev = dct_minmax[gridno]["max"] if dct_minmax[gridno]["max"] > elevation else elevation
                dct_minmax[gridno] = {"min": min_elev, "max": max_elev}
            else:
                dct_minmax[gridno] = {"min": elevation, "max": elevation}

    # use update cursor to update min and max elevation
    flds = (fld_gridno, fld_min, fld_max)
    with arcpy.da.SearchCursor(fc, flds) as curs:
        for row in curs:
            gridno = row[0]
            if gridno in dct_minmax:
                row[1] = dct_minmax[gridno]["min"]
                row[2] = dct_minmax[gridno]["max"]
            curs.updateRow(row)

if __name__ == '__main__':
    main()
curtvprice
MVP Esteemed Contributor

Raj: the Summary Statistics tool should do the trick. There's a python example in the help.

Summary Statistics—Help | ArcGIS for Desktop