POST
|
I have a way to do it from a field so sadly that does not help I could manually type the list of feature classes but that is hacking it together ..
... View more
12-29-2015
10:53 AM
|
0
|
0
|
1278
|
POST
|
Hi all, I have a tool that basically push's data down from one environment to another. An example of this is from production to test environment. Currently the tool has the import feature classes hard coded into it. What I am trying to do is generate a Dynamic list when the first parameter is selected (a database connection file) Anyone have any advice for me that would be great! Below is the code i currently have that does not work.
def getParameterInfo(self):
from_database = arcpy.Parameter(
displayName = "From Database",
name = "from_database",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
from_database.filter.type = "ValueList"
from_database.filter.list = [self.prod, self.test]
to_database = arcpy.Parameter(
displayName = "To Database",
name = "to_database",
datatype = "GPString",
parameterType = "Required",
direction = "Input")
to_database.filter.type = "ValueList"
to_database.filter.list = [self.test, self.dev]
select_features = arcpy.Parameter(
displayName = "Select Features to Push Down",
name = "down_features",
datatype = "DEFeatureClass",
parameterType = "Required",
direction = "Input"
multiValue = True)
parameters = [from_database, to_database, select_features]
return parameters
def updateParameters(self, parameters):
if parameters[0].value:
arcpy.env.workspace = parameters[0].valueAsText
fcs = arcpy.ListFeatureClasses()
parameters[3].filter.list = fcs
return So what i want is to get a check box list of all the feature classes in the "from_database" parameter where the user can check the feature classes they want to send from production to test.... basically to update our environments. Let me know thanks everyone! -Matt below is my values for the database connections self.prod = r'\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\PRODUCTION_10.2.2_GISUser_Default.sde'
self.test = r'\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\Test_10.2.2_GISUser_Default.sde'
self.dev = r'\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\Dev_10.2.2_GISUser_Default.sde'
... View more
12-29-2015
09:03 AM
|
0
|
4
|
5302
|
POST
|
For some reason I am running into an issue on a filter list for my tool box. Below is my Code: def getParameterInfo(self):
"""Define parameter definitions"""
prod = "\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\PRODUCTION_10.2.2_GISUser_Default.sde"
test = "\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\Test_10.2.2_GISUser_Default.sde"
dev = "\\hqstore\geostore\Software\Scripts\Python_Toolbox\ConnectionFiles\Dev_10.2.2_GISUser_Default.sde"
from_database = arcpy.Parameter(
displayName = "From Database",
name = "From_Database",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
#from_database.filter.type = "ValueList"
#from_database.filter.list = [prod, test]
to_database = arcpy.Parameter(
displayName = "To Database",
name = "To_Database",
datatype = "DEWorkspace",
parameterType = "Required",
direction = "Input")
#to_database.filter.type = "ValueList"
#to_database.filter.list = [test, dev]
parameters = [from_database, to_database]
return parameters any ideas why this is not working? the filters are commented out... so my tool works # Ignore my spacing it is just how the copy paste ended up
... View more
12-28-2015
03:02 PM
|
0
|
2
|
5552
|
POST
|
def delCursor(table):
try:
counter = 0
with arcpy.da.UpdateCursor(table, "*") as cursor:
for row in cursor:
counter +=1
cursor.deleteRow()
except:
arcpy.ClearWorkspaceCache_management()
delcursor(table_name)
# This is how I clear a table... it does take a bit of time but found that it worked in SDE
... View more
12-18-2015
10:15 AM
|
0
|
0
|
2908
|
POST
|
This issue has come up time and time again. I make programmatic edits in a version SDE. To save everyone some time i have attached my code snippet that current works to update rows in SDE. (See Below) db = database connection file
edit = arcpy.da.Editor(db)
edit.startEditing()
edit.startOperation()
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
for code in facilCodes:
if code == row[0]:
row[1] = "New Mexico Central"
cursor.updateRow(row)
count += 1
print("This information")
edit.stopOperation()
edit.stopEditing(save_changes=True)
Formatted in this way, my code works... and updates the rows in the version SDE What I am looking to do is write a class or a few functions so that I can reuse my edit code. What I have tried so far is this... def openEdit(database):
edit = arcpy.da.Editor(database)
edit.startEditing()
edit.startOperation()
def closeEdit(database):
edit = arcpy.da.Editor(database):
edit.stopOperation()
edit.stopEditing(save_changes=True):
# Then I run it like this:
db = database connection file
openEdit(db)
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
for code in facilCodes:
if code == row[0]:
row[1] = "New Mexico Central"
cursor.updateRow(row)
count += 1
print("This information")
closeEdit(db) It gives me an error saying: RuntimeError: Objects in this class cannot be updated outside an edit session [GISUSER.T_SWITCH] This leads me to believe after my openEdit function runs it does not leave the edit session open? Any ideas to help me be able to reuse code like this?
... View more
12-18-2015
09:59 AM
|
1
|
1
|
2629
|
POST
|
Hi All, I have created a script that does some data checks and I am down to my last check. Where I am stuck at is comparing time Values between rows in a Search Cursor. for example I will have several tables that have 2-10 values in them. My code looks something like this: table = 'b3514str133'
field = "INP_DATE"
tempList = []
with arcpy.da.SearchCursor(table, field) as cursor:
for row in cursor:
tempList.append(row)
# My Templist now looks like this : [(datetime.datetime(2015, 4, 1, 14, 22, 4),),
(datetime.datetime(2015, 4, 1, 14, 22, 10),),
(datetime.datetime(2015, 4, 1, 14, 22, 15),),
(datetime.datetime(2015, 4, 1, 14, 22, 20),),
(datetime.datetime(2015, 4, 1, 14, 22, 37),)]
for item in tempList:
if any of the items are within 1 hour of each other:
print row
My first question is: Is this the easiest way to do this? My Second question is: Should I be using a list to do this or can i compare each row by all the other rows? My third question is: What if statement could i used to compare each row within 1 hour of each other? My checks go through about 5 different levels of verification so my mind is currently blown!!!! Any help would be great thanks! -Matt
... View more
09-09-2015
09:11 AM
|
0
|
2
|
3239
|
POST
|
Thinking about it, I think you have to setup your environments in windows? I could be wrong because I am not able to do this at work (no admin rights). check this out: Setting Python Path (PythonPath) system variable : KatsBits TUTORIALS
... View more
06-12-2015
06:14 AM
|
0
|
0
|
388
|
POST
|
I run larger scripts in the command line, they work faster and I believe Tony is correct
... View more
06-12-2015
06:01 AM
|
0
|
0
|
867
|
POST
|
I had issues with PyScripter and switched to PyCharm, I like it way better. Sorry for stealing your thread!
... View more
06-12-2015
05:58 AM
|
0
|
2
|
2892
|
POST
|
put your buffer in the loop and clean go through your logic
... View more
05-08-2015
11:28 AM
|
0
|
1
|
487
|
POST
|
Exactly the information I was looking for thanks Dan.
... View more
05-08-2015
08:59 AM
|
0
|
1
|
682
|
POST
|
Hi all, I have wrote a small "Module" that I call in my ArcGIS Python window to do simple tasks for me when I am doing edits. When I call my Function basically only the function and the arguments show up. In the module I have a docstring listed below in hopes that it would pick that up as well incase i want to share this with co-workers. Anyone know the solution to this? Below is an example of one of the functions: def calc_feet(table):
""" Creates a Field named "Feet" and calculates the Field """
py = "PYTHON_9.3"
var = "Feet"
type = "DOUBLE"
sql = "float(!shape.length@feet!)"
arcpy.AddField_management(table, var, type)
arcpy.CalculateField_management(table, var, sql, py, "#")
import gis # my module
gis.calc_feet("my table")
#help window only shows:
gis.calc_feet(table) with no docstring
... View more
05-08-2015
08:22 AM
|
0
|
4
|
6302
|
POST
|
def import_to_GDB(input_workspace, output_workspace):
import arcpy
import os
base = os.path.basename(input_workspace)
arcpy.CreateFileGDB_management(output_workspace, base)
for dirpath, dirnames, filenames in arcpy.da.Walk(input_workspace):
for dirname in dirnames:
try:
x = os.path.join(dirpath, dirname)
desc = arcpy.Describe(x)
name = desc.name
print("Working on: {0}".format(name))
if "-" in name:
new_name = "rename"
arcpy.Rename_management(x, new_name)
dir_path = os.path.join(dirpath, new_name)
arcpy.env.workspace = dir_path
fcs = arcpy.ListFeatureClasses()
fds = os.path.join(output_workspace, base + ".gdb\\")
arcpy.CreateFeatureDataset_management(fds, new_name)
suboutput = os.path.join(fds, new_name)
count = 0
for fc in fcs:
count = count + 1
try:
arcpy.FeatureClassToGeodatabase_conversion(fc, suboutput)
print("{0} Complete".format(count))
except:
print("{0} had an error, passing to the next object".format(fc))
else:
dir_path = os.path.join(dirpath, dirname)
arcpy.env.workspace = dir_path
fcs = arcpy.ListFeatureClasses()
fds = os.path.join(output_workspace, base + ".gdb\\")
arcpy.CreateFeatureDataset_management(fds, dirname)
suboutput = os.path.join(fds, dirname)
count = 0
for fc in fcs:
count = count + 1
try:
arcpy.FeatureClassToGeodatabase_conversion(fc, suboutput)
print("{0} Complete".format(count))
except:
print("{0} had an error, passing to the next object".format(fc))
except:
print("{0} had an error, passing to the next object".format(dirname)) This currently works, but it only tests for a "-" it was passing the if statment everytime if i tested " " .... any ideas?
... View more
04-09-2015
01:32 PM
|
0
|
1
|
703
|
POST
|
Dan, Thanks alot you got the ball rolling for some interesting things
... View more
04-09-2015
11:32 AM
|
0
|
0
|
703
|
Title | Kudos | Posted |
---|---|---|
1 | 04-07-2015 10:22 AM | |
1 | 12-18-2015 09:59 AM | |
1 | 01-28-2015 12:58 PM |
Online Status |
Offline
|
Date Last Visited |
05-10-2023
03:58 PM
|