|
POST
|
I like to test field calculations with the CalculateField tool and then look at the results window and 'copy as Python snippet'. When this was done, I noticed that the domain code was wrapped in single quotes and then wrapped in double quotes. So try: arcpy.CalculateField_management(ug, "LENGTHSOURCE", "'USER'", "PYTHON_9.3") I also noticed most of your domain codes are 2 characters. If you still have issues, you may wish to confirm that 'USER' is the correct code.
... View more
06-16-2020
08:25 PM
|
1
|
1
|
3569
|
|
POST
|
As an alternative to ogr2ogr, you might consider Features to JSON. If you are using Pro or Desktop 10.5+, there is an option to Create output as GeoJSON, conforming to the GeoJSON specification. I tested the following, to which you can add a walk through your shape file directory: import arcpy
shp = r'C:\Path\To\file.shp'
out = r'C:\Path\To\file.json' # cannot use '.geojson' as extension
arcpy.FeaturesToJSON_conversion(shp, out, format_json="FORMATTED", geoJSON='GEOJSON')
# format_json is optional, makes file a bit more human readable
print('Done')
... View more
06-13-2020
10:25 AM
|
2
|
0
|
3025
|
|
POST
|
Another option might be to use a combination of List Domains and Create Domain to copy and create the domains. These tools are available in both Pro and Desktop. There are some related tools mentioned on these help pages that work with the range or coded values.
... View more
06-12-2020
10:36 AM
|
0
|
0
|
5088
|
|
POST
|
It looks like you might be using python 3. Try: print(f"Writing: {fileLocation}{os.sep}{filename}") If this doesn't solve the issue, confirm which version of Python you are using.
... View more
06-08-2020
07:40 PM
|
2
|
0
|
6574
|
|
POST
|
Assuming building number is supposed to be a string value, try: with arcpy.da.UpdateCursor(fc, ["BUILDING_NUMBER"]) as cursor:
for row in cursor:
counter += 1
row[0] = str(counter) # update first element of row
print(row[0], type(row[0])) # For testing/diagnostic purposes
cursor.updateRow(row) Note line 4, using indexing.
... View more
06-08-2020
01:07 PM
|
1
|
2
|
5269
|
|
POST
|
Look at line 52-54 in the script and you will see this note: # initialize the portal helper class
# ago.py is part of the 10.3 python install
agol_helper = ago.AGOLHelper(portal_url)
I was able to import it using desktop 10.5. So the script is a desktop thing using Python 2.7, apparently. >>> help(ago)
Help on module ago:
NAME
ago - ago.py: interact with an ArcGIS Portal instance
FILE
c:\program files (x86)\arcgis\desktop10.5\arctoolbox\scripts\ago.py
CLASSES
__builtin__.object
AGOLHelper
MultipartFormdataEncoder
class AGOLHelper(__builtin__.object)
| Interact with an ArcGIS Portal instance, such as ArcGIS Online. Must be
| initialized with either the login() method, or by reusing an existing
| OAuth token via token_login(). Covers approximately 1/3 of the complete
| API, primarily focused on the common operations around uploading and
| managing services and web maps.
... etc.
... View more
05-27-2020
05:40 PM
|
1
|
1
|
3378
|
|
POST
|
Assuming that the error on line 41 referrers to line 7 in your snippet, you might use a print statement to see what the variable gdb[0] is referencing. I also notice that later you are referencing gdb[1] for messaging which is also puzzling. Since gdb appears to be a tuple/list, you might try a print statement just to verify that it is what is expected.
... View more
05-27-2020
12:48 PM
|
1
|
0
|
3011
|
|
POST
|
If you requested json instead of geojson, you could use the JSONToFeatures tool (Pro version) to import into ArcMap. My test script using python 2.7: import arcpy, urllib, urllib2, json
URL = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/ArcGIS/rest/services/Coronavirus_2019_nCoV_Cases/FeatureServer/1/query" # query this feature
# using GET method
query_dict = {
"where" : "1=1",
"outFields" : "*",
"f": "json" }
# results in json format
response = urllib.urlopen(URL, urllib.urlencode(query_dict))
with open('covid_update.json', 'w') as f:
f.write(response.read())
arcpy.JSONToFeatures_conversion(in_json_file="covid_update.json",
out_features="C:/Path/to/file.gdb/covid_update")
print 'Done.'
... View more
05-22-2020
07:43 PM
|
1
|
2
|
2273
|
|
POST
|
You can use the json module to process the geojson. I was testing the following using python 2.7. It makes the URL request and writes a tab delimited file. import urllib, urllib2, json, sys, time, collections
fw = open("covidUpdate.txt", "w") # file to write
URL = "https://services1.arcgis.com/0MSEUqKaxRlEPj5g/ArcGIS/rest/services/Coronavirus_2019_nCoV_Cases/FeatureServer/1/query" # query this feature
# using GET method
query_dict = {
"where" : "1=1", # something always true
"outFields" : "*",
"f": "geojson" }
# results in geojson format
jsonResponse = urllib.urlopen(URL, urllib.urlencode(query_dict))
features = json.loads(jsonResponse.read(),
object_pairs_hook=collections.OrderedDict)[u'features']# using the features section
# Header
fw.writelines("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n".format(
'OBJECTID','Province_State','Country_Region','Last_Update','Latitude','Longitude','Confirmed','Recovered','Deaths'))
# Data rows
for f in features:
fw.writelines("{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\t{}\n".format(
f['properties']['OBJECTID'],
f['properties']['Province_State'] if f['properties']['Province_State'] is not None else '',
f['properties']['Country_Region'],
# convert timestamp to local time
# time.strftime('%c', time.localtime(f['properties']['Last_Update']/1000)) if f['properties']['Last_Update'] is not None else '',
# convert timestamp to GMT
time.strftime('%Y-%m-%d %H:%M:%S', time.gmtime(f['properties']['Last_Update']/1000)) if f['properties']['Last_Update'] is not None else '',
f['properties']['Lat'],
f['properties']['Long_'],
f['properties']['Confirmed'],
f['properties']['Recovered'],
f['properties']['Deaths']))
fw.close()
print 'Done.' Results: OBJECTID Province_State Country_Region Last_Update Latitude Longitude Confirmed Recovered Deaths
1 Abruzzo Italy 2020-05-22 23:32:40 42.35122196 13.39843823 3220 1647 394
2 Acre Brazil 2020-05-22 23:32:40 -9.0238 -70.812 3343 0 80
3 Aguascalientes Mexico 2020-05-22 23:32:40 21.8853 -102.2916 586 402 21
..... I noticed that Provence_State is sometimes null/None, as was the timestamp on occasion. I kept the time in GMT/UTC, but you can convert it to local time if desired. It is also possible to use an insert cursor and create a feature layer if desired. This should give you some ideas.
... View more
05-22-2020
05:45 PM
|
0
|
0
|
2273
|
|
POST
|
Check out the examples using the Domains toolset (ArcMap) or Pro. Specifically look at code for Delete Coded Value To Domain and Add Coded value to Domain. Delete the old value, add the new value. There is a tool to resort the the domain which may be of benefit, particularly when using tools like Collector. If you are not changing the code (just the description), you probably shouldn't have to change your data. If you do need to change your data, you could use an update cursor and a where statement (where field using domain equals the code value being replaced). Alternatively, you could use the Field Calculator.
... View more
05-20-2020
12:24 PM
|
1
|
0
|
1359
|
|
POST
|
It should run with 10.6. I assume you are running the script as a script tool inside ArcMap. Can you describe your process, what parameters you are using, etc.?
... View more
05-11-2020
10:35 AM
|
0
|
0
|
846
|
|
POST
|
You might check out the answer given in this Stackoverflow discussion about the 64 and 32-bit versions of Access 2010.
... View more
05-11-2020
10:26 AM
|
1
|
0
|
6925
|
|
POST
|
Are you connecting to 32 or 64 bit Access? You might try: connStr = (
r"DRIVER={Microsoft Access Driver (*.mdb, *.accdb)};"
r"P:\Conservation Programs\Natural Heritage Program\Data Management\ACCESS databases\POND_entry\POND_be.accdb;"
)
conn = pyodbc.connect(connStr)
... View more
05-08-2020
12:00 PM
|
2
|
2
|
6925
|
|
POST
|
I think you have the solution. For a "prettier way", perhaps: if 'TableView' in str(type(brknItem)):
# do something
... View more
05-02-2020
10:30 AM
|
1
|
1
|
1532
|
|
POST
|
It appears to be a unix timestamp in nanoseconds. Scientific notation
1.5390954e+18
+18 move decimal 18 places to right
Timestamp in nanoseconds
1539095400000000000
Converts to UTC as:
Tuesday, October 9, 2018 2:30:00 PM
If you convert the UTC for your timezone, it should match. AGOL usually stores the date as timestamp; but I would have expected milliseconds. from datetime import datetime
from dateutil import tz
from pytz import timezone
ts = float("1.5390954e+18")
UTC = datetime.utcfromtimestamp(ts // 1000000000).replace(tzinfo=tz.tzutc())
print UTC
# 2018-10-09 14:30:00+00:00
east = UTC.astimezone(timezone('Canada/Eastern'))
print east
# 2018-10-09 10:30:00-04:00
... View more
05-01-2020
03:01 PM
|
1
|
1
|
4225
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-27-2016 02:23 PM | |
| 1 | 09-09-2017 08:27 PM | |
| 2 | 08-20-2020 06:15 PM | |
| 1 | 10-21-2021 09:15 PM | |
| 1 | 07-19-2018 12:33 PM |
| Online Status |
Offline
|
| Date Last Visited |
02-12-2026
07:13 PM
|