|
POST
|
Since this was just one example, I used Excel to do the conversion from DMS to decimal degrees and converted degrees East to degrees West. These were done with formulas, so for your project I would suggest writing a python function to do the conversion.
... View more
08-02-2018
11:55 AM
|
1
|
0
|
2991
|
|
POST
|
I've always wondered how to deal with issues with the dateline, then I came across a reference to WGS 1984 (G1762) in the Collector section. This Geographic Coordinate System uses decimal degrees that go North and South past +- 90 degrees and East and West past +- 180 degrees. I created a polygon feature using this system and plotted your coordinates. Those to one side of the dateline were converted to the other side; that is, 130 degrees East became -230 degrees West. Here's my script and results: import arcpy
dataset = r"C:\Path\To\filegeodatabase.gdb\PolyTest"
sr = arcpy.Describe(dataset).spatialReference
print sr.factoryCode
# 104015
print sr.name
# u'WGS_1984_(G1762)'
# A list of features and coordinate pairs
feature_info = [[[-230, 21],[-205, 21],[-205, 27], [-195, 27],[-195, 43],[-197.083333333333, 45.7],
[-176.566666666667, 50.1333333333333],[-167.816666666667, 51.4],[-160, 53.5],[-153, 56],
[-151.75, 56.8666666666667],[-137, 53.375],[-135, 52.7166666666667],[-133.75, 51],
[-128, 48.3333333333333],[-128, 48.1666666666667],[-126.5, 45],[-126.9, 40.9833333333333],
[-127, 40.8333333333333],[-127, 37.5638888888889],[-126.933333333333, 36.5694444444444],
[-125.833333333333, 35.5],[-124.2, 36],[-123.25, 34.5],[-120.833333333333, 30.75],[-120, 30],
[-120, 3.5],[-145, 3.5],[-155, -5],[-180, -5],[-180, 3.5],[-200, 3.5],[-200, 0],[-219, 0],
[-219, 3.5],[-227, 3.5],[-230, 7]]]
# Open an InsertCursor to insert the new geometry
cursor = arcpy.da.InsertCursor(dataset, ['SHAPE@','Name'])
for feature in feature_info:
# Create a Polygon object based on the array of points
# Append to the list of Polygon objects
polygon = arcpy.Polygon(
arcpy.Array([arcpy.Point(*coords) for coords in feature]))
cursor.insertRow([polygon,'Test1'])
# Delete cursor object
del cursor
... View more
08-02-2018
11:23 AM
|
1
|
2
|
2991
|
|
POST
|
Perhaps something like this for the ToolValidator class (script tool, not python toolbox): import arcpy
class ToolValidator(object):
"""Class for validating a tool's parameter values and controlling
the behavior of the tool's dialog."""
def __init__(self):
"""Setup arcpy and the list of tool parameters."""
self.params = arcpy.GetParameterInfo()
def initializeParameters(self):
fc = r'C:\Path\To\Test.gdb\TableTest' # our table with set-up data
fld = 'Selection' # field named 'Selection'
self.params[0].filter.list = [str(val) for val in sorted(set(row[0] for row in arcpy.da.SearchCursor(fc, fld)))]
self.params[0].value = self.params[0].filter.list[0] # on init, set to first value in list
return
def updateParameters(self):
if self.params[0].value: # an option has been selected
fc = r'C:\Path\To\Test.gdb\TableTest' # our table with set-up data
flds = ( 'Option1', 'Option2', 'Option3','Option4' ) # fields with values we want
wClause = "Selection = '{}'".format(self.params[0].value) # match field 'Selection'
values = next(arcpy.da.SearchCursor(fc, flds, where_clause=wClause))
self.params[1].value = values[0]
self.params[2].value = values[1]
self.params[3].value = values[2]
self.params[4].value = values[3]
return
def updateMessages(self):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
... View more
07-27-2018
03:01 PM
|
2
|
2
|
6846
|
|
POST
|
I could see the approach you want as being workable. I would look at the updateParameters section of the ToolValidator class. Although it doesn't take your desired approach, this thread on Conditional Drop Down Lists - Tool Validator may give you some ideas in using updateParameters. Unfortunately, the blog posting mentioned in the first post is no longer available (or not yet available) in the new ESRI blogs. I imagine you would have your users select the appropriate row in your table based on a value in the first column. Then other column values in the selected row would populate several of your tool's option selections. Can you describe how your table would be organized and how you would use the values from it in your tool?
... View more
07-26-2018
10:08 PM
|
2
|
0
|
6846
|
|
POST
|
Try this at line 80 in your updateParameters section (.endswith can't be used unless there is text in the parameter): if parameters[4].valueAsText is not None:
if not parameters[4].valueAsText.endswith('xls'):
parameters[4].value=parameters[4].valueAsText+'.xls'
... View more
07-19-2018
12:33 PM
|
1
|
1
|
2146
|
|
POST
|
In the where clause, try >= with the date, otherwise you might be matching today's date at midnight. And you might try a different format for the date. whereClause = "Approved = 'Yes' AND Date_Approved >= '{} 00:00:00'".format(today.strftime('%Y-%m-%d'))
# whereClause =
# "Approved = 'Yes' AND Date_Approved >= '2018-07-18 00:00:00'" Also, can you confirm that the data in Approved is a text string consisting of either 'Yes' or 'No'? Could it be using some other value? 'Y' or 'N', 'True' or 'False'?
... View more
07-18-2018
12:22 PM
|
0
|
0
|
2739
|
|
POST
|
Add it to your where clause. The SQL syntax may vary slightly depending on the type of database you are using. Are you using a file geodatabase or another type? whereClause = "Approved = 'Yes' AND DateField BETWEEN '2018-01-01' AND '2018-07-01'"
whereClause = "Approved = 'Yes' AND DateField > '2018-01-01' AND DateField < '2018-07-01'"
... View more
07-18-2018
09:36 AM
|
0
|
2
|
2739
|
|
POST
|
I was a bit confused by your loop. You were looping through your pop_cent list instead of your text elements. If you didn't have the same number of text elements as in your list, you would get an indexing error. I would suggest that your template map have a number of text elements available and named - the content can be an empty string or spaces. Then you can check if the name is a certain value, then set the text value and position as necessary.
... View more
07-17-2018
12:08 PM
|
1
|
1
|
3072
|
|
POST
|
Something like this should give a listing with a count of the values in the LIFECYCLESTATUS field: import arcpy
fc = r'G:\pworks\assetmanagement\Local Gov Info Model\Wastewater\Inputs\Valve_Schema.gdb\SControlValve'
field = 'LIFECYCLESTATUS'
d = {} # new dictionary
with arcpy.da.SearchCursor(fc, (field)) as rows:
for row in rows:
if row[0] not in d:
d[row[0]] = 1
else:
d[row[0]] += 1
for k, v in d.iteritems():
print k, v
... View more
07-16-2018
09:12 AM
|
0
|
0
|
2185
|
|
POST
|
I don't think it is possible with arcpy. When you make changes to the TOC without changing the data, the change is saved only in the mxd file. I'm not sure you could or would want to edit the mxd directly.
... View more
07-14-2018
08:28 PM
|
1
|
0
|
1079
|
|
POST
|
A basic approach would look something like: import arcpy
fc = r"C:\Path\To\database.gdb\Approaches" # feature class
fn = r"C:\Path\To\output.txt" # save file name
f = open(fn, 'w')
fields = ['Name', 'Approved'] # can add other fields such as Approved, if needed
whereClause = "Approved = 'Yes'" # may need to modify, based on field type, how Y-N is stored
with arcpy.da.SearchCursor(fc, fields, where_clause=whereClause) as cursor:
for row in cursor:
f.write("{}\t{}".format(row[0], row[1])) # Name and Approved - to file
print "{}\t{}".format(row[0], row[1]) # Name and Approved - to console if needed
f.close()
print "Done" (It will probably need some editing to work with your data.)
... View more
07-13-2018
05:06 PM
|
1
|
6
|
2739
|
|
POST
|
I notice in your second code posting, you are running multiple update cursor loops, once for each item in your list (line 12). With either the indexing solution from Joshua or the dictionary solution, only a single pass with an update cursor is needed and is more efficient.
... View more
07-13-2018
02:11 PM
|
1
|
2
|
5422
|
|
POST
|
For the dictionary approach, a check would be something like: for row in cursor:
if if row[0] not in LCStatus.keys():
# print error message and keep original value
print "{} not in list".format(row[0])
else: # update value
row[0] = LCStatus[row[0]]
cursor.updateRow(row)
... View more
07-13-2018
12:24 PM
|
1
|
0
|
5422
|
| 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
|