Quantcast
Channel: Forums - Python
Viewing all articles
Browse latest Browse all 2485

XYZ to GRID in Python - performance

$
0
0
Hello,
I have really a lot of zip files which contains *.xyz files and my job is to convert these xyz files to the GRID/DEM.
I want to use Python and the ArcPy. In the first step, I will extract xyz file, go through these file line by line and I'll add the "points" (lines, one by one) to the POINT feature class using the Insert Cursor (I am using 10.0 version of desktop).
In second step I will convert this point feature class to GRID or terrain model... in Spatial Analyst... but what do you thing about first Python step? It will take a really long time. Is there any way to do it differently?? Faster??
Here is sample of my Python script:

Code:

import zipfile
import os
import arcpy

dirPath = "C:/Workspace/Data/tmp/tmpzip/"
outputFileGdb = "C:/Workspace/Data/tmp/test.gdb/"

if (not arcpy.Exists(outputFileGdb + "lidarPoints")):
    arcpy.CreateFeatureclass_management(outputFileGdb, "lidarPoints", "POINT", "", "DISABLED", "ENABLED")

fileInDirList = os.listdir(dirPath)
for file in fileInDirList:
        if file.endswith(".zip"):
                z = zipfile.ZipFile(dirPath + file, "r")
                for filename in z.namelist():
                        if filename.endswith(".xyz"):
                                print filename
                                f = z.open(filename, 'r')
                                content = f.read()
                                f.close()
                                lines = content.splitlines(True)
                                for line in lines:
                                    try:
                                                line = line.strip()
                                                point = line.split(' ')
                                                esriPoint = arcpy.Point()
                                                esriPoint.X = point[0]
                                                esriPoint.Y = point[1]
                                                esriPoint.Z = point[2]
                                                cur = arcpy.InsertCursor(outputFileGdb + "lidarPoints")
                                                row = cur.newRow()
                                                row.shape = esriPoint
                                                cur.insertRow(row)
                                                del cur, row
                                        except Exception as e:
                                                print e

Thanks for help and ideas.

RendyO
Czech Republic

Viewing all articles
Browse latest Browse all 2485

Trending Articles