POST
|
I have found a solution that take a different perspective on the problem. In my first try I created a point object, point geometry list and iterated through list and appended every coordinate pair to geometry list. That didn't pass through the z values though. Now I create a table and add appropiate fields, use an insertCursor, iterate through the point list and pass X, Y and Z values in to the correct fields. From there I create an XYEvent layer and finally copy to a point feature layer. Works great! # Import arcpy import arcpy # Set the outputZFlag environment to Enabled arcpy.env.outputZFlag = "Enabled" # Input feature class inFC = arcpy.GetParameterAsText(0) outFolder = arcpy.GetParameterAsText(1) outFC = arcpy.GetParameterAsText(2) # Set workspace arcpy.env.workspace = outFolder # Create describe desc = arcpy.Describe(inFC) shapefieldname = desc.ShapeFieldName inFCCoordinateSystem = desc.SpatialReference inFCDataType = desc.DataType # Create point list ptList = [] # Create cursor and iterate through objects in feature class rows = arcpy.SearchCursor(inFC) for row in rows: # Create the geometry object feat = row.getValue(shapefieldname) partnum = 0 # Step through each part of the feature and append vertice coordinates to point list for part in feat: part_list = [] for pnt in feat.getPart(partnum): ptList.append([pnt.X, pnt.Y, pnt.Z]) partnum += 1 # Create table and add fields x, y, z arcpy.management.CreateTable(outFolder, "XY_Table") arcpy.management.AddField("XY_Table", "X", "DOUBLE") arcpy.management.AddField("XY_Table", "Y", "DOUBLE") arcpy.management.AddField("XY_Table", "Z", "DOUBLE") # Create cursor object cur = arcpy.InsertCursor("XY_Table") # Iterate through ptList and insert a new row in table for every coordinate pair in ptList for pt in ptList: row = cur.newRow() row.X = pt[0] row.Y = pt[1] row.Z = pt[2] cur.insertRow(row) # Create XY event layer arcpy.management.MakeXYEventLayer("XY_Table", "X", "Y", "XY_Table_Event") inTableEvent = "XY_Table_Event" # Create point feature class arcpy.management.CopyFeatures(inTableEvent, outFC) # Delete event layer and table arcpy.management.Delete(inTableEvent) arcpy.management.Delete("XY_Table") # Create describe on out data desc2 = arcpy.Describe(outFC) outFCSpatialRef = desc2.SpatialReference outFCSpatialRefName = outFCSpatialRef.name # Check if out data has spatial reference, # if not, project in data spatial reference on out data if outFCSpatialRefName == "Unknown": arcpy.management.DefineProjection(outFC, inFCCoordinateSystem) else: pass
... View more
08-03-2012
05:16 AM
|
0
|
0
|
792
|
POST
|
I just figured it out with your help, thanks! When I use GetParameterAsText I actually point out the table in the Excel file, not the Excel file itself, which is exactly what you're doing when setting the Excel file as a workspace. I tried and tried listing the Excel file (not the table within) while having the folder as a workspace. That kinda make sense now.
... View more
08-03-2012
12:30 AM
|
0
|
0
|
519
|
POST
|
It didn't work to kick ArcGIS in the... However, I found a solution (sort of). When I use arcpy.ListTables() in the Python interpreter in ArcCataloge it won't list any tables in excel format but will list tables in dbf format. However, my intention was to use it in a script tool and there arcpy.ListTables works just fine with excel format. I'm not sure but I think it has something to do with formatting pathways. In my script to I use arpy.GetParameterAsText and that works fine.
... View more
08-02-2012
02:16 AM
|
0
|
0
|
519
|
POST
|
I'm creating a file GDB and then importing tables (Excel) with TableToGeodatabase. After that I want to list them using arcpy.ListTables but it results in an empty list, even though they are there when I check in ArcCatalouge. In ArcCatalouge I can copy the tables for example but in the Python window I can't list them or access them (like they don't exist). However, if I create a file geodatabase in ArcCatalouge and then import the tables using right click > import (table, multiple) the tables will show up in Python using arcpy.ListTables() import arcpy # Get parameters to create geodatabase OutputFolder = arcpy.GetParameterAsText(0) FGDName = arcpy.GetParameterAsText(1) # Create File GDB... OutputGDB = OutputFolder + '\\' + FGDName + '.gdb' arcpy.management.CreateFileGDB(OutputFolder, FGDName) # Set current workspace to to file geodatabase arcpy.env.workspace = OutputFolder # Get parameters to import tables to geodatabase adress = arcpy.GetParameterAsText(2) adress_xy = arcpy.GetParameterAsText(3) # Import tables to geodatabase arcpy.conversion.TableToGeodatabase([adress, adress_xy], OutputGDB) Any help would be greatly appreciated- Thanks / Rickard
... View more
07-31-2012
06:22 AM
|
0
|
4
|
2700
|
POST
|
Unfortunately it doesn't work. The feature class created already have hasZ = True. The output feature class includes X and Y coordinates as well as a column for Z-values, but that only has 0 (zero) as opposed to the correct values. When I check ptList in Python all the z-values are there, but I don't manage to get them to the feature class. Rickard
... View more
07-30-2012
11:01 PM
|
0
|
0
|
792
|
POST
|
I'm trying to create a point feature class using vertices from a line feature class that will add the X, Y, and Z-values. I can't figure out how to get the Z-values to the point feature. I manage to get the X and Y but the Z-values always results in 0. The ptList have Z-values from the vertices but I can't get them to the point feature. I am interested in a solution using python, not using a tool like Vertices To Points. import arcpy # Set the outputZFlag environment to Enabled arcpy.env.outputZFlag = "Enabled" # Input feature class inFC = arcpy.GetParameterAsText(0) outFC = arcpy.GetParameterAsText(1) # Create describe desc = arcpy.Describe(inFC) shapefieldname = desc.ShapeFieldName inFCDataType = desc.DataType # Create point list ptList = [] # Create cursor and iterate through objects in feature class rows = arcpy.SearchCursor(inFC) for row in rows: # Create the geometry object "feat" feat = row.getValue(shapefieldname) partnum = 0 # Step through each part of the feature and append vertice coordinates to point list for part in feat: part_list = [] for pnt in feat.getPart(partnum): ptList.append([pnt.X, pnt.Y, pnt.Z]) partnum += 1 # Create point object, point geometry list and iterate through list # and append every coordinate pair to geometry list. pt = arcpy.Point() ptGeoms = [] for p in ptList: pt.X = p[0] pt.Y = p[1] pt.Z = p[2] ptGeoms.append(arcpy.PointGeometry(pt)) # Create point feature class arcpy.management.CopyFeatures(ptGeoms, outFC) # Add XY to point feature class arcpy.management.AddXY(outFC) Any help would be greatly appreciated! Thanks, Rickard
... View more
07-30-2012
07:01 AM
|
0
|
3
|
3274
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|