-1

I have a python script which dies after the first iteration. It dies on the second feature class to coverage. This also happened in modelbuilder, which is why I went to python hoping it would go away. I can create the coverage on the layer that crashes the script in the standalone tool, but once in the script, after the first iteration, it dies. It makes me think that there is something being held on to in memory by the script or modelbuilder that I am not aware of.

I have tried repairing geometry of the input dataset; ensuring it is singlepart; name chages. None has worked.

View image for error in image. It says invalid topology, but it works fine standalone.

enter image description here

import arcinfo, arcpy, os, sys
from arcpy import env
print 'Starting....'
env.OverWriteOutput = True
arcpy.SetProduct("ArcInfo")
import datetime
import time
ts = time.time()
st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
print st

tbx = arcpy.ImportToolbox(r"C:\Program Files (x86)\ArcGIS\Desktop10.1\ArcToolbox\Toolboxes\Coverage Tools.tbx", "COVG")
SDE = "C:\\Users\\david\\AppData\\Roaming\\ESRI\\Desktop10.1\\ArcCatalog\\p747.sde"
AVI = r"C:\david\delete\AVI.shp"
#AVI = "G:\\ALPAC\\Projects\\P747\\3_Landbase\\Processing\\AVI\\AVI_20141216_Only_polynum.shp"
FMUs = r"C:\david\delete\fmus2.shp"
#FMUs = r"\\silver\\clients\Projects\P747\3_Landbase\LB1\FileGeodatabase\All_Data\All_Data.gdb\ALPAC_Data\Administrative_FMUs"
GDB1 = "\\\\silver\\clients\\Projects\\P747\\3_Landbase\\LB1\\Temp\\"
FCView = "\\\\silver\\clients\\Psrojects\\P747\\3_Landbase\\LB1\\TEMP\\FCView.lyr"
LayerU = r"G:\Projects\P747\3_Landbase\LB1\Multiunion\TEMP\Union_Fwrd"
OutLOC = "\\\\silver\\clients\\Projects\\P747\\3_Landbase\\LB1\\multiunion\\m_20150129\\"
TableView = "\\\\silver\\client\\Projects\\P747\\3_Landbase\\LB1\\Temp\\Tableview.lyr"

FieldMappings = arcpy.FieldMappings()
FieldMap1 = arcpy.FieldMap()
#arcpy.RepairGeometry_management(FMUs)
if arcpy.Exists(FCView):
    arcpy.Delete_management(FCView)

arcpy.MakeFeatureLayer_management(FMUs, FCView)

FieldMap1.addInputField(FMUs, 'FMU_NAME')
FieldMappings.addFieldMap(FieldMap1)

r = 1
for row in arcpy.SearchCursor(FCView):

    objectid = str(row.getValue("FMU_NAME"))
    #print '"FMU_NAME"= {}'.format(objectid)
    print 'Working on ' + objectid

    FMUNAME = GDB1 +  "FMU_" + objectid + ".shp"
    AVINAME = GDB1 + "AVI_" + objectid + ".shp"
    OUTCOV = OutLOC+ "MU_" + objectid
    OUTCOVPOLY = OutLOC+ "MU_" + objectid + " POLYGON"

    if arcpy.Exists(FMUNAME):
        arcpy.Delete_management(FMUNAME)
    if arcpy.Exists(AVINAME):
        arcpy.Delete_management(AVINAME)
    if arcpy.Exists(OUTCOV):
        arcpy.Delete_management(OUTCOV)
    if arcpy.Exists(GDB1+ "MUa_" + objectid):
        arcpy.Delete_management(GDB1+ "MUa_" + objectid)
    if arcpy.Exists(GDB1+ "FMU_" + objectid):
        arcpy.Delete_management(GDB1+ "FMU_" + objectid)
    if arcpy.Exists(TableView):
        arcpy.Delete_management(TableView)
    if arcpy.Exists(GDB1 + "AVICV_" + objectid):
        arcpy.Delete_management(GDB1 + "AVICV_" + objectid)
    if arcpy.Exists(GDB1 + "AVIa_" + objectid + ".shp"):
        arcpy.Delete_management(GDB1 + "AVIa_" + objectid + ".shp")

    arcpy.SelectLayerByAttribute_management(FCView, "NEW_SELECTION", '"FMU_NAME"=' + "'" + objectid + "'")

    print 'Creating FMU shape and coverage for clipping'

    arcpy.FeatureClassToFeatureClass_conversion(FCView , GDB1, "FMU_" + objectid, "#", FieldMappings)
    arcpy.FeatureclassToCoverage_conversion(FMUNAME + " POLYGON", GDB1 + "FMU_" + objectid, "", "DOUBLE")

    print 'Running clips'

    arcpy.Clip_COVG(LayerU, GDB1 + "FMU_" + objectid, GDB1+ "MUa_" + objectid)
    arcpy.Clip_analysis(AVI, FMUNAME, GDB1 + "AVI_" + objectid)

    #print 'Repairing geometry'

    #arcpy.RepairGeometry_management(GDB1 + "AVI_" + objectid + ".shp")

    print 'Turn AVI into coverage'

    #ERROR OCCURS HERE !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    arcpy.FeatureclassToCoverage_conversion(AVINAME + " POLYGON", GDB1 + "AVICV_" + objectid, "", "DOUBLE")

    print 'Unioning the ' + objectid + " datasets"

    arcpy.Union_COVG(GDB1 + "AVICV_" + objectid, GDB1+ "MUa_" + objectid, OutLOC + "MU_" + objectid)

    #print 'Running multi-part to single-part'

    #arcpy.MultipartToSinglepart_management(GDB1 + "AVIa_" + objectid + ".shp", GDB1 + "AVI_" + objectid)

    print 'Calculating fields'

    arcpy.MakeTableView_management(OUTCOV +'\\polygon', TableView)
    arcpy.AddField_management(TableView, "MKey", "LONG", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.CalculateField_management(TableView, "MKey", "( " + str(r) + " * 1000000 ) + !FID!", "PYTHON", "")
    arcpy.AddField_management(TableView, "AreaHA", "DOUBLE", "", "", "", "", "NULLABLE", "NON_REQUIRED", "")
    arcpy.CalculateField_management(TableView, "AreaHA", "!shape.area@hectares!", "PYTHON", "")

    print 'Deleting fields'

    arcpy.DeleteField_management(TableView, "U20#;U20-ID;U19#;U19-ID;U18#;U18-ID)

    #print 'Deleting fields'
    #if arcpy.Exists(SDE + objectid + "_tables_v2"):
    #    arcpy.Delete_management(SDE + objectid + "_tables_v2")

    #print 'Table to table'
    #arcpy.TableToTable_conversion(TableView, SDE2, objectid + "_tables_v2")

    #print 'Deleting fields'
    #arcpy.DeleteField_management(TableView, "FEATURE_TY;NAME;TS_BUFF;PLOT_TYPE;DISP_NUM;DISP_TYPE;LANDBASE;RIVBRK;FMU_NAME;MOSA;SLOPE;FIRE_NUMBE;BURNCODE;BURN_CLASS;YEAR;RFMA_NAME;HYD_FEAT;CRPRO_NAME;TYPE;PPA_STAT;DIDS_NUM;DIDS_TYPE;ID;WTRSHED;FN_TYPE;FN_NAME;MUNIC_TYPE;MUNIC_NAME;FMA_STATUS;FEATURE_NA;DFA_STATUS;HY_DIST;HY_SRCE;HY_FEATURE;POLYGON;OWNER_1;STATUS;OWNERSHIP;CATEGORY;OPEN_NUM;COWPER_LOS;RSIID;POLY_NUM")

    ts = time.time()
    st = datetime.datetime.fromtimestamp(ts).strftime('%Y-%m-%d %H:%M:%S')
    print st

    print 'Next....'

    r += 1

python 2.7, Arcinfo license and 10.2 Arc

PolyGeo
  • 65,136
  • 29
  • 109
  • 338
D_C
  • 1,359
  • 10
  • 23
  • For that error message my first thought is always a lack of memory - see http://gis.stackexchange.com/a/90531 - also, it is far better to include error messages as text rather than pictures so that they can be searched for. It looks like you have run it at the DOS prompt which may make that hard to copy/paste so I would try running it from IDLE instead. – PolyGeo Feb 01 '15 at 03:47
  • I can do that for sure with the image. As for your comment, I think something like that is happening; as if after the first iteration, the memory is held onto. Is there a way to dump everything after the iteration? – D_C Feb 01 '15 at 03:49
  • Some people have suggested using Python's subprocess (e.g. https://geonet.esri.com/thread/49275) and I started to investigate that once a few years ago but I think I found that upping the RAM solved my issues and so I abandoned that effort. – PolyGeo Feb 01 '15 at 03:56
  • I've got 16GB and 64 bit. I have access to a virtual machine on our network with 48GB and 64 bit but the modelbuilder version of this process crashed on it too. – D_C Feb 01 '15 at 04:02
  • You may need to consider the approach that I suggested on another ERROR 999999 at http://gis.stackexchange.com/a/92421 - it is certainly what I would have pursued if that error became a showstopper for me. – PolyGeo Feb 01 '15 at 04:05
  • I have also just noticed that the coverage created in python in the first iteration is bigger (more records) than the one that it crashes on ( as checked through the stand alone run). So the memory hang is more and more likely. – D_C Feb 01 '15 at 04:05
  • You could try splitting your script out into one script per iteration and then writing them into a *.bat so that it becomes a series of standalone runs. – PolyGeo Feb 01 '15 at 07:17
  • I was thinking in the line of segmentation somehow, but am still new to pyhton. Never used .bat before, so will have to look into it. Any good resources you can think of?

    I tried on the 46gb RAM virtual machine to the same error.

    – D_C Feb 01 '15 at 16:24
  • Naming of in_features in error line seems strange. It is something like "AVI_OBJECTNAME.shp POLYGON". Is this a legal thing at all? – FelixIP Feb 01 '15 at 21:31
  • Ooops. Disregard one above. It refers to other tool – FelixIP Feb 01 '15 at 21:38
  • It says INVALID TOPOLOGY, Coverages are NOT tolerant for topology errors. Use Repair Geometry to clean up the data before you try to convert to a coverage. Also be aware that there is a restriction in coverage names of 13 characters so I would reccomend using "A" + objectid instead of "AVICV_" + objectid for the name. – Michael Stimson Feb 01 '15 at 23:43
  • I have attempted repair geometry to no avail. The 'objectid' is maximum 3 characters in length, so no possibility of hitting the 13 character mark. The layers that it crashes on run fine when I do them manually. This process worked fine in modelbuilder 10-15 times before, then something changed to make it crash on the second iteration to which I have no clue; this is why I went to python but it hasn't fixed it. I am researching the .bat idea now. – D_C Feb 02 '15 at 16:09

1 Answers1

1

According to the help file the in_features should be a list of featureclasses and type.

Try changing this line

arcpy.FeatureclassToCoverage_conversion(AVINAME + " POLYGON", GDB1 + "AVICV_" + objectid, "", "DOUBLE")

to

arcpy.FeatureclassToCoverage_conversion([[AVINAME , "POLYGON"]], GDB1 + "AVICV_" + objectid, "", "DOUBLE")
Mark Bryant
  • 1,435
  • 8
  • 7