Skip to content

moosetraveller/aputil

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ArcPyUtil

Utility classes and functions for arcpy

Create Distribution

cd c:\projects\arcpy-util
python setup.py sdist bdist_wheel

Install

python -m pip install ArcPyUtil-X.X.X-py3-none-any.whl

Note: replace X.X.X with version number

Example

arcpyutil.xcursor

Using xcursor(cursor)

import arcpy, arcpy.da

from arcpyutil import xcursor

feature_class = "points.shp"

with arcpy.da.SearchCursor(feature_class, ["FieldName"]) as cursor:

    for row in xcursor(cursor):
        
        print(row["FieldName"])  # instead of row[0]

        # other examples
        print(row.get("FieldName", "Default Value"))
        print(row.get_by_index(0, "Default Value"))

Using to_row()

See test/xcursor_test.py (test test_to_row) for an example.

arcpyutil.tcursor

Using tcursor(cursor)

import arcpy, arcpy.da

from arcpyutil import tcursor

feature_class = "points.shp"

with arcpy.da.SearchCursor(feature_class, ["FieldName"]) as cursor:

    for row in tcursor(cursor):

        print(row.FieldName)  # instead of row[0]

arcpyutil.fc

Using use_memory()

import arcpy, arcpy.management

from arcpyutil import fc

arcpy.env.workspace = r"c:\data"

with fc.use_memory() as copied:

    print(arcpy.Exists(copied))  # false (not yet)
    arcpy.management.CopyFeatures("buildings.shp", copied)
    print(arcpy.Exists(copied))  # true

print(arcpy.Exists(copied))  # false

Using count(fc)

import arcpy

from arcpyutil import fc

record_count = fc.count(r"c:\data\buildings.shp")

print(record_count)

arcpyutil.typings

import arcpy, arcpy.management

from arcpyutil.typings import FeatureClassType

def create_feature_class() -> FeatureClassType:
    return arcpy.management.CreateFeatureclass(r"c:\temp", "test.shp")

print(create_feature_class())

Run Unit Tests

cd c:\projects\arcpy-util
[conda activate arcgispro-py3]
python test.py