Select to view content in your preferred language

Split Polylines at certain increments

2393
11
01-06-2021 10:45 AM
CCWeedcontrol
Frequent Contributor

I need to create a polyline grid with vertical and horizontal lines of increments of one hundred, somehow divide each polyline/polygon by 9 and across multiple polygons/polylines and I am not sure on how go about doing it. What I have is the polygons/sections and polylines/sections lines.. The polygons/polylines are NOT evenly squared so I can't use fish net, at least I don't think...?

Grid.png

11 Replies
DanPatterson
MVP Esteemed Contributor

It is also easy enough to add transect lines, just do one for each axis orientation.

Transect lines, parallel lines, offset lines - GeoNet, The Esri Community

Since it appears that you are working with a road network you north-south lines will always have offsets which are reflected in the grid pattern

Split (Analysis)—ArcGIS Pro | Documentation would be useful, but not on a micro scale.  You would have to use "cut" in Polygon—ArcGIS Pro | Documentation if you want to code


... sort of retired...
0 Kudos
CCWeedcontrol
Frequent Contributor

I was able to achieve creating the blocks with the following below but would be nice if could have populate the attributes based on a formula and this is beyond me. I attached the sections in case anyone wants to help out.

 

import arcpy, os

arcpy.env.overwriteOutput = True

def CreateFishnetsForFeats(shp, out, cell_x=0, cell_y=0, n_rows=0, n_cols=0):
    # Create file gdb to store data
    gdb = str(arcpy.CreateFileGDB_management(out, 'Fishnets.gdb').getOutput(0))

    # spatial reference
    arcpy.env.outputCoordinateSystem = arcpy.Describe(shp).spatialReference

    # Loop thru rows of input polygons
    with arcpy.da.SearchCursor(shp, ['SHAPE@', 'OID@']) as rows:
        for row in rows:
            ext = row[0].extent
            st = '%f %f' %(ext.XMin, ext.YMin)
            ort = '%f %f' %(ext.XMin, ext.YMax)

            # Create fishnet
            outFn = os.path.join(gdb, 'fish_{0}'.format(row[1]))
            arcpy.CreateFishnet_management(outFn, st, ort, cell_x,cell_y, n_rows, n_cols,
                                           labels='NO_LABELS',template = ext,
                                           geometry_type='POLYGON')

    # set workspace to new gdb
    arcpy.env.workspace = gdb
    fishnets = arcpy.ListFeatureClasses()
    targ = fishnets[0]
    for i, fish in enumerate(fishnets):
        # Add field for original polygon ID
        fid = fish.split('_')[1]
        arcpy.AddField_management(fish, 'POLY_ID', 'LONG')
        with arcpy.da.UpdateCursor(fish, ['POLY_ID']) as rows:
            for row in rows:
                row[0] = fid
                rows.updateRow(row)
                
        # append fishnets into one feature class
        if i > 0:
            arcpy.Append_management([fish], targ, 'NO_TEST')
            arcpy.Delete_management(fish)
            print (*'Appended: {0}'.format(fish))
    print ('Done')
    return

if __name__ == '__main__':
    polys = r'C:\Temp\SectionGrid\SectionsCopy.shp'
    loc = r'C:\TEMP'
    CreateFishnetsForFeats(polys, loc, 0, 0, 9, 9)
0 Kudos