Issue with Z Values Being Zero in Polylines and Polygons

303
9
4 weeks ago
SononosoT
Emerging Contributor

現在、ArcGIS Pro 3.3で作業しているときに問題が発生しています。具体的には、Z 値を持つポリラインとポリゴンの両方を作成しようとしていますが、フィーチャクラスへの挿入時に Z 値が 0 に設定されています。

以下は、私のプロセスの概要です。

  1. 「ExampleDatabase.gdb」という名前のファイル ジオデータベースと、Z が有効なポリライン フィーチャクラスを作成します。
  2. 指定したZ値でポリラインジオメトリを作成します。
  3. an を使用して、ポリラインをフィーチャクラスに追加します。カーソルの挿入
  4. ポリゴン フィーチャクラスを作成する場合も同様の手順を実行しますが、Z 値が 0 に設定されている場合でも同じ問題が発生します。

これらの手順を実行しても、挿入されたポリラインとポリゴンの両方の Z 値は常に 0 として返されます。

参考までに私のコードのスニペットを次に示します。

import arcpy
import os

# Create a file geodatabase
output_folder = r"D:/temp"
gdb_name = "ExampleDatabase.gdb"
gdb_full_path = os.path.join(output_folder, gdb_name)

if not arcpy.Exists(gdb_full_path):
    arcpy.management.CreateFileGDB(out_folder_path=output_folder, out_name=gdb_name)

# Create a polyline feature class
feature_class_name_polyline = "counties_polyline"
arcpy.CreateFeatureclass_management(
    out_path=gdb_full_path,
    out_name=feature_class_name_polyline,
    geometry_type="POLYLINE",
    has_z="ENABLED"  # Enable Z values
)

# Create polyline geometry with Z values
array_polyline = arcpy.Array([arcpy.Point(1000.0, 2000.0, 50.0),
                               arcpy.Point(1500.0, 2500.0, 75.0),
                               arcpy.Point(2000.0, 3000.0, 100.0)])
polyline = arcpy.Polyline(array_polyline)

# InsertCursor to add new polyline geometry
with arcpy.da.InsertCursor(os.path.join(gdb_full_path, feature_class_name_polyline), ['SHAPE@']) as cursor:
    cursor.insertRow([polyline])

# Create a polygon feature class
feature_class_name_polygon = "counties_polygon"
arcpy.CreateFeatureclass_management(
    out_path=gdb_full_path,
    out_name=feature_class_name_polygon,
    geometry_type="POLYGON",
    has_z="ENABLED"  # Enable Z values
)

# Create polygon geometry with Z values
array_polygon = arcpy.Array([arcpy.Point(1000.0, 2000.0, 50.0),
                              arcpy.Point(1500.0, 2000.0, 50.0),
                              arcpy.Point(1500.0, 2500.0, 50.0),
                              arcpy.Point(1000.0, 2500.0, 50.0),
                              arcpy.Point(1000.0, 2000.0, 50.0)])  # Closing the polygon
polygon = arcpy.Polygon(array_polygon)

# InsertCursor to add new polygon geometry
with arcpy.da.InsertCursor(os.path.join(gdb_full_path, feature_class_name_polygon), ['SHAPE@']) as cursor:
    cursor.insertRow([polygon])

# Check Z values for polyline
with arcpy.da.SearchCursor(os.path.join(gdb_full_path, feature_class_name_polyline), ['SHAPE@']) as cursor:
    for row in cursor:
        geometry = row[0]
        for part in geometry:
            for p in part:
                print("Polyline - X:", p.X, "Y:", p.Y, "Z:", p.Z)  # Output Z values

# Check Z values for polygon
with arcpy.da.SearchCursor(os.path.join(gdb_full_path, feature_class_name_polygon), ['SHAPE@']) as cursor:
    for row in cursor:
        geometry = row[0]
        for part in geometry:
            for p in part:
                print("Polygon - X:", p.X, "Y:", p.Y, "Z:", p.Z)  # Output Z values

 

両方のフィーチャクラスが Z 値を有効にして作成されていますが、挿入されたポリラインとポリゴンの Z 値は常に 0 として報告されることを確認しました。

なぜこれが起こっているのかを理解するのを手伝ってくれませんか?ご指導やご提案をいただければ幸いです。

ご協力いただきありがとうございます!

よろしくお願いいたします

0 Kudos
9 Replies
SononosoT
Emerging Contributor

I apologize for the text being in my native language.

I am currently experiencing an issue when working with ArcGIS Pro3.3. Specifically, I am trying to create both polylines and polygons with Z values, but the Z values are being set to 0 upon insertion into the feature class.

Here is a brief overview of my process:

 

I have verified that both feature classes are created with Z values enabled, but the Z values of the inserted polylines and polygons are always reported as 0.

Could you please assist me in understanding why this might be happening? Any guidance or suggestions would be greatly appreciated.

  1. I create a file geodatabase named "ExampleDatabase.gdb" and a polyline feature class with Z enabled.
  2. I construct a polyline geometry with specified Z values.
  3. I use an InsertCursor to add the polyline to the feature class.
  4. I perform similar steps for creating a polygon feature class, but I encounter the same issue with the Z values being set to 0.

Despite following these steps, the Z values of both the inserted polylines and polygons are always returned as 0.

DanPatterson
MVP Esteemed Contributor

Have you tried to create a list of your poly* features, then use the Copy Features tool/function as in this blog

Working with 3D and M-aware geometries in Arcpy - Esri Community

might be worth a shot to see if it could be an alternative to cursors.


... sort of retired...
DavidSolari
MVP Regular Contributor

You need to specify that your Polyline object is Z enabled, even if you pass in three dimensional points. This is because the third dimension could be Z values or M values. I've also added a spatial reference where necessary. Please see this corrected excerpt of your code:

sr = arcpy.SpatialReference(6679)

# Create a polyline feature class
feature_class_name_polyline = "counties_polyline"
arcpy.CreateFeatureclass_management(
    out_path=gdb_full_path,
    out_name=feature_class_name_polyline,
    geometry_type="POLYLINE",
    has_z="ENABLED",  # Enable Z values
    spatial_reference=sr
)

# Create polyline geometry with Z values
array_polyline = arcpy.Array([arcpy.Point(1000.0, 2000.0, 50.0),
                               arcpy.Point(1500.0, 2500.0, 75.0),
                               arcpy.Point(2000.0, 3000.0, 100.0)])
polyline = arcpy.Polyline(array_polyline, has_z=True, spatial_reference=sr)

# InsertCursor to add new polyline geometry
with arcpy.da.InsertCursor(os.path.join(gdb_full_path, feature_class_name_polyline), ['SHAPE@']) as cursor:
    cursor.insertRow([polyline])

 

DanPatterson
MVP Esteemed Contributor

# Create a polygon feature class
feature_class_name_polygon = "counties_polygon"
arcpy.CreateFeatureclass_management(
out_path=gdb_full_path,
out_name=feature_class_name_polygon,
geometry_type="POLYGON",
has_z="ENABLED" # Enable Z values
)

 

It was... unless the original code was edited by someone other than @SononosoT ... which it shouldn't be


... sort of retired...
0 Kudos
DavidSolari
MVP Regular Contributor

The polyline feature class was Z-enabled but the Polyline object to insert into the feature class was not, this is what I corrected on line 17 of my listing.

DanPatterson
MVP Esteemed Contributor

got it. but

import arcpy
array_polygon = arcpy.Array([arcpy.Point(1000.0, 2000.0, 50.0),
                              arcpy.Point(1500.0, 2000.0, 50.0),
                              arcpy.Point(1500.0, 2500.0, 50.0),
                              arcpy.Point(1000.0, 2500.0, 50.0),
                              arcpy.Point(1000.0, 2000.0, 50.0)])  # Closing the polygon
polygon = arcpy.Polygon(array_polygon)  # polygon object
out_fc = r"C:\arcpro_npg\Project_npg\npgeom.gdb\copy_poly_tst"
arcpy.CopyFeatures_management([polygon], out_fc)

copy_poly.png

seems to work as @XanderBakker suggested back in the day


... sort of retired...
HaydenWelch
MVP Regular Contributor

This is an easy one, you have a Z-enabled featureclass, but you aren't creating z-enabled Geometry:

 

polygon = arcpy.Polygon(array_polygon, has_z=True)
polyline = arcpy.Polyline(array_polyline, has_z=True)

 

EDIT: Just saw that David figured this out yesterday... Only saw one response when I clicked in -_-

 

0 Kudos
SononosoT
Emerging Contributor

Thank you everyone for your comments. I was able to successfully create data that includes Z values.

  • Added the coordinates (XYZ) to a list of tuples.
  • Added those coordinates to the list of tuples.
  • Converted each tuple to a point object and added them to a list of points.
  • Saved the polygons to a feature class using arcpy.CopyFeatures_management.

I was really struggling, so everyone help was truly appreciated. Thank you very much!!

0 Kudos
DanPatterson
MVP Esteemed Contributor

As suggested and originally posted by @XanderBakker 

Old is new 😉


... sort of retired...