Select to view content in your preferred language

ArcPy: Feature to Polygon (in_memory)

5327
1
Jump to solution
05-28-2015 05:15 PM
PeterWilson
Frequent Contributor

I've created a python scripts that takes a feature class (polyline) of contours and a feature class (polyline) that represents the position of a proposed dam wall. I then use the feature to polygon tool to create a polygon from each contour that represents the proposed full supply level of the proposed dam site. I then use Polygon Volume Tool to determine the volume and surface area for each proposed full supply level.

The problem that I'm having is that:

  1. if I use in_memory for the output for feature to polygon, the shape_length & shape_area is missing
  2. if I save the output for each polygon from Feature to Polygon , the shape_length & shape_area is added, but when I try to append the following feature classes into a new feature class using an Insert Cursor, the geometry is not being transferred into the empty feature class.

From the testing that I've done there seems to be a problem in storing the output feature class from Feature to Polygon in_memory as the shape_length & shape_area fields are being dropped, which I tested within ArcMap running the tool and storing the output into memory.

I've also tested the same tools using the same input layers and saved the results to disk, the shape_length and shape_area are then preserved within the output results.

If anyone can give me advice in how to resolve the following, it would be appreciated.

'''
Created on May 28, 2015
@author: PeterW
The following script calculates the volume for each Full Supply Level
to calculate the capacity curve for a proposed dam site
'''
# import system modules and site packages
import arcpy
# Check out 3D Analyst
arcpy.CheckOutExtension("3D")
# set environment settings
arcpy.env.overwriteOutput = True
# set input and output arguments
cont_line = r"F:\Projects\2015\PRCPTWAT02\13176\A34631\wspace\ChrisFox.gdb\Contours"
dw_line = r"F:\Projects\2015\PRCPTWAT02\13176\A34631\wspace\ChrisFox.gdb\Dam_Wall"
fsl_gon = r"F:\Projects\2015\PRCPTWAT02\13176\A34631\wspace\ChrisFox.gdb\Full_Supply_Level"
surf = r"F:\Projects\2015\PRCPTWAT02\13176\A34631\wspace\TIN\tin"
# make feature layer from the dam wall (polyline)
dwLyr = arcpy.MakeFeatureLayer_management(dw_line,"dwLayer")
# convert each FSL contour polyline into a FSL polygon and determine the volume
# below the contour elevation using the polygon volume tool
with arcpy.da.SearchCursor(cont_line,["Elevation"]) as cursor: #@UndefinedVariable
    for row in cursor:
        elev = str(row[0])
        outName = "FSL" + elev + "m"
        sqlExp = "Elevation" + " = " + elev
        contLyr = arcpy.MakeFeatureLayer_management(cont_line, outName, sqlExp)
        fslLyr = "in_memory" + "\\" + outName
        arcpy.FeatureToPolygon_management([contLyr,dwLyr], fslLyr, attributes = True)
        arcpy.AddField_management(fslLyr, "Elevation", "SHORT")
        arcpy.CalculateField_management(fslLyr, "Elevation", elev, "PYTHON_9.3")
        fields = arcpy.ListFields(fslLyr)
        fields = [field.name for field in fields]
        print fields
        with arcpy.da.SearchCursor(fslLyr, fields) as sCur: #@UndefinedVariable
            with arcpy.da.InsertCursor(fsl_gon, fields) as iCur: #@UndefinedVariable
                for sRow in sCur:
                    iCur.insertRow(sRow)

# calculate the volume and surface area for each Full Supply Level polygon and the TIN 
arcpy.PolygonVolume_3d(surf, fsl_gon, "Elevation", "BELOW", "SVolume", "SArea","0")

# print statement that process is completed
arcpy.AddMessage("Completed Processing Capacity Curves")

Regards

Peter Wilson

0 Kudos
1 Solution

Accepted Solutions
JoshuaBixby
MVP Esteemed Contributor

You can use Add Geometry Attribute to add the geometry attributes you want (more than just area and perimeter) to the in-memory feature classes.

View solution in original post

1 Reply
JoshuaBixby
MVP Esteemed Contributor

You can use Add Geometry Attribute to add the geometry attributes you want (more than just area and perimeter) to the in-memory feature classes.