4

I am working on some scripts with 3D polygons using ArcPy (ArcGIS 10). Reading and data manipulation works fine. However, writing the output back into a shapefile does not seem to work, it only generated 2D files. For writing I use the following function:

import arcpy    
def write_new_MP(data,outfile):
        array = arcpy.Array()
        point = arcpy.Point()
        features=[]
        for feature in data:
            for part in feature:         
                point.X=part[0]
                point.Y=part[1]
                point.Z=part[2]
                array.add(point)
            MP=arcpy.Polygon(array,None,True,True)
            array.removeAll()
            features.append(MP)
        arcpy.CopyFeatures_management(features, outfile,"", "0", "0", "0")
        return

the data is a list likedata=[[[5,5,5],[10,5,5],[10,10,5],[5,10,5],[5,5,5]],[[15,15,15],[10,15,15],[10,10,15],[15,10,15],[15,15,15]]]

Does somebody know why the Z-values aren't used when generating the output?

  • How have you confirmed that the Z isn't written to the file? Are you viewing this in the 3D analyst? – user681 Jun 15 '11 at 15:14
  • by viewing in arcscene, all objects appear flat no matter what z-data is written – Paul Jun 16 '11 at 7:29
  • Are you using an existing feature class or are you creating the fc as part of this script? If it is part of the script can you post that portion as well? How are you setting the coordinate system, etc? – theJones Oct 28 '11 at 16:50
  • Depending on your data you might also need to include another nested loop to account for multi-part features (an array of arrays). So it would go Features -> Parts -> Vertices. – blah238 Oct 30 '11 at 1:11
  • Bringing an old post back from the dead. Can you try enabling the environment variable "outputZFlag" to see if that makes a difference? – Barbarossa Nov 14 '16 at 20:17
1

Let me say first that I spent few minutes learning what GIS is and few more minutes learning what arcpy is. In addition, I do not have required software to check your code. However, the similarity of your code and the code at Arc Gis Resource Center-Desktop10-polygon example-Create a polyline feature class from scratch is striking. What is missing in your code is the following.

"Add the first point of the array in to close off the polygon"

array.add(array.getObject(0))

in between your lines

array.add(point)
MP=arcpy.Polygon(array,None,True,True)

Did you try that already?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.