-1

I'm fairly new to the python world, this being my first script I've written myself, but am looking for some help.

Besides the script needing to be tidied up, I'm having issues with a geoprocessing tool using arcpy. I'd like to create tessellations based on clusters of point data, and eventually within the tessellation, have less than 50 points. I've created a script, which runs, however, I'm trying to automate the Areal Unit for the generate tessellation tool and it seems to hang up. I end up killing the script.

Updated to add new code:

So the new code is supposed to create a hexagon tessellation, join with pnts file and for join counts > 50 create hexagon tessellations drilling down to 50 pnts per hexagon. This is my first attempt at python functions and jumping in feet first. First major error is an invalid domain range but I'm having issues as to what exactly that means and is calling for.

I know its with the final line of the code I believe.

import arcpy as ap
import os

ap.env.overwriteOutput = True
ap.env.workspace = "D:\\Ed_Stuff\Testing\All_Test_Workspace.gdb"
out_gdb = "D:\\Ed_Stuff\Testing\All_Test_Out.gdb"
pnts = "D:\Ed_Stuff\Hexagon.gdb\hexagon_subset"
out_fc = "D:\\Ed_Stuff\Testing\All_Test_Workspace\Total_Tess.shp"

def create_hex(pnts, out_fc, level=0, area=2560608986):
    #pull extent from initial point feature
    desc = ap.Describe(pnts)
    Ext = desc.extent
    SR = desc.SpatialReference
    #generate hexagon for initial extent
    out_fc = os.path.join(out_gdb,'hex_level_{0}'.format(level))
    ap.GenerateTessellation_management(out_fc, Ext, "Hexagon", area, SR)
    print "Worked Check 1"
    #spatially join with point layer
    ap.MakeFeatureLayer_management(pnts, 'pnts_lyr')
    fc_join = os.path.join(out_gdb, 'join_level_{0}'.format(level))
    ap.SpatialJoin_analysis(out_fc, 'pnts_lyr', fc_join, "JOIN_ONE_TO_ONE", "KEEP_ALL", "INTERSECT")
    print "Worked Check 2"
    ##ap.MakeFeatureLayer_management(fc_join, "fc_join_lyr", "'Join_Count'<50")
    ##ap.SelectLayerByAttribute_management (in_layer_or_view, {selection_type}, {where_clause}, {invert_where_clause})
    #make layer of all hexes with 'Join_Count' < 50 and append to output tess file
    ap.MakeFeatureLayer_management(fc_join, "fc_join_lyr", "'Join_Count'<50")
    ap.Append_management(fc_join_lyr, out_fc)
    print "Apended Again"+fc_join
    field = arcpy.ListFields(fc_join, "Join_Count")
    for field in fc_join:
        if 'Join_Count' > 50 and level < 32:
            ap.Dissolve_management(fc_join, dis_hex, ['OID'], '', "MULTI_PART", '')
            hex_multi = os.path.join(out_gdb, 'multihex_level_{0}'.format(level))
            ap.MultipartToSinglepart_management (dis_hex, hex_multi)
            print "Working... Maybe"
            with arcpy.da.SearchCursor(hex_multi, field('OID')) as cursor:
                for field in cursor:
                    hex = "in_memory/hex_{0}_{1}".format(level, 'OID')
                    desc = ap.Describt(hex)
                    Ext = desc.extent
                    create_hex(hex, out_fc, level+1, area*(1/3))
                    print "Boots and Pants"
                    ap.Delete_management(hex)

        elif level >= 32:
            ap.Append_management(fc_join_lyr, out_fc)
            print "Done at 32!"

create_hex(pnts, out_fc)

This is my error: Traceback (most recent call last): File "D:/Ed_Stuff/Testing/Def_Tess_Test.py", line 50, in create_hex(pnts, out_fc) File "D:/Ed_Stuff/Testing/Def_Tess_Test.py", line 17, in create_hex ap.GenerateTessellation_management(out_fc, Ext, "Hexagon", area, SR) File "C:\Program Files (x86)\ArcGIS\Desktop10.4\ArcPy\arcpy\management.py", line 15539, in GenerateTessellation raise e ExecuteError: ERROR 000375: Invalid range domain. Failed to execute (GenerateTessellation).

12
  • How long does it run before you need to kill it? How long does the same operation take when executed from inside ArcMap?
    – Erica
    Mar 13, 2017 at 14:06
  • Hi Erica, it ran 12+ hours before I finally killed it. I let it go so long because it's a rather large dataset. Mar 14, 2017 at 18:12
  • I'm trying to figure out how to update my code on here, I've been told to write the script in a function format. I have new code and now new errors. Mar 14, 2017 at 18:13
  • You can click edit to make changes to your question. Did the GenerateTessellation operation take that long within ArcMap? (The Python tools do exactly the same thing as the ArcMap operations, since they are really just wrappers -- so they will take approximately the same time to run. I have some that run for daaaaaays :/ )
    – Erica
    Mar 14, 2017 at 18:15
  • Can you include the exact error that you're getting? (It'll tell you what line of code it is on.)
    – Erica
    Mar 14, 2017 at 18:24

1 Answer 1

0

That error definitely indicates that GenerateTesselation is where it's failing. I'm guessing at the cause, though. Possible solutions...

  1. Change the Shape_Type to "HEXAGON" instead of "Hexagon"
  2. More likely, the areal unit (parameter Size) should have units specified with it. Right now area is defined as an integer, and appears to need to be a string instead, with units specified (e.g. "5000 SquareMiles").

    The example code from the GenerateTesselation help page may be useful:

    # Find the width, height and linear unit used by the input feature class' extent
    # Divide the width and height value by three
    # Multiply the divided values together and specify an area unit from the linear unit
    # Should result in a 4x4 grid covering the extent. (Not 3x3 since the squares hang over the extent.)
    w = extent.width
    h = extent.height
    u = extent.spatialReference.linearUnitName
    area = "{size} Square{unit}s".format(size=w/3 * h/3, unit=u)
    

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.