arc-utils 1.1__tar.gz → 1.2.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- arc_utils-1.2.1/PKG-INFO +62 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/README.md +43 -49
- arc_utils-1.2.1/arc_utils/__init__.py +10 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/arc_utils/gdb.py +26 -1
- {arc_utils-1.1 → arc_utils-1.2.1}/arc_utils/table.py +148 -72
- arc_utils-1.2.1/arc_utils.egg-info/PKG-INFO +62 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/arc_utils.egg-info/SOURCES.txt +2 -2
- {arc_utils-1.1 → arc_utils-1.2.1}/arc_utils.egg-info/top_level.txt +2 -0
- arc_utils-1.2.1/examples/extract-featureclass-details.py +124 -0
- arc_utils-1.2.1/pyproject.toml +32 -0
- arc_utils-1.2.1/setup.py +3 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/tests/conftest.py +0 -5
- {arc_utils-1.1 → arc_utils-1.2.1}/tests/test_table.py +3 -3
- arc_utils-1.1/PKG-INFO +0 -70
- arc_utils-1.1/arc_utils/__init__.py +0 -16
- arc_utils-1.1/arc_utils/mxd.py +0 -46
- arc_utils-1.1/arc_utils.egg-info/PKG-INFO +0 -70
- arc_utils-1.1/setup.py +0 -41
- arc_utils-1.1/tests/test_mxd.py +0 -13
- {arc_utils-1.1 → arc_utils-1.2.1}/LICENSE.txt +0 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/arc_utils/aprx.py +0 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/arc_utils/output.py +0 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/arc_utils.egg-info/dependency_links.txt +0 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/setup.cfg +0 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/tests/__init__.py +0 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/tests/test_aprx.py +0 -0
- {arc_utils-1.1 → arc_utils-1.2.1}/tests/test_gdb.py +0 -0
arc_utils-1.2.1/PKG-INFO
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arc-utils
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Python utilities for use with Esri ArcGIS Pro software
|
|
5
|
+
Author-email: Grant Herbert <gdherbert@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/gdherbert/arc_utils
|
|
8
|
+
Project-URL: Download, https://github.com/gdherbert/arc_utils/tree/1.2
|
|
9
|
+
Keywords: esri,arcpy,arcgis
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE.txt
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# README #
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### What is this repository for? ###
|
|
24
|
+
* A collection of (mostly) arcpy related utilities for use within ArcGIS Pro (Python 3).
|
|
25
|
+
Shortcuts for accessing elements of a map document, performing various data discovery tasks on a table or geodatabase
|
|
26
|
+
|
|
27
|
+
### How do I get set up? ###
|
|
28
|
+
|
|
29
|
+
* To install the utilities:
|
|
30
|
+
* ``pip install arc_utils``
|
|
31
|
+
* Clone the repo to your machine and add the path to the python install https://docs.python.org/2/tutorial/modules.html#the-module-search-path
|
|
32
|
+
* Optionally, you can copy the folder to the site-packages in the ESRI python install directory, or add a .pth file to the site-packages folder pointing to the clone directory.
|
|
33
|
+
|
|
34
|
+
To use the utilities:
|
|
35
|
+
|
|
36
|
+
* in the python window in ArcGIS Pro
|
|
37
|
+
|
|
38
|
+
``import arc_utils as au``
|
|
39
|
+
|
|
40
|
+
* typing ``au.`` will now reveal the modules and functions available to you if you have autocomplete on
|
|
41
|
+
|
|
42
|
+
* Depends on arcpy (only available with Esri license)
|
|
43
|
+
|
|
44
|
+
### Example usage ###
|
|
45
|
+
|
|
46
|
+
``import arc_utils as au``
|
|
47
|
+
|
|
48
|
+
``tbl = au.table.TableObj(path to featureclass)``
|
|
49
|
+
|
|
50
|
+
# list all fields
|
|
51
|
+
|
|
52
|
+
``print(tbl.fields)``
|
|
53
|
+
|
|
54
|
+
``pro_doc = au.aprx.AprxObj(“CURRENT”)``
|
|
55
|
+
|
|
56
|
+
``pro_doc.maps`` >> [<arcpy._mp.Map object at 0x000001A4AECBF108>, <arcpy._mp.Map object at 0x000001A4AEBB6608>]
|
|
57
|
+
|
|
58
|
+
``pro_doc.maps[0].name`` >> ‘Map’
|
|
59
|
+
|
|
60
|
+
### Contribution guidelines ###
|
|
61
|
+
|
|
62
|
+
Contributions welcomed, this is a starting point for various utilities that I think could be useful within ArcGIS Pro.
|
|
@@ -1,49 +1,43 @@
|
|
|
1
|
-
# README #
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
### What is this repository for? ###
|
|
5
|
-
* A collection of (mostly) arcpy related utilities for use within ArcGIS
|
|
6
|
-
Shortcuts for accessing elements of a map document, performing various data discovery tasks on a table or
|
|
7
|
-
|
|
8
|
-
### How do I get set up? ###
|
|
9
|
-
|
|
10
|
-
* To install the utilities:
|
|
11
|
-
*
|
|
12
|
-
* Clone the repo to your machine and add the path to the python install https://docs.python.org/2/tutorial/modules.html#the-module-search-path
|
|
13
|
-
* Optionally, you can copy the folder to the site-packages in the ESRI python install directory, or add a .pth file to the site-packages folder pointing to the clone directory.
|
|
14
|
-
|
|
15
|
-
To use the utilities:
|
|
16
|
-
|
|
17
|
-
* in the python window in
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
*
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
pro_doc.maps[0].name >> ‘Map’
|
|
46
|
-
|
|
47
|
-
### Contribution guidelines ###
|
|
48
|
-
|
|
49
|
-
Contributions welcomed, this is a starting point for various utilities that I think could be useful within Arc.
|
|
1
|
+
# README #
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### What is this repository for? ###
|
|
5
|
+
* A collection of (mostly) arcpy related utilities for use within ArcGIS Pro (Python 3).
|
|
6
|
+
Shortcuts for accessing elements of a map document, performing various data discovery tasks on a table or geodatabase
|
|
7
|
+
|
|
8
|
+
### How do I get set up? ###
|
|
9
|
+
|
|
10
|
+
* To install the utilities:
|
|
11
|
+
* ``pip install arc_utils``
|
|
12
|
+
* Clone the repo to your machine and add the path to the python install https://docs.python.org/2/tutorial/modules.html#the-module-search-path
|
|
13
|
+
* Optionally, you can copy the folder to the site-packages in the ESRI python install directory, or add a .pth file to the site-packages folder pointing to the clone directory.
|
|
14
|
+
|
|
15
|
+
To use the utilities:
|
|
16
|
+
|
|
17
|
+
* in the python window in ArcGIS Pro
|
|
18
|
+
|
|
19
|
+
``import arc_utils as au``
|
|
20
|
+
|
|
21
|
+
* typing ``au.`` will now reveal the modules and functions available to you if you have autocomplete on
|
|
22
|
+
|
|
23
|
+
* Depends on arcpy (only available with Esri license)
|
|
24
|
+
|
|
25
|
+
### Example usage ###
|
|
26
|
+
|
|
27
|
+
``import arc_utils as au``
|
|
28
|
+
|
|
29
|
+
``tbl = au.table.TableObj(path to featureclass)``
|
|
30
|
+
|
|
31
|
+
# list all fields
|
|
32
|
+
|
|
33
|
+
``print(tbl.fields)``
|
|
34
|
+
|
|
35
|
+
``pro_doc = au.aprx.AprxObj(“CURRENT”)``
|
|
36
|
+
|
|
37
|
+
``pro_doc.maps`` >> [<arcpy._mp.Map object at 0x000001A4AECBF108>, <arcpy._mp.Map object at 0x000001A4AEBB6608>]
|
|
38
|
+
|
|
39
|
+
``pro_doc.maps[0].name`` >> ‘Map’
|
|
40
|
+
|
|
41
|
+
### Contribution guidelines ###
|
|
42
|
+
|
|
43
|
+
Contributions welcomed, this is a starting point for various utilities that I think could be useful within ArcGIS Pro.
|
|
@@ -20,12 +20,13 @@ class GDBObj(object):
|
|
|
20
20
|
self.path = gdb_path
|
|
21
21
|
self.describe_obj = self._describe_object()
|
|
22
22
|
self.feature_classes = self.get_feature_class_names()
|
|
23
|
+
self.tables = self.get_table_names()
|
|
23
24
|
self.domain_names = self.get_all_domain_names()
|
|
24
25
|
|
|
25
26
|
def _describe_object(self):
|
|
26
27
|
""" returns describe object"""
|
|
27
28
|
return arcpy.Describe(self.path)
|
|
28
|
-
|
|
29
|
+
|
|
29
30
|
def get_feature_class_names(self):
|
|
30
31
|
""" get a list of all the featureclass names"""
|
|
31
32
|
fc_list = []
|
|
@@ -38,6 +39,17 @@ class GDBObj(object):
|
|
|
38
39
|
fc_list.append(fc)
|
|
39
40
|
arcpy.env.workspace = temp_ws
|
|
40
41
|
return fc_list
|
|
42
|
+
|
|
43
|
+
def get_table_names(self):
|
|
44
|
+
""" get a list of all the table names"""
|
|
45
|
+
tbl_list = []
|
|
46
|
+
temp_ws = arcpy.env.workspace
|
|
47
|
+
arcpy.env.workspace = self.path
|
|
48
|
+
tbls = arcpy.ListTables()
|
|
49
|
+
for tbl in tbls:
|
|
50
|
+
tbl_list.append(tbl)
|
|
51
|
+
arcpy.env.workspace = temp_ws
|
|
52
|
+
return tbl_list
|
|
41
53
|
|
|
42
54
|
def get_all_domain_names(self):
|
|
43
55
|
domain_names = []
|
|
@@ -46,6 +58,19 @@ class GDBObj(object):
|
|
|
46
58
|
domain_names.append(domain.name)
|
|
47
59
|
return domain_names
|
|
48
60
|
|
|
61
|
+
def OID_check(self):
|
|
62
|
+
for fc in self.feature_classes:
|
|
63
|
+
oidfield = ''
|
|
64
|
+
tmp = arcpy.Describe(fc)
|
|
65
|
+
if tmp.hasOID:
|
|
66
|
+
oidfield = tmp.OIDFieldName
|
|
67
|
+
print('featureclass', tmp.name, tmp.hasOID, oidfield)
|
|
68
|
+
for tb in self.tables:
|
|
69
|
+
oidfield = ''
|
|
70
|
+
tmp = arcpy.Describe(tb)
|
|
71
|
+
if tmp.hasOID:
|
|
72
|
+
oidfield = tmp.OIDFieldName
|
|
73
|
+
print('table', tmp.name, tmp.hasOID, oidfield)
|
|
49
74
|
|
|
50
75
|
#TODO split into 3 - get all FC, create formatted string output, write to file. use io
|
|
51
76
|
def report_all_fc_as_text(geodatabase, output_file=None, sep='\t'):
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
"""utilities for working with tables, featureclasses and fields
|
|
3
3
|
"""
|
|
4
4
|
from __future__ import print_function, unicode_literals, absolute_import
|
|
5
|
-
import six
|
|
6
5
|
import arcpy
|
|
7
6
|
from .output import get_valid_output_path
|
|
8
7
|
from .output import output_msg
|
|
@@ -22,9 +21,11 @@ class TableObj(object):
|
|
|
22
21
|
self.describe_obj = self._describe_object()
|
|
23
22
|
self.name = self._get_fc_name()
|
|
24
23
|
self.type = self._get_fc_type()
|
|
24
|
+
self.field_dict = self._make_field_dict()
|
|
25
25
|
self.fields = self._list_field_names()
|
|
26
26
|
self.fields2 = self._list_field_names(required=False)
|
|
27
|
-
self.
|
|
27
|
+
self.fieldaliases = self._list_field_names(aliases=True)
|
|
28
|
+
|
|
28
29
|
|
|
29
30
|
def _describe_object(self):
|
|
30
31
|
""" returns describe object"""
|
|
@@ -41,13 +42,16 @@ class TableObj(object):
|
|
|
41
42
|
else:
|
|
42
43
|
return 'Unknown'
|
|
43
44
|
|
|
44
|
-
def _list_field_names(self, required=True):
|
|
45
|
+
def _list_field_names(self, required=True, aliases=False):
|
|
45
46
|
"""Array of field names
|
|
46
47
|
"""
|
|
47
48
|
if required:
|
|
48
|
-
f_list = [field
|
|
49
|
+
f_list = [field['name'] for field in self.field_dict.values()]
|
|
49
50
|
else:
|
|
50
|
-
f_list = [field
|
|
51
|
+
f_list = [field['name'] for field in self.field_dict.values() if not field['required']]
|
|
52
|
+
if aliases:
|
|
53
|
+
# override the output to use aliases instead of field names
|
|
54
|
+
f_list = [self.field_dict[field]['aliasName'] for field in f_list]
|
|
51
55
|
return f_list
|
|
52
56
|
|
|
53
57
|
def _make_field_dict(self):
|
|
@@ -126,14 +130,11 @@ class TableObj(object):
|
|
|
126
130
|
length = len(val)
|
|
127
131
|
return length
|
|
128
132
|
|
|
129
|
-
def get_field_value_set(self, field
|
|
133
|
+
def get_field_value_set(self, field):
|
|
130
134
|
"""Return set of unique field values
|
|
131
135
|
:param field {String}:
|
|
132
136
|
name of the field to parse
|
|
133
|
-
:
|
|
134
|
-
character set to use (default = 'ascii').
|
|
135
|
-
Valid values are those in the Python documentation for string encode.
|
|
136
|
-
:return set of unique values. Null values are represented as 'NULL'
|
|
137
|
+
:return set of unique values. Null values are represented as 'NULL' string
|
|
137
138
|
"""
|
|
138
139
|
try:
|
|
139
140
|
value_set = set() # set to hold unique values
|
|
@@ -141,12 +142,6 @@ class TableObj(object):
|
|
|
141
142
|
for value in values:
|
|
142
143
|
if value[0] is None:
|
|
143
144
|
value_set.add("NULL")
|
|
144
|
-
elif isinstance(value[0], six.string_types):
|
|
145
|
-
if charset != 'ascii':
|
|
146
|
-
value_set.add(value[0])
|
|
147
|
-
else:
|
|
148
|
-
# if unicode strings are causing problem, try
|
|
149
|
-
value_set.add(value[0].encode('ascii', 'ignore'))
|
|
150
145
|
else:
|
|
151
146
|
value_set.add(value[0])
|
|
152
147
|
return value_set
|
|
@@ -159,7 +154,6 @@ class TableObj(object):
|
|
|
159
154
|
def get_multiple_field_value_set(self, fields, sep=':'):
|
|
160
155
|
"""return a set of unique field values for an input table
|
|
161
156
|
and any number of fields (values will be concatenated with sep)
|
|
162
|
-
null values converted to 'NULL'
|
|
163
157
|
:param fields {array of String values}:
|
|
164
158
|
single field name or an array of field names (['Field1', 'Field2'])
|
|
165
159
|
:param sep {String}:
|
|
@@ -169,16 +163,14 @@ class TableObj(object):
|
|
|
169
163
|
fieldslist = [fields]
|
|
170
164
|
else:
|
|
171
165
|
fieldslist = fields
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
result = df.values.flatten()
|
|
181
|
-
# return as a set
|
|
166
|
+
|
|
167
|
+
result = set()
|
|
168
|
+
|
|
169
|
+
with arcpy.da.SearchCursor(self.path, fieldslist) as cursor:
|
|
170
|
+
for row in cursor:
|
|
171
|
+
parts = [('NULL' if v is None else str(v)) for v in row]
|
|
172
|
+
result.add(sep.join(parts))
|
|
173
|
+
|
|
182
174
|
return set(result)
|
|
183
175
|
|
|
184
176
|
def find_duplicate_field_values(self, field, charset='ascii'):
|
|
@@ -197,12 +189,6 @@ class TableObj(object):
|
|
|
197
189
|
for value in values:
|
|
198
190
|
if value[0] in value_set:
|
|
199
191
|
dup_set.add(value[0])
|
|
200
|
-
if isinstance(value[0], six.string_types):
|
|
201
|
-
if charset != 'ascii':
|
|
202
|
-
value_set.add(value[0])
|
|
203
|
-
else:
|
|
204
|
-
# if unicode strings are causing problem, try
|
|
205
|
-
value_set.add(value[0].encode('ascii', 'ignore'))
|
|
206
192
|
else:
|
|
207
193
|
value_set.add(value[0])
|
|
208
194
|
return dup_set
|
|
@@ -212,6 +198,27 @@ class TableObj(object):
|
|
|
212
198
|
except Exception as e:
|
|
213
199
|
output_msg(e.args[0])
|
|
214
200
|
|
|
201
|
+
def find_duplicate_field_values_as_df(path, fields):
|
|
202
|
+
"""Return set of unique field values
|
|
203
|
+
:param path {String}:
|
|
204
|
+
path to data
|
|
205
|
+
:param field [{String}]:
|
|
206
|
+
list of name(s) of fields to parse
|
|
207
|
+
:return Pandas DataFrame of values which are duplicated in the field with count > 1 (ignores Null values).
|
|
208
|
+
Use Pandas DataFrame <result>.to_csv() to export to file
|
|
209
|
+
"""
|
|
210
|
+
if not isinstance(fields, list):
|
|
211
|
+
fieldslist = [fields]
|
|
212
|
+
else:
|
|
213
|
+
fieldslist = fields
|
|
214
|
+
|
|
215
|
+
import pandas
|
|
216
|
+
data = arcpy.da.TableToNumPyArray(path, fieldslist, null_value='NULL')
|
|
217
|
+
df = pandas.DataFrame(data)
|
|
218
|
+
count = df.groupby(fields).size().reset_index().rename(columns={0:'count'})
|
|
219
|
+
dups = count[count['count'] > 1]
|
|
220
|
+
return dups
|
|
221
|
+
|
|
215
222
|
def export_schema_to_csv(self, path):
|
|
216
223
|
"""Create a csv schema report of all fields in a featureclass,
|
|
217
224
|
to the supplied path.
|
|
@@ -335,37 +342,108 @@ class TableObj(object):
|
|
|
335
342
|
_print(["{:>12}".format(getattr(f, i)) for i in atts])
|
|
336
343
|
|
|
337
344
|
|
|
338
|
-
def get_max_field_value(input_fc, field, treatasfloat=False):
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
345
|
+
def get_max_field_value(input_fc, field, treatasfloat=False):
|
|
346
|
+
"""Return either the longest string in the field,
|
|
347
|
+
or the largest number.
|
|
348
|
+
:param input_fc {String}:
|
|
349
|
+
Path or reference to feature class or table.
|
|
350
|
+
:param field {String}:
|
|
351
|
+
name of the field to parse
|
|
352
|
+
:param treatasfloat:
|
|
353
|
+
setting to treat the field as a float value (expects all numeric)
|
|
354
|
+
:return value of largest field entry
|
|
355
|
+
"""
|
|
356
|
+
result = None
|
|
357
|
+
with arcpy.da.SearchCursor(input_fc, field) as values:
|
|
358
|
+
for value in values:
|
|
359
|
+
if value[0] is not None:
|
|
360
|
+
if treatasfloat:
|
|
361
|
+
val = float(value[0])
|
|
362
|
+
else:
|
|
363
|
+
val = value[0]
|
|
364
|
+
if isinstance(val, str):
|
|
365
|
+
# return longest string
|
|
366
|
+
if result is None:
|
|
367
|
+
result = ''
|
|
368
|
+
if len(val) > len(result):
|
|
369
|
+
result = val
|
|
370
|
+
else:
|
|
371
|
+
if result is None:
|
|
372
|
+
result = 0
|
|
373
|
+
if val > result:
|
|
374
|
+
result = val
|
|
375
|
+
return result
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
def export_field_sets(fc_list, out_xlsx, ignore_fields=["objectid","globalid"], use_lyr_alias=True):
|
|
379
|
+
""" Export unique field values for each layer in a list to an Excel file with one sheet per layer
|
|
380
|
+
:param fc_list: list of feature class or table paths
|
|
381
|
+
:param out_xlsx: path to output Excel file
|
|
382
|
+
:param ignore_fields: list of lowercase fields to ignore (e.g. ['objectid', 'shape'])
|
|
383
|
+
:param use_lyr_alias: if True, use layer alias for sheet name;"""
|
|
384
|
+
import os
|
|
385
|
+
from openpyxl import Workbook
|
|
386
|
+
|
|
387
|
+
ignore_fields = [v.lower() for v in ignore_fields]
|
|
388
|
+
|
|
389
|
+
# Create workbook
|
|
390
|
+
wb = Workbook()
|
|
391
|
+
# Remove the default sheet that openpyxl creates
|
|
392
|
+
default_sheet = wb.active
|
|
393
|
+
wb.remove(default_sheet)
|
|
394
|
+
|
|
395
|
+
# Loop through layers and create a sheet per layer
|
|
396
|
+
for lyr in layr_list:
|
|
397
|
+
tbl = TableObj(lyr)
|
|
398
|
+
|
|
399
|
+
print(f'Processing name: {tbl.name}, alias: {str(lyr)}')
|
|
400
|
+
|
|
401
|
+
# Excel sheet name must be <= 31 chars and cannot contain: : \ / ? * [ ]
|
|
402
|
+
if use_lyr_alias:
|
|
403
|
+
raw_name = str(lyr)
|
|
404
|
+
else:
|
|
405
|
+
raw_name = str(tbl.name) if hasattr(tbl, "name") else str(lyr)
|
|
406
|
+
safe_name = "".join(ch for ch in raw_name if ch not in r':\/?*[]')
|
|
407
|
+
safe_name = safe_name[:31] if len(safe_name) > 31 else safe_name
|
|
408
|
+
if not safe_name:
|
|
409
|
+
safe_name = "Sheet"
|
|
410
|
+
|
|
411
|
+
ws = wb.create_sheet(title=safe_name)
|
|
412
|
+
|
|
413
|
+
# Header row
|
|
414
|
+
ws["A1"] = "Field"
|
|
415
|
+
ws["B1"] = "Values"
|
|
416
|
+
|
|
417
|
+
row_idx = 2
|
|
418
|
+
|
|
419
|
+
for fld in tbl.fields2: # skip required fields by default
|
|
420
|
+
if fld.lower() in ignore_fields:
|
|
421
|
+
continue
|
|
422
|
+
|
|
423
|
+
#get field alias if available
|
|
424
|
+
if fld in tbl.field_dict and 'aliasName' in tbl.field_dict[fld] and tbl.field_dict[fld]['aliasName']:
|
|
425
|
+
alias = tbl.field_dict[fld]['aliasName']
|
|
426
|
+
else:
|
|
427
|
+
alias = fld
|
|
428
|
+
# Get unique values for the field
|
|
429
|
+
vals = tbl.get_field_value_set(fld)
|
|
430
|
+
|
|
431
|
+
# Convert to sorted, comma-separated string
|
|
432
|
+
# Make sure everything is a string for consistency
|
|
433
|
+
vals_str = ", ".join(sorted(str(v) for v in vals))
|
|
434
|
+
|
|
435
|
+
# Write to Excel
|
|
436
|
+
ws.cell(row=row_idx, column=1, value=alias) # Column A: field alias/name
|
|
437
|
+
try:
|
|
438
|
+
ws.cell(row=row_idx, column=2, value=vals_str) # Column B: CSV of unique values
|
|
439
|
+
except Exception as e:
|
|
440
|
+
ws.cell(row=row_idx, column=2, value="VALUES ERROR") # Column B: error msg
|
|
441
|
+
print(f"Error writing field '{alias}' values to Excel: {e}")
|
|
442
|
+
row_idx += 1
|
|
443
|
+
|
|
444
|
+
# Save workbook
|
|
445
|
+
wb.save(out_xlsx)
|
|
446
|
+
print(f"\nExcel file written to: {out_xlsx}")
|
|
369
447
|
|
|
370
448
|
|
|
371
449
|
def compare_schema(fc1, fc2):
|
|
@@ -398,13 +476,11 @@ def compare_schema(fc1, fc2):
|
|
|
398
476
|
output_msg(the_result)
|
|
399
477
|
result_arr.append(the_result)
|
|
400
478
|
else:
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
the_result = " {0} {1} {2} {3} does not exactly match {4} {5} {6} {7}".format(
|
|
407
|
-
fc1, ifield, field_one_type, field_one_length, fc2, ifield, field_two_type, field_two_length)
|
|
479
|
+
the_result = "Field Mismatch {}: ({}, {}) ".format(
|
|
480
|
+
ifield, fc1, fc2)
|
|
481
|
+
for k in field_dict1[ifield]:
|
|
482
|
+
if field_dict1[ifield][k] != field_dict2[ifield][k]:
|
|
483
|
+
the_result += '{}: ({}, {}) '.format(k, field_dict1[ifield][k], field_dict2[ifield][k])
|
|
408
484
|
output_msg(the_result)
|
|
409
485
|
result_arr.append(the_result)
|
|
410
486
|
|
|
@@ -419,7 +495,7 @@ def import_schema_to_fc(csv_file, fc_name):
|
|
|
419
495
|
# load the csv file from line 2 for field info
|
|
420
496
|
# get field list
|
|
421
497
|
# ignore OBJECTID, SHAPE
|
|
422
|
-
fields_to_ignore =["OBJECTID", "FID", "SHAPE", "SHAPE_AREA", "SHAPE.AREA", "SHAPE.STAREA()", "SHAPE_LENGTH", "SHAPE.LEN", "SHAPE.STLENGTH()"]
|
|
498
|
+
fields_to_ignore =["OBJECTID", "GLOBALID","FID", "SHAPE", "SHAPE_AREA", "SHAPE.AREA", "SHAPE.STAREA()", "SHAPE_LENGTH", "SHAPE.LEN", "SHAPE.STLENGTH()"]
|
|
423
499
|
# create fc from fc_name
|
|
424
500
|
# add fields from field list
|
|
425
501
|
# arcpy.AddField_management(in_table, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: arc-utils
|
|
3
|
+
Version: 1.2.1
|
|
4
|
+
Summary: Python utilities for use with Esri ArcGIS Pro software
|
|
5
|
+
Author-email: Grant Herbert <gdherbert@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/gdherbert/arc_utils
|
|
8
|
+
Project-URL: Download, https://github.com/gdherbert/arc_utils/tree/1.2
|
|
9
|
+
Keywords: esri,arcpy,arcgis
|
|
10
|
+
Classifier: Development Status :: 4 - Beta
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Requires-Python: >=3.11
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE.txt
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# README #
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
### What is this repository for? ###
|
|
24
|
+
* A collection of (mostly) arcpy related utilities for use within ArcGIS Pro (Python 3).
|
|
25
|
+
Shortcuts for accessing elements of a map document, performing various data discovery tasks on a table or geodatabase
|
|
26
|
+
|
|
27
|
+
### How do I get set up? ###
|
|
28
|
+
|
|
29
|
+
* To install the utilities:
|
|
30
|
+
* ``pip install arc_utils``
|
|
31
|
+
* Clone the repo to your machine and add the path to the python install https://docs.python.org/2/tutorial/modules.html#the-module-search-path
|
|
32
|
+
* Optionally, you can copy the folder to the site-packages in the ESRI python install directory, or add a .pth file to the site-packages folder pointing to the clone directory.
|
|
33
|
+
|
|
34
|
+
To use the utilities:
|
|
35
|
+
|
|
36
|
+
* in the python window in ArcGIS Pro
|
|
37
|
+
|
|
38
|
+
``import arc_utils as au``
|
|
39
|
+
|
|
40
|
+
* typing ``au.`` will now reveal the modules and functions available to you if you have autocomplete on
|
|
41
|
+
|
|
42
|
+
* Depends on arcpy (only available with Esri license)
|
|
43
|
+
|
|
44
|
+
### Example usage ###
|
|
45
|
+
|
|
46
|
+
``import arc_utils as au``
|
|
47
|
+
|
|
48
|
+
``tbl = au.table.TableObj(path to featureclass)``
|
|
49
|
+
|
|
50
|
+
# list all fields
|
|
51
|
+
|
|
52
|
+
``print(tbl.fields)``
|
|
53
|
+
|
|
54
|
+
``pro_doc = au.aprx.AprxObj(“CURRENT”)``
|
|
55
|
+
|
|
56
|
+
``pro_doc.maps`` >> [<arcpy._mp.Map object at 0x000001A4AECBF108>, <arcpy._mp.Map object at 0x000001A4AEBB6608>]
|
|
57
|
+
|
|
58
|
+
``pro_doc.maps[0].name`` >> ‘Map’
|
|
59
|
+
|
|
60
|
+
### Contribution guidelines ###
|
|
61
|
+
|
|
62
|
+
Contributions welcomed, this is a starting point for various utilities that I think could be useful within ArcGIS Pro.
|
|
@@ -1,20 +1,20 @@
|
|
|
1
1
|
LICENSE.txt
|
|
2
2
|
README.md
|
|
3
|
+
pyproject.toml
|
|
3
4
|
setup.cfg
|
|
4
5
|
setup.py
|
|
5
6
|
arc_utils/__init__.py
|
|
6
7
|
arc_utils/aprx.py
|
|
7
8
|
arc_utils/gdb.py
|
|
8
|
-
arc_utils/mxd.py
|
|
9
9
|
arc_utils/output.py
|
|
10
10
|
arc_utils/table.py
|
|
11
11
|
arc_utils.egg-info/PKG-INFO
|
|
12
12
|
arc_utils.egg-info/SOURCES.txt
|
|
13
13
|
arc_utils.egg-info/dependency_links.txt
|
|
14
14
|
arc_utils.egg-info/top_level.txt
|
|
15
|
+
examples/extract-featureclass-details.py
|
|
15
16
|
tests/__init__.py
|
|
16
17
|
tests/conftest.py
|
|
17
18
|
tests/test_aprx.py
|
|
18
19
|
tests/test_gdb.py
|
|
19
|
-
tests/test_mxd.py
|
|
20
20
|
tests/test_table.py
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
import arc_utils as au
|
|
2
|
+
import arcpy
|
|
3
|
+
import os
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def write_field_info(fc):
|
|
7
|
+
desc = arcpy.Describe(fc)
|
|
8
|
+
root_path = desc.path
|
|
9
|
+
fc_name = desc.name
|
|
10
|
+
print('getting field info from %s' % fc_name)
|
|
11
|
+
if fc_name.find(".") != -1:
|
|
12
|
+
fc_name = fc_name.split(".")[0]
|
|
13
|
+
a = open(os.path.join(root_path, fc_name + ".tsv"), "w")
|
|
14
|
+
a.write(au.table.get_field_info_as_text(fc)) # use default tab
|
|
15
|
+
a.flush()
|
|
16
|
+
a.close()
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def write_field_values(fc):
|
|
20
|
+
import csv
|
|
21
|
+
desc = arcpy.Describe(fc)
|
|
22
|
+
root_path = desc.path
|
|
23
|
+
print(root_path)
|
|
24
|
+
fc_name = desc.name
|
|
25
|
+
print('getting field values from %s' % fc_name)
|
|
26
|
+
if fc_name.find(".") != -1:
|
|
27
|
+
fc_name = fc_name.split(".")[0]
|
|
28
|
+
field_value_csv = os.path.join(root_path, fc_name + "_field_values.csv")
|
|
29
|
+
with open(field_value_csv, 'a+') as a:
|
|
30
|
+
csvw = csv.writer(a, lineterminator='\n')
|
|
31
|
+
fco = au.table.TableObj(fc)
|
|
32
|
+
for field in fco.fields2:
|
|
33
|
+
print('writing field values for %s' % field)
|
|
34
|
+
values = [field]
|
|
35
|
+
values.extend(fco.get_field_value_set(field))
|
|
36
|
+
csvw.writerow(values)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_featureclass_info(workspace):
|
|
40
|
+
ws = arcpy.env.workspace
|
|
41
|
+
arcpy.env.workspace = workspace
|
|
42
|
+
desc = arcpy.Describe(workspace)
|
|
43
|
+
root_path = workspace
|
|
44
|
+
if not desc.dataType == 'Folder':
|
|
45
|
+
root_path = desc.catalogPath # path
|
|
46
|
+
for fc in arcpy.ListFeatureClasses():
|
|
47
|
+
fc_path = os.path.join(arcpy.env.workspace, fc)
|
|
48
|
+
# write field info
|
|
49
|
+
write_field_info(fc_path)
|
|
50
|
+
# write field values
|
|
51
|
+
write_field_values(fc_path)
|
|
52
|
+
arcpy.env.workspace = ws
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def export_field_sets(layr_list, out_xlsx, ignore_fields=[], use_lyr_alias=True):
|
|
56
|
+
""" Export unique field values for each layer in a list to an Excel file with one sheet per layer
|
|
57
|
+
:param layr_list: list of layer objects or paths to layers
|
|
58
|
+
:param out_xlsx: path to output Excel file
|
|
59
|
+
:param ignore_fields: list of lowercase fields to ignore (e.g. ['objectid', 'shape'])
|
|
60
|
+
:param use_lyr_alias: if True, use layer alias for sheet name;"""
|
|
61
|
+
import os
|
|
62
|
+
from openpyxl import Workbook
|
|
63
|
+
|
|
64
|
+
ignore_fields = [v.lower() for v in ignore_fields]
|
|
65
|
+
|
|
66
|
+
# Create workbook
|
|
67
|
+
wb = Workbook()
|
|
68
|
+
# Remove the default sheet that openpyxl creates
|
|
69
|
+
default_sheet = wb.active
|
|
70
|
+
wb.remove(default_sheet)
|
|
71
|
+
|
|
72
|
+
# Loop through layers and create a sheet per layer
|
|
73
|
+
|
|
74
|
+
for lyr in layr_list:
|
|
75
|
+
tbl = au.table.TableObj(lyr)
|
|
76
|
+
|
|
77
|
+
print(f'Processing name: {tbl.name}, alias: {str(lyr)}')
|
|
78
|
+
|
|
79
|
+
# Excel sheet name must be <= 31 chars and cannot contain: : \ / ? * [ ]
|
|
80
|
+
if use_lyr_alias:
|
|
81
|
+
raw_name = str(lyr)
|
|
82
|
+
else:
|
|
83
|
+
raw_name = str(tbl.name) if hasattr(tbl, "name") else str(lyr)
|
|
84
|
+
safe_name = "".join(ch for ch in raw_name if ch not in r':\/?*[]')
|
|
85
|
+
safe_name = safe_name[:31] if len(safe_name) > 31 else safe_name
|
|
86
|
+
if not safe_name:
|
|
87
|
+
safe_name = "Sheet"
|
|
88
|
+
|
|
89
|
+
ws = wb.create_sheet(title=safe_name)
|
|
90
|
+
|
|
91
|
+
# Header row
|
|
92
|
+
ws["A1"] = "Field"
|
|
93
|
+
ws["B1"] = "Values"
|
|
94
|
+
|
|
95
|
+
row_idx = 2
|
|
96
|
+
|
|
97
|
+
for fld in tbl.fields2:
|
|
98
|
+
if fld.lower() in ignore_fields:
|
|
99
|
+
continue
|
|
100
|
+
|
|
101
|
+
#get field alias if available
|
|
102
|
+
if fld in tbl.field_dict and 'aliasName' in tbl.field_dict[fld] and tbl.field_dict[fld]['aliasName']:
|
|
103
|
+
alias = tbl.field_dict[fld]['aliasName']
|
|
104
|
+
else:
|
|
105
|
+
alias = fld
|
|
106
|
+
# Get unique values for the field
|
|
107
|
+
vals = tbl.get_field_value_set(fld)
|
|
108
|
+
|
|
109
|
+
# Convert to sorted, comma-separated string
|
|
110
|
+
# Make sure everything is a string for consistency
|
|
111
|
+
vals_str = ", ".join(sorted(str(v) for v in vals))
|
|
112
|
+
|
|
113
|
+
# Write to Excel
|
|
114
|
+
ws.cell(row=row_idx, column=1, value=alias) # Column A: field alias/name
|
|
115
|
+
try:
|
|
116
|
+
ws.cell(row=row_idx, column=2, value=vals_str) # Column B: CSV of unique values
|
|
117
|
+
except Exception as e:
|
|
118
|
+
ws.cell(row=row_idx, column=2, value="VALUES ERROR") # Column B: error msg
|
|
119
|
+
print(f"Error writing field '{alias}' values to Excel: {e}")
|
|
120
|
+
row_idx += 1
|
|
121
|
+
|
|
122
|
+
# Save workbook
|
|
123
|
+
wb.save(out_xlsx)
|
|
124
|
+
print(f"\nExcel file written to: {out_xlsx}")
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77.0.3"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "arc-utils"
|
|
7
|
+
version = "1.2.1"
|
|
8
|
+
description = "Python utilities for use with Esri ArcGIS Pro software"
|
|
9
|
+
readme = { file = "README.md", content-type = "text/markdown" }
|
|
10
|
+
requires-python = ">=3.11"
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
|
|
13
|
+
authors = [
|
|
14
|
+
{ name = "Grant Herbert", email = "gdherbert@gmail.com" }
|
|
15
|
+
]
|
|
16
|
+
|
|
17
|
+
keywords = ["esri", "arcpy", "arcgis"]
|
|
18
|
+
|
|
19
|
+
classifiers = [
|
|
20
|
+
"Development Status :: 4 - Beta",
|
|
21
|
+
"Intended Audience :: Developers",
|
|
22
|
+
"Programming Language :: Python",
|
|
23
|
+
"Programming Language :: Python :: 3.13",
|
|
24
|
+
"Operating System :: Microsoft :: Windows"
|
|
25
|
+
]
|
|
26
|
+
|
|
27
|
+
[project.urls]
|
|
28
|
+
Homepage = "https://github.com/gdherbert/arc_utils"
|
|
29
|
+
Download = "https://github.com/gdherbert/arc_utils/tree/1.2"
|
|
30
|
+
|
|
31
|
+
[tool.setuptools.packages.find]
|
|
32
|
+
where = ["."]
|
arc_utils-1.2.1/setup.py
ADDED
|
@@ -12,11 +12,6 @@ def testgdb(pytestconfig):
|
|
|
12
12
|
gdb_name = "arc_utils_test_tmp.gdb"
|
|
13
13
|
return str(pytestconfig.rootdir.join(testfolder).join(gdb_name))
|
|
14
14
|
|
|
15
|
-
@pytest.fixture(scope='module')
|
|
16
|
-
def testmxd(pytestconfig):
|
|
17
|
-
mxd_name = "arc_utils_test.mxd"
|
|
18
|
-
return str(pytestconfig.rootdir.join(testfolder).join(mxd_name))
|
|
19
|
-
|
|
20
15
|
@pytest.fixture(scope='module')
|
|
21
16
|
def testaprx(pytestconfig):
|
|
22
17
|
aprx_name = "arc_utils_test_pro.aprx"
|
|
@@ -14,7 +14,7 @@ def test_tableobj_properties(testdatabase):
|
|
|
14
14
|
assert tbl.field_dict['Shape']['type'] == u'Geometry'
|
|
15
15
|
assert tbl.field_dict['ftext']['aliasName']== u'ftext'
|
|
16
16
|
assert tbl.field_dict['OBJECTID']['required']== True
|
|
17
|
-
assert tbl.field_dict['fint']['type']== u'
|
|
17
|
+
assert tbl.field_dict['fint']['type']== u'Integer'
|
|
18
18
|
|
|
19
19
|
|
|
20
20
|
def test_tableobj_single_text_field_methods(testdatabase):
|
|
@@ -28,7 +28,7 @@ def test_tableobj_single_text_field_methods(testdatabase):
|
|
|
28
28
|
assert tbl.get_max_field_value_length('ftext') == 5
|
|
29
29
|
|
|
30
30
|
|
|
31
|
-
def
|
|
31
|
+
def test_tableobj_single_integer_field_methods(testdatabase):
|
|
32
32
|
# test table object methods
|
|
33
33
|
tbl = table.TableObj(testdatabase.fc1)
|
|
34
34
|
fint_set = tbl.get_field_value_set('fint')
|
|
@@ -43,7 +43,7 @@ def test_tableobj_multi_field_methods(testdatabase):
|
|
|
43
43
|
tbl = table.TableObj(testdatabase.fc1)
|
|
44
44
|
multi_field = tbl.get_multiple_field_value_set(['ftext', 'fint'])
|
|
45
45
|
assert isinstance(multi_field, set)
|
|
46
|
-
assert sorted(multi_field) == [u'NULL:5', u'val02:7', u'val1:
|
|
46
|
+
assert sorted(multi_field) == [u'NULL:5', u'val02:7', u'val1:10', u'val1:4', u'val1:NULL', u'val2:5', u'val2:7']
|
|
47
47
|
|
|
48
48
|
|
|
49
49
|
|
arc_utils-1.1/PKG-INFO
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: arc_utils
|
|
3
|
-
Version: 1.1
|
|
4
|
-
Summary: Python utilities for use with Esri ArcGIS Desktop, ArcGIS Pro software
|
|
5
|
-
Home-page: https://github.com/gdherbert/arc_utils
|
|
6
|
-
Author: Grant Herbert
|
|
7
|
-
Author-email: gdherbert@gmail.com
|
|
8
|
-
License: License:: MIT
|
|
9
|
-
Download-URL: https://github.com/gdherbert/arc_utils/tree/1.0
|
|
10
|
-
Description: # README #
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### What is this repository for? ###
|
|
14
|
-
* A collection of (mostly) arcpy related utilities for use within ArcGIS Desktop (Python 2.7), or ArcGIS Pro (Python 3) as well where possible.
|
|
15
|
-
Shortcuts for accessing elements of a map document, performing various data discovery tasks on a table or gdb
|
|
16
|
-
|
|
17
|
-
### How do I get set up? ###
|
|
18
|
-
|
|
19
|
-
* To install the utilities:
|
|
20
|
-
* `pip install arc_utils`
|
|
21
|
-
* Clone the repo to your machine and add the path to the python install https://docs.python.org/2/tutorial/modules.html#the-module-search-path
|
|
22
|
-
* Optionally, you can copy the folder to the site-packages in the ESRI python install directory, or add a .pth file to the site-packages folder pointing to the clone directory.
|
|
23
|
-
|
|
24
|
-
To use the utilities:
|
|
25
|
-
|
|
26
|
-
* in the python window in ArcMap/ArcCatalog/Pro
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
import arc_utils as au
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
* typing `au.` will now reveal the modules and functions available to you if you have autocomplete on
|
|
33
|
-
|
|
34
|
-
* Depends on arcpy (only available with Esri license)
|
|
35
|
-
|
|
36
|
-
### Example usage ###
|
|
37
|
-
|
|
38
|
-
import arc_utils as au
|
|
39
|
-
|
|
40
|
-
tbl = au.table.TableObj(path to featureclass)
|
|
41
|
-
|
|
42
|
-
# list all fields
|
|
43
|
-
|
|
44
|
-
print(tbl.fields)
|
|
45
|
-
|
|
46
|
-
mxd_doc = au.mxd.MxdObj(“CURRENT”)
|
|
47
|
-
|
|
48
|
-
mxd_doc.layer_names_array >> [‘layer1’,’layer2’]
|
|
49
|
-
|
|
50
|
-
pro_doc = au.aprx.AprxObj(“CURRENT”)
|
|
51
|
-
|
|
52
|
-
pro_doc.maps >> [<arcpy._mp.Map object at 0x000001A4AECBF108>, <arcpy._mp.Map object at 0x000001A4AEBB6608>]
|
|
53
|
-
|
|
54
|
-
pro_doc.maps[0].name >> ‘Map’
|
|
55
|
-
|
|
56
|
-
### Contribution guidelines ###
|
|
57
|
-
|
|
58
|
-
Contributions welcomed, this is a starting point for various utilities that I think could be useful within Arc.
|
|
59
|
-
|
|
60
|
-
Keywords: esri arcpy arcgis
|
|
61
|
-
Platform: UNKNOWN
|
|
62
|
-
Classifier: Development Status :: 4 - Beta
|
|
63
|
-
Classifier: Intended Audience :: Developers
|
|
64
|
-
Classifier: Intended Audience :: End Users/Desktop
|
|
65
|
-
Classifier: Programming Language :: Python
|
|
66
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
67
|
-
Classifier: Environment :: Win32 (MS Windows)
|
|
68
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
69
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
70
|
-
Description-Content-Type: text/markdown
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
"""A collection of python utilities for ArcGIS Desktop and ArcGIS Pro
|
|
2
|
-
"""
|
|
3
|
-
__version__ = '1.0'
|
|
4
|
-
__author__ = 'Grant Herbert'
|
|
5
|
-
|
|
6
|
-
__all__ = ['gdb.py', 'table.py']
|
|
7
|
-
|
|
8
|
-
import sys
|
|
9
|
-
if sys.version_info.major == 3:
|
|
10
|
-
from arc_utils import gdb
|
|
11
|
-
from arc_utils import table
|
|
12
|
-
from arc_utils import aprx
|
|
13
|
-
else:
|
|
14
|
-
from arc_utils import gdb
|
|
15
|
-
from arc_utils import table
|
|
16
|
-
from arc_utils import mxd
|
arc_utils-1.1/arc_utils/mxd.py
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
"""ArcGIS Desktop mxd related utilities
|
|
3
|
-
"""
|
|
4
|
-
from __future__ import print_function, unicode_literals, absolute_import
|
|
5
|
-
import arcpy
|
|
6
|
-
|
|
7
|
-
class MxdObj(object):
|
|
8
|
-
""" provide methods for working with a Arc Desktop mxd file
|
|
9
|
-
all standard arcpy methods are available via .mxd
|
|
10
|
-
Usage: mxd = arc_utils.mxd.MxdObj(path)
|
|
11
|
-
:param
|
|
12
|
-
path: a string representing an mxd file, or "CURRENT" if used in ArcMap
|
|
13
|
-
"""
|
|
14
|
-
def __init__(self, mxd_path):
|
|
15
|
-
""" sets up reference to mxd
|
|
16
|
-
adds methods
|
|
17
|
-
"""
|
|
18
|
-
self.path = mxd_path
|
|
19
|
-
self.mxd = arcpy.mapping.MapDocument(mxd_path)
|
|
20
|
-
self.layer_names_array = self._get_layer_names_as_array()
|
|
21
|
-
self.layer_obj_array = self._get_layer_obj_as_array()
|
|
22
|
-
|
|
23
|
-
def _get_layer_obj_as_array(self):
|
|
24
|
-
""" :return array of layer objects"""
|
|
25
|
-
layer_obj_array = []
|
|
26
|
-
for layer in arcpy.mapping.ListLayers(self.mxd):
|
|
27
|
-
layer_obj_array.append(layer)
|
|
28
|
-
return layer_obj_array
|
|
29
|
-
|
|
30
|
-
def _get_layer_names_as_array(self):
|
|
31
|
-
""" :return array of layer names"""
|
|
32
|
-
lyr_name_array = []
|
|
33
|
-
for layer in arcpy.mapping.ListLayers(self.mxd):
|
|
34
|
-
lyr_name_array.append(layer.name)
|
|
35
|
-
return lyr_name_array
|
|
36
|
-
|
|
37
|
-
def layer_obj_generator(self):
|
|
38
|
-
""" yields layer objects"""
|
|
39
|
-
for layer in arcpy.mapping.ListLayers(self.mxd):
|
|
40
|
-
yield layer
|
|
41
|
-
|
|
42
|
-
def layer_names_generator(self):
|
|
43
|
-
""" yields layer names"""
|
|
44
|
-
for layer in arcpy.mapping.ListLayers(self.mxd):
|
|
45
|
-
yield layer.name
|
|
46
|
-
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
Metadata-Version: 2.1
|
|
2
|
-
Name: arc-utils
|
|
3
|
-
Version: 1.1
|
|
4
|
-
Summary: Python utilities for use with Esri ArcGIS Desktop, ArcGIS Pro software
|
|
5
|
-
Home-page: https://github.com/gdherbert/arc_utils
|
|
6
|
-
Author: Grant Herbert
|
|
7
|
-
Author-email: gdherbert@gmail.com
|
|
8
|
-
License: License:: MIT
|
|
9
|
-
Download-URL: https://github.com/gdherbert/arc_utils/tree/1.0
|
|
10
|
-
Description: # README #
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
### What is this repository for? ###
|
|
14
|
-
* A collection of (mostly) arcpy related utilities for use within ArcGIS Desktop (Python 2.7), or ArcGIS Pro (Python 3) as well where possible.
|
|
15
|
-
Shortcuts for accessing elements of a map document, performing various data discovery tasks on a table or gdb
|
|
16
|
-
|
|
17
|
-
### How do I get set up? ###
|
|
18
|
-
|
|
19
|
-
* To install the utilities:
|
|
20
|
-
* `pip install arc_utils`
|
|
21
|
-
* Clone the repo to your machine and add the path to the python install https://docs.python.org/2/tutorial/modules.html#the-module-search-path
|
|
22
|
-
* Optionally, you can copy the folder to the site-packages in the ESRI python install directory, or add a .pth file to the site-packages folder pointing to the clone directory.
|
|
23
|
-
|
|
24
|
-
To use the utilities:
|
|
25
|
-
|
|
26
|
-
* in the python window in ArcMap/ArcCatalog/Pro
|
|
27
|
-
|
|
28
|
-
```python
|
|
29
|
-
import arc_utils as au
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
* typing `au.` will now reveal the modules and functions available to you if you have autocomplete on
|
|
33
|
-
|
|
34
|
-
* Depends on arcpy (only available with Esri license)
|
|
35
|
-
|
|
36
|
-
### Example usage ###
|
|
37
|
-
|
|
38
|
-
import arc_utils as au
|
|
39
|
-
|
|
40
|
-
tbl = au.table.TableObj(path to featureclass)
|
|
41
|
-
|
|
42
|
-
# list all fields
|
|
43
|
-
|
|
44
|
-
print(tbl.fields)
|
|
45
|
-
|
|
46
|
-
mxd_doc = au.mxd.MxdObj(“CURRENT”)
|
|
47
|
-
|
|
48
|
-
mxd_doc.layer_names_array >> [‘layer1’,’layer2’]
|
|
49
|
-
|
|
50
|
-
pro_doc = au.aprx.AprxObj(“CURRENT”)
|
|
51
|
-
|
|
52
|
-
pro_doc.maps >> [<arcpy._mp.Map object at 0x000001A4AECBF108>, <arcpy._mp.Map object at 0x000001A4AEBB6608>]
|
|
53
|
-
|
|
54
|
-
pro_doc.maps[0].name >> ‘Map’
|
|
55
|
-
|
|
56
|
-
### Contribution guidelines ###
|
|
57
|
-
|
|
58
|
-
Contributions welcomed, this is a starting point for various utilities that I think could be useful within Arc.
|
|
59
|
-
|
|
60
|
-
Keywords: esri arcpy arcgis
|
|
61
|
-
Platform: UNKNOWN
|
|
62
|
-
Classifier: Development Status :: 4 - Beta
|
|
63
|
-
Classifier: Intended Audience :: Developers
|
|
64
|
-
Classifier: Intended Audience :: End Users/Desktop
|
|
65
|
-
Classifier: Programming Language :: Python
|
|
66
|
-
Classifier: License :: OSI Approved :: MIT License
|
|
67
|
-
Classifier: Environment :: Win32 (MS Windows)
|
|
68
|
-
Classifier: Programming Language :: Python :: 2.7
|
|
69
|
-
Classifier: Programming Language :: Python :: 3.6
|
|
70
|
-
Description-Content-Type: text/markdown
|
arc_utils-1.1/setup.py
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
from setuptools import setup, find_packages
|
|
2
|
-
from codecs import open
|
|
3
|
-
from os import path
|
|
4
|
-
|
|
5
|
-
# Utility function to read the README file.
|
|
6
|
-
# Used for the long_description.
|
|
7
|
-
def read(fname):
|
|
8
|
-
return open(path.join(path.dirname(__file__), fname)).read()
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
setup(
|
|
12
|
-
name='arc_utils',
|
|
13
|
-
version='1.01',
|
|
14
|
-
description="Python utilities for use with Esri ArcGIS Desktop, ArcGIS Pro software",
|
|
15
|
-
license='License:: MIT',
|
|
16
|
-
long_description=read('README.md'),
|
|
17
|
-
long_description_content_type='text/markdown',
|
|
18
|
-
url='https://github.com/gdherbert/arc_utils',
|
|
19
|
-
author='Grant Herbert',
|
|
20
|
-
author_email='gdherbert@gmail.com',
|
|
21
|
-
keywords='esri arcpy arcgis',
|
|
22
|
-
download_url = 'https://github.com/gdherbert/arc_utils/tree/1.0',
|
|
23
|
-
classifiers=[
|
|
24
|
-
# 4 - Beta
|
|
25
|
-
# 5 - Production/Stable
|
|
26
|
-
'Development Status :: 4 - Beta',
|
|
27
|
-
|
|
28
|
-
# Indicate who your project is intended for
|
|
29
|
-
'Intended Audience :: Developers',
|
|
30
|
-
'Intended Audience :: End Users/Desktop',
|
|
31
|
-
'Programming Language :: Python',
|
|
32
|
-
# Pick your license as you wish (should match "license" above)
|
|
33
|
-
'License :: OSI Approved :: MIT License',
|
|
34
|
-
'Environment :: Win32 (MS Windows)',
|
|
35
|
-
# Specify the Python versions you support here. In particular, ensure
|
|
36
|
-
# that you indicate whether you support Python 2, Python 3 or both.
|
|
37
|
-
'Programming Language :: Python :: 2.7',
|
|
38
|
-
'Programming Language :: Python :: 3.6'
|
|
39
|
-
],
|
|
40
|
-
packages=find_packages()
|
|
41
|
-
)
|
arc_utils-1.1/tests/test_mxd.py
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import sys
|
|
2
|
-
if sys.version_info.major == 2:
|
|
3
|
-
from arc_utils import mxd
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
def test_mxdobj_properties(testmxd):
|
|
7
|
-
mxdpath = testmxd
|
|
8
|
-
mxdobj = mxd.MxdObj(mxdpath)
|
|
9
|
-
assert mxdobj.path == mxdpath
|
|
10
|
-
#assert mxdobj.mxd is object
|
|
11
|
-
assert mxdobj.layer_names_array == [u'test_fc']
|
|
12
|
-
assert isinstance(mxdobj.layer_obj_array, list)
|
|
13
|
-
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|