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

Memory issues, ideas?

$
0
0
Hello all, I have written script based on input from a csv that contains 4 lat, lon points per record.
It works fine for quite a few features but attempting to run it over 100,000 or so it runs out of memory suggestions would be appreciated the 2 issues I have are below I only attached the part of the code that is having this issue:

1) it breaks on the featureList.append(polygon) at some large number of records...
If I could save and erase it each time without sacrificing to much speed would be ideal as I want to use it on even larger files.
I did attempt this before moving the copyfeatures up to the loop of lines but it increases the time too much 0.06s to 2.95 mins for 100 records.

2) I also would like to have the orginal .csv information joined to the shapefile/feature created but have not yet done this either based on the amount of time it takes to join the two together.


Maybe there is another way all together?
Thanks! :confused:

Code:


        latIndex = valueList.index(fieldNames[0])
        lonIndex = valueList.index(fieldNames[1])
        llLatIndex = valueList.index(fieldNames[2])
        llLonIndex = valueList.index(fieldNames[3])
        urLatIndex = valueList.index(fieldNames[4])
        urLonIndex = valueList.index(fieldNames[5])
        lrLatIndex = valueList.index(fieldNames[6])
        lrLonIndex = valueList.index(fieldNames[7])

        ##cursor = arcpy.InsertCursor(pointFC)
        for line in inFile.readlines():
        #print line
            field = line.split(",")
        #print fields[0]
            points = [[field[latIndex],field[lonIndex]],[field[llLatIndex],field[llLonIndex]],[field[lrLatIndex],field[lrLonIndex]],[field[urLatIndex],field[urLonIndex]]]
           
            for coordPair in points:
                point.X = coordPair[0]
                point.Y = coordPair[1]
                array.add(point)
               
##        # Add the first point of the array in to close off the polygon
            #print "array"
            array.add(array.getObject(0))

##        # Create a Polygon object based on the array of points
            polygon = arcpy.Polygon(array)

##        # Clear the array for future use
            array.removeAll()

##        # Append to the list of Polygon objects
            featureList.append(polygon)
##
    # Create a copy of the Polygon objects, by using featureList as input to
    #  the CopyFeatures tool.
        try:
            arcpy.CopyFeatures_management(featureList, "feat")
##        ##arcpy.JoinField_management("feat", "OBJECTID", "csv", "OBJECTID")
        except:
            print arcpy.GetMessages()


Viewing all articles
Browse latest Browse all 2485

Trending Articles