|
POST
|
Does something like this help: fc1 = "C:\Temp\blah1.dbf"
fld1 = ["Field1", "Copy"]
fc2 = "C:\Temp\blah2.dbf"
fld2 = ["Field2"]
valueList = [r[0] for r in arcpy.da.SearchCursor(fc2, fld2)]
with arcpy.da.UpdateCursor(fc1, fld1) as cursor:
for row in cursor:
if row[0] in valueList:
row[1] = 'Copy' # May wish to swap 'Copy' and 'No'
else:
row[1] = 'No'
cursor.updateRow(row)
... View more
03-04-2020
07:34 PM
|
0
|
1
|
4714
|
|
POST
|
I think this also works for python3, put the "f" before the triple quotes ( not inside 😞 ts = '2020-03-04 12:21:00'
query = f"""SELECT idProject, idController, siteAddress,
siteApn,projectName, projectType,dateCreated,
datePermitIssued, permitNumber,applicationApprovedBy
FROM master_db.saltlakecountybuildingpermits
where datePermitIssued > '{ts}'
and siteAddress is not null;"""
print(query)
... View more
03-04-2020
12:24 PM
|
2
|
1
|
1601
|
|
POST
|
Are the values in "Field1" and "Field2" unique identifiers and can only appear once in each feature? If so, you could read the value of fc2's Field2 into a list/dictionary. Then use an update cursor to mark the Copy field if Field1 is not in the Field2 list.
... View more
03-04-2020
12:13 PM
|
1
|
5
|
3052
|
|
POST
|
Does something like this work for you: >>> ts = '2020-03-04 12:21:00'
>>> query = """SELECT idProject, idController, siteAddress,
siteApn,projectName, projectType,dateCreated,
datePermitIssued, permitNumber,applicationApprovedBy
FROM master_db.saltlakecountybuildingpermits
where datePermitIssued > '{}'
and siteAddress is not null;""".format(ts)
>>> print query
SELECT idProject, idController, siteAddress,
siteApn,projectName, projectType,dateCreated,
datePermitIssued, permitNumber,applicationApprovedBy
FROM master_db.saltlakecountybuildingpermits
where datePermitIssued > '2020-03-04 12:21:00'
and siteAddress is not null;
... View more
03-04-2020
12:03 PM
|
2
|
3
|
1601
|
|
POST
|
Perhaps this ZIP Code to ZCTA Crosswalk may be of help. And this page explains a bit about zip codes vs ZCTA.
... View more
02-29-2020
07:50 PM
|
1
|
1
|
2183
|
|
POST
|
Regarding your question about using the GlobalID, the documentation says: The attributes property of the feature should include the object ID (and the global ID, if available) of the feature along with the other attributes. I have used just the OBJECTID field without the global ID (it is a bit to complex to type easily) to update features on AGOL. If you want to use the FACILITYID, one way would be to use it to query the feature to obtain the OBJECTID and/or GlobalID. Then use the OBJECTID to make the update.
... View more
02-28-2020
07:17 PM
|
2
|
1
|
2323
|
|
POST
|
Your json is missing a comma after "LOW". You can check your json using a service like jsonlint.com. [{
"attributes": {
"ADMINISTRA": "LOW"
"GlobalID": "{a8917ecd-d21e-46ce-b34a-46b0be3e5b4c}"
}
}]
Result from jsonlint.com:
Error: Parse error on line 3:
...DMINISTRA": "LOW" "GlobalID": "{a8917e
Correction:
[{
"attributes": {
"ADMINISTRA": "LOW",
"GlobalID": "{a8917ecd-d21e-46ce-b34a-46b0be3e5b4c}"
}
}]
Result from jsonlint.com:
Valid JSON
... View more
02-28-2020
07:01 PM
|
2
|
0
|
2323
|
|
POST
|
I have used the Update Definition (Feature Layer) of the REST API to modify domains (see example 6). I think adding to the domain list works best, as deleting a domain value may leave some invalid values in the field. Instead of deleting a domain, I would recommend changing the name/description to indicate it is out of date. If the field needing the domain update is used for symbology, you will also need to edit and update the "types" section of the JSON file. I have not used the ArcGIS API for Python for this purpose. For this, I would explore the update_definition section of the API documentation.
... View more
02-23-2020
08:08 PM
|
2
|
0
|
9804
|
|
POST
|
What are you working with - Desktop 10.x, Pro, AGOL ? With Desktop for example, the label manager allows for creating an expression. Python code would be something like (note: advanced checked): from datetime import datetime
def FindLabel ( [EditDate] ):
ds = datetime.strptime([EditDate], '%m/%d/%Y %H:%M:%S %p')
return ds.strftime("%B %Y")
... View more
01-22-2020
07:41 PM
|
2
|
1
|
3030
|
|
POST
|
Did you try something like indicating that total_rows was a global in the "execute" function (line 3) below: def execute(self, parameters, messages):
"""The source code of the tool."""
global total_rows # indicate that total_rows is a global
inputdataset = parameters[0].valueAsText #getting the parameters
count_rows = arcpy.GetCount_management(inputdataset)
total_rows = int(count_rows.getOutput(0))
expression = '''
def getCitation(p_dataset_id):
global total_rows
if(total_rows == 5):
ds=PanDataSet(p_dataset_id)
return ds.citation
''' I'm also puzzled by the indentation in the code snippet you posted. Is the "expression" section (lines 9 -17) part of the "execute" function? It may not be indented properly.
... View more
01-21-2020
11:22 PM
|
0
|
0
|
3369
|
|
POST
|
Using globals in a Python toolbox or script tool is a bit tricky. The toolbox/script creates a number of instances during function calls. It is best to declare a global in getParameterInfo as this function appears to be called only once. An example of a toolbox script that uses "junk" as a global variable is: import arcpy
class Toolbox(object):
def __init__(self):
self.label = "Toolbox"
self.alias = ""
self.tools = [Tool]
class Tool(object):
def __init__(self):
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
global junk
junk = None
param0 = arcpy.Parameter(
displayName="Something",
name="something",
datatype="GPString",
parameterType="Required",
direction="Input"
)
params = [param0]
return params
def isLicensed(self):
return True
def updateParameters(self, parameters):
global junk
junk = "XYZ"
return
def updateMessages(self, parameters):
return
def execute(self, parameters, messages):
global junk
arcpy.AddMessage("The value junk is: " + junk)
return For more discussion see the following: Using Global Variables in Python Toolbox? Python toolbox tool objects do not remember instance variables between function calls?
... View more
01-17-2020
07:51 PM
|
1
|
3
|
3369
|
|
POST
|
Dan Patterson offers a good suggestion for formatting your OR statement and should correct your issue. The print statement (e.g. print (expression1)) also only prints the variable Q1_A. This is because of the double quotes around the word " or ". # wrong
expression1 = ("Vessel_Name = '" + str(Q1_A) + "'" or "Vessel_Name = '" + str(Q1_B) + "'")
# correct
expression1 = ("Vessel_Name = '" + str(Q1_A) + "' or Vessel_Name = '" + str(Q1_B) + "'")
... View more
01-17-2020
06:39 PM
|
2
|
1
|
4739
|
|
POST
|
To set the output format, use the "f" query parameter: f=json See Output formats for more information.
... View more
01-15-2020
06:12 PM
|
2
|
1
|
1772
|
|
POST
|
Features use a format like (assuming you are not including geometry): [
{
"attributes" : {
"Name" : "TestName",
"ColumnTwo": 2
}
},
{
"attributes" : {
"Name" : "TestName2",
"ColumnTwo": 3
}
}
] Note the coma on line 7 as it joins the next feature. Typically, the feature would include "attributes" and "geometry". [
{
"attributes" : {
"Name" : "TestName",
"ColumnTwo": 2
},
"geometry" : {
"x" : -111.111,
"y" : 111.111
}
}
] For more information see: Add Features
... View more
01-15-2020
06:05 PM
|
3
|
1
|
3766
|
|
POST
|
Since you are interested in file creation/modification dates, I was experimenting with the following: from datetime import datetime
import dateutil.tz as tz # to convert utc to local time
import dateutil.parser as parser # will parse a variety of datetime formats
import requests
import os.path
import xml.etree.ElementTree as ET # for parsing xml file
import zipfile # to open zip file (excel uses this format)
directory = r'C:\Path\To\Save\Directory' # directory for saved file
file = 'Grid_Support_Inverter_List_Full_Data.xlsm' # name of saved file
# file to download
url = "https://www.gosolarcalifornia.ca.gov/equipment/documents/Grid_Support_Inverter_List_Full_Data.xlsm"
content = requests.get(url)
# print content.headers # for debugging
# get Last-Modified date from header and print as a local time
webModDate = parser.parse(content.headers['Last-Modified']).astimezone(tz.tzlocal())
print "Web Last-Modified: {}".format(webModDate.strftime('%Y-%m-%d %H:%M:%S'))
# save downloaded excel file to local drive
with open(os.path.join(directory, file), 'wb') as f:
f.write(content.content)
f.close()
# excel file format is a type of zip file
# read an xml file inside the excel file to get file modified date
# and convert to local date timetime
zip = zipfile.ZipFile(os.path.join(directory, file))
props = zip.open('docProps/core.xml') # core document properties
xmlText = props.read()
zip.close()
# print xmlText # for debugging
ns = { 'cp' : 'http://schemas.openxmlformats.org/package/2006/metadata/core-properties',
'dc' : 'http://purl.org/dc/elements/1.1/',
'dcterms' : 'http://purl.org/dc/terms/' }
tree = ET.fromstring(xmlText)
creator = tree.find('dc:creator', ns).text
lastModBy = tree.find('cp:lastModifiedBy', ns).text
created = tree.find('dcterms:created', ns).text
modified = tree.find('dcterms:modified', ns).text
# print creator, lastModBy, created, modified # for debugging
# convert excel modified date to local datetime
xlModDate = parser.parse(modified).astimezone(tz.tzlocal())
print "Excel file modified: {}".format(xlModDate.strftime('%Y-%m-%d %H:%M:%S'))
# get the saved file's create and modified date from operating system
# datetime will be timestamp in local time, when file was saved
# (basically the time when this script was run)
osCreateDate = datetime.fromtimestamp(os.path.getctime(os.path.join(directory, file)))
print "OS file created: {}".format(osCreateDate.strftime('%Y-%m-%d %H:%M:%S'))
osModDate = datetime.fromtimestamp(os.path.getmtime(os.path.join(directory, file)))
print "OS file modified: {}".format(osModDate.strftime('%Y-%m-%d %H:%M:%S')) The results: Web Last-Modified: 2020-01-02 10:48:55
Excel file modified: 2020-01-02 09:32:50
OS file created: 2020-01-03 18:12:12
OS file modified: 2020-01-03 18:12:12 From this, you can see that the Excel file was modified a bit over an hour before it was put on the web server. The modified date/time came directly from xml inside the Excel file. The operating system gave the file the same create and modified date indicating when the file was downloaded and saved to the local system (and not the actual time the Excel file was last modified). You should be able to use requests.head(url) to retrieve just the header to examine the modified date and then determine if you want to actually download the file.
... View more
01-03-2020
07:47 PM
|
0
|
1
|
2464
|
| 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
|