arcpy-util


Namearcpy-util JSON
Version 0.4.4 PyPI version JSON
download
home_pagehttps://github.com/moosetraveller/arcpy-util
SummaryCollection of arcpy helper classes and functions
upload_time2023-08-30 18:03:40
maintainer
docs_urlNone
authorThomas Zuberbuehler
requires_python
licenseMIT
keywords arcpy util arcgis esri cursor
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # `arcpy-util`

Utility classes and functions for arcpy

## Install 

```shell
python -m pip install arcpy-util
```

## Example

### `arcpyutil.xcursor`

### Using `xcursor(cursor)`

```python
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)`

```python
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()`

```python
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)`

```python
import arcpy

from arcpyutil import fc

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

print(record_count)
```

### `arcpyutil.typings`

```python
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

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

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/moosetraveller/arcpy-util",
    "name": "arcpy-util",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "arcpy,util,arcgis,esri,cursor",
    "author": "Thomas Zuberbuehler",
    "author_email": "thomas.zuberbuehler@gmail.com",
    "download_url": "",
    "platform": null,
    "description": "# `arcpy-util`\r\n\r\nUtility classes and functions for arcpy\r\n\r\n## Install \r\n\r\n```shell\r\npython -m pip install arcpy-util\r\n```\r\n\r\n## Example\r\n\r\n### `arcpyutil.xcursor`\r\n\r\n### Using `xcursor(cursor)`\r\n\r\n```python\r\nimport arcpy, arcpy.da\r\n\r\nfrom arcpyutil import xcursor\r\n\r\nfeature_class = \"points.shp\"\r\n\r\nwith arcpy.da.SearchCursor(feature_class, [\"FieldName\"]) as cursor:\r\n\r\n    for row in xcursor(cursor):\r\n        \r\n        print(row[\"FieldName\"])  # instead of row[0]\r\n\r\n        # other examples\r\n        print(row.get(\"FieldName\", \"Default Value\"))\r\n        print(row.get_by_index(0, \"Default Value\"))\r\n```\r\n\r\n#### Using `to_row()`\r\n\r\nSee `test/xcursor_test.py` (test `test_to_row`) for an example.\r\n\r\n### `arcpyutil.tcursor`\r\n\r\n### Using `tcursor(cursor)`\r\n\r\n```python\r\nimport arcpy, arcpy.da\r\n\r\nfrom arcpyutil import tcursor\r\n\r\nfeature_class = \"points.shp\"\r\n\r\nwith arcpy.da.SearchCursor(feature_class, [\"FieldName\"]) as cursor:\r\n\r\n    for row in tcursor(cursor):\r\n\r\n        print(row.FieldName)  # instead of row[0]\r\n```\r\n\r\n### `arcpyutil.fc`\r\n\r\n#### Using `use_memory()`\r\n\r\n```python\r\nimport arcpy, arcpy.management\r\n\r\nfrom arcpyutil import fc\r\n\r\narcpy.env.workspace = r\"c:\\data\"\r\n\r\nwith fc.use_memory() as copied:\r\n\r\n    print(arcpy.Exists(copied))  # false (not yet)\r\n    arcpy.management.CopyFeatures(\"buildings.shp\", copied)\r\n    print(arcpy.Exists(copied))  # true\r\n\r\nprint(arcpy.Exists(copied))  # false\r\n```\r\n\r\n#### Using `count(fc)`\r\n\r\n```python\r\nimport arcpy\r\n\r\nfrom arcpyutil import fc\r\n\r\nrecord_count = fc.count(r\"c:\\data\\buildings.shp\")\r\n\r\nprint(record_count)\r\n```\r\n\r\n### `arcpyutil.typings`\r\n\r\n```python\r\nimport arcpy, arcpy.management\r\n\r\nfrom arcpyutil.typings import FeatureClassType\r\n\r\ndef create_feature_class() -> FeatureClassType:\r\n    return arcpy.management.CreateFeatureclass(r\"c:\\temp\", \"test.shp\")\r\n\r\nprint(create_feature_class())\r\n```\r\n\r\n## Run Unit Tests\r\n\r\n```shell\r\ncd c:\\projects\\arcpy-util\r\n[conda activate arcgispro-py3]\r\npython test.py\r\n```\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Collection of arcpy helper classes and functions",
    "version": "0.4.4",
    "project_urls": {
        "Homepage": "https://github.com/moosetraveller/arcpy-util"
    },
    "split_keywords": [
        "arcpy",
        "util",
        "arcgis",
        "esri",
        "cursor"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3812148fa05310046f40d95cb5bca9d1addba65e1008c6116d930bc145da1d4d",
                "md5": "87ae38b2980795984d5104a72626ed9b",
                "sha256": "004e9d6aa91534f219d6f8a7535a82c0dae47f458e4a72472c95ef307238e3c4"
            },
            "downloads": -1,
            "filename": "arcpy_util-0.4.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "87ae38b2980795984d5104a72626ed9b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 13403,
            "upload_time": "2023-08-30T18:03:40",
            "upload_time_iso_8601": "2023-08-30T18:03:40.779874Z",
            "url": "https://files.pythonhosted.org/packages/38/12/148fa05310046f40d95cb5bca9d1addba65e1008c6116d930bc145da1d4d/arcpy_util-0.4.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-08-30 18:03:40",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "moosetraveller",
    "github_project": "arcpy-util",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "arcpy-util"
}
        
Elapsed time: 0.11372s