POST
|
Hi all, I have a load of VB.NET code that is currently utilized in ArcDesktop. The code does a range of jobs, including the use of ArcObjects. My company is contemplating transferring this code from ArcDesktop to ArcPro. I have been tasked with working out whether or not the functionality that the code currently uses from ArcObjects can be re-created in ArcPro. I am confident that, for the most part, this will be achievable. Part of what the VB code currently uses ArcObjects for is visualization and creating graphs. Would anyone be able to clarify that it is possible to re-create the core/majority of ArcObjects functionality in ArcPro and/or any functionality that is not supported can be created with some sort of VB or Python addin? I am particularly interested in any thoughts as to why transferring the VB code to ArcPro would be a bad idea over leaving it in ArcDesktop. Thanks in advance for any advice. Ben
... View more
07-15-2016
03:48 AM
|
0
|
1
|
1327
|
POST
|
Thanks Dan, that link was helpful. Your link didn't work for some reason so hopefully this one will LayerTime—Help | ArcGIS for Desktop The method shown in that link did not completely work for me, mainly because I am working from raster layers so some of the code was not working. Instead I found this link using arcpy to export separate netcdf dimension values as a raster . The answer that Justin Koppa gave helped me solve my issue. I took a step back and batch imported the .nc files as raster layers (MakeNetCDFRasterLayer). I created a separate raster layer for each time interval (1 day), then used the 'Extract Multi Values to Point' tool to join the data to my points layer. The code below is what I ended up using which so far has worked fine. The only thing I didn't include is a method to delete the unwanted raster layers after the Extract Multi Values To Points tool was used. Sorry I have forgotten how to format code in here # Year info years = range(2013,2015) for yrs in years: # Month info allMnths = range(1,12) for mnths in allMnths: Lastday = calendar.monthrange(Yr, mnths)[1] MRange = range(1,Lastday+1) for dyy in MRange: dyys =int(dyy) mnthsss = int(mnths) Yr = int(yrs) a = str(Yr) + "-" + str(mnthsss)+ "-" + str(dyys) inDate = "time " + a rainfall_2013_nc = r"D:\rainfall_data\UK_data_2013_2015.nc" layer_title = "rr_" + a # Process: Make NetCDF Raster Layer arcpy.MakeNetCDFRasterLayer_md(rainfall_2013_nc, "rainfall_amount", "x", "y", layer_title, "", inDate, "BY_VALUE") # run the Extract Multi Values to Points tool on the newly created raster layer ExtractMultiValuesToPoints("SR_Loc_All", layer_title, "NONE")
... View more
06-28-2016
10:23 AM
|
1
|
0
|
788
|
POST
|
Hi, I am trying to run the 'Extract Multi Value to Points' tool in ArcGIS 10.3. The purpose for running this tool is that I have four time enabled raster layers (rainfall measurements) and a point layer. The raster layers have a single value (daily average) per day for a whole yea. What I want to end up with is in the points layer a column for each of the daily values from all four raster layers. The 'Extract Multi Value to Point' tool does this perfectly for the currently visible time period of the raster layers. Now seeing as I do not want to run this tool 365 times manually, I was wondering if anyone new of a quicker way to go about this? If the answer is to create a python script to iterate through each of the time intervals then that is fine. If this is the case does anyone know how to set the selected/visible time interval (daily value) for a raster layer in python? Thanks in advance for any help, Ben.
... View more
06-28-2016
02:35 AM
|
1
|
2
|
2443
|
POST
|
Hi, I am currently creating a custom toolbox which will run a script to append tables and feature classes from one personal geodatabase to another. Abit of background about these personal GDBs; they all have the exact same format in terms of the number of feature classes and tables, their objects names and the structure/type of tables/feature classes. You could think of these personal GDBs as regional databases. What I need to do is merge several of these GDBs into one GDB. What I am currently unsure about how to code is I want to create a python script to automate this process (which working on one GDB at a time is fine), specifically to run through multiple GDBs at a time. So in my script I have a variable (Import_SIMCAT) which holds a list of the GDBs selected to be appended to, and I have a variable (Export_SIMCAT) which holds the GDBs being appended from. To make things less straight forward, I have a varying number of GDBs being appended/merged together, so one GDB may have only one other GDB being appended to it while another may have 5 GDBs being appended to it. The question I have is how in my script can I get my code to identify which GDBs need to be appended to which? For example, lets say that I have 10 GDBs being appended to 4 GDBs. In the variable Import_SIMCAT I would have GDBs A,B,C,D while in variable Export_SIMCAT I would have GDBs E,F,G,H,I,J,K,L,M,N. I would want GDB E,F and G to be appended to GDB A, while GDB H to be appended to GDB B, while GDBs I,J,K and L to be appended to GDB C and finally GDBs M and N to be appended to GDB D. I dont know if it is possible to make it so that the user can identify which GDBs are getting appended to which. At the moment I only know how to loop through the selected GDBs by using their index position within the list variable they are stored in. But that process doesnt work when I have different number of GDBs being appended. I hope that makes sence. If it helps I can put a copy of my current script on here but as it currently stands it is very unformed and only creates variables for the two different parameters, splits them up into lists and removes the unwanted single quotes. Thanks in advance for any help and advice anyone can provide on this topic. Ben.
... View more
12-16-2015
02:13 AM
|
0
|
1
|
2999
|
POST
|
Thank you both for your helpful advice. Stripping the single quotes worked a treat. Your help is much appreciated.
... View more
12-15-2015
12:48 AM
|
1
|
0
|
781
|
POST
|
Hi, I have a custom toolbox which I added a python script too. The script currently runs when the input parameters are not multivalue, but the script falls over when I set the input parameters to multivalue. Where they seem to be falling over is when I try to use pyodbc to connect to an access database. I am currently using the arcpy.GetParameterAsText function and then using the split function to separate the semicolon delimited string into a list. This is the error information that I am currently receiving. Error Info: <class 'pyodbc.Error'>: ('HY000', "[HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044) (SQLDriverConnect); [01000] [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x1200 Thread 0x128c DBC 0x24d28a4 Jet'. (1); [01000] [Microsoft][ODBC Microsoft Access Driver]General Warning Unable to open registry key 'Temporary (volatile) Jet DSN for process 0x1200 Thread 0x128c DBC 0x24d28a4 Jet'. (1); [HY000] [Microsoft][ODBC Microsoft Access Driver] Not a valid file name. (-1044)") A snippet of my code: import arcpy
import pyodbc
import sys
import os
import pythonaddins
SAGIS_Input = arcpy.GetParameterAsText(0)
SAGIS_model_new = SAGIS_Input.split(";")
SAGIS_Count = len(SAGIS_model_new)
arcpy.AddMessage(SAGIS_Count)
for model in SAGIS_model_new:
SAGIS_model = str(model)
arcpy.AddMessage(SAGIS_model)
# connection to SAGIS model geodatabase
access_conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+SAGIS_model)
access_cursor = access_conn.cursor()
tablelist = arcpy.ListTables()
tablecount = len(tablelist)
arcpy.AddMessage(tablecount)
arcpy.AddMessage("Script run successfully.")
#print "Script run successful."
access_cursor.close()
access_conn.close() I would very much appreciate any advise on how to get the muiltvalue paramters to work with the pyodbc connection. Thanks in advance. Ben.
... View more
12-14-2015
09:09 AM
|
0
|
3
|
3775
|
POST
|
The fields in question are definately using the Yes/No datatype. I can easily change the fields to display Yes/No instead of -1/0 or any of the other boolean codes but I am hoping to find a way of coding this manual step into my script. Its just on less manual step for the users to deal with.
... View more
12-08-2015
01:08 AM
|
0
|
0
|
1465
|
POST
|
Yes, my python addin is calling my custom toolbox which contains this script. Its being called from a toolbar button. The input for the tool is the SAGIS_model_new variable which allows the user to select the geodatabase. This is providing a list of selected geodatabase paths which the script is working from. This script will eventually run these processes and more on multiple geodatabases. The other arc tools which I have used in my full script have run correctly (e.g. AddGeometryAttributes, CreateTable and CreateFeatureclass). Does that answer your question?
... View more
12-07-2015
09:17 AM
|
0
|
0
|
570
|
POST
|
it needs to be displayed as Yes/No. I am trying to recreate the table the same as in databases that already work. They will be put through a software which may specifically look for Yes/No in these fields. I am not exactly sure what the software looks for so I am having to replicate the tables with the exact same format. I can easily change the format from the default Access boolean (-1/0) to Yes/No but I was hoping that there was a way of coding it so I dont have to do this manual step every time I want to create this database.
... View more
12-07-2015
09:08 AM
|
0
|
1
|
1465
|
POST
|
Hi, I have a python addin which is running a custom toolbox. Part of the python script linked to the toolbox is suppose to use the arcpy.MakeXYEventLayer_management tool to create a point feature class from a table in my personal geodatabase. The problem I am having is that it keeps coming up with the error saying that the dataset does not exist or is not supported (below). When I do the same process manually it works fine and the MakeXYEventLayer tool creates the point feature class. I am not sure why it is unable to detect the database table. ERROR 000732: XY Table: Dataset D:\SAGIS Conversion\SAGIS Models Test\Model_2_Wick River_T1 - Copy (17)\SAGIS_Wick_River_2.mdb\SimWaterBodiesT1 does not exist or is not supported Failed to execute (MakeXYEventLayer). Here is a snippet of my code: import arcpy
import os
import sys
SAGIS_model_new = [arcpy.GetParameterAsText(0)]
model_pos = 0
for model in SAGIS_model_new:
featureList = arcpy.ListFeatureClasses()
if "SimWaterBodiesCent" in featureList:
arcpy.AddMessage("SimWaterBodiesCent feature class already exists within " + Model_Name)
else:
SimWaterBodies = os.path.join(SAGIS_model_new[model_pos], "SimWaterBodies")
SimWaterBodiesT1 = os.path.join(SAGIS_model_new[model_pos], "SimWaterBodiesT1")
x_coords = "CentroidX"
y_coords = "CentroidY"
out_Layer = "SimWaterBodiesCent"
spatial_reference = arcpy.Describe(SimWaterBodies).spatialReference
arcpy.MakeXYEventLayer_management(SimWaterBodiesT1, x_coords, y_coords, out_Layer, spatial_reference, "")
arcpy.FeatureClassToFeatureClass_conversion(out_Layer, simcat, "SimWaterBodiesCent")
model_pos = model_pos +1 Can someone help me work out why this error message is persisting: Thanks in advance for any help. Ben.
... View more
12-07-2015
08:52 AM
|
0
|
4
|
3217
|
POST
|
Hi, In my python script I have some code which, using a SQL statement copies a table from one Access database to another. In the original database there are several fields which are Yes/No fields. The problem I am having is that when I copy over the table to the new database these fields revert to Access's default boolean code (-1/0). I know how to manually change the fields format in Access but I am struggling to work out how to do it from my python script. I need to get these fields back to displaying Yes/No. I copy the table across using the """SELECT * INTO (table name) IN (new database) FROM (table name) IN (original database)""". I have tried using the FORMAT(table name,'Yes/No') clause in SELECT statements, ALTER TABLE statements and UPDATE statements but with no luck. At this point I am not too sure what I am suppose to do. It is most likely that I am doing something very obvious wrong but I am clueless as to what it is. Thanks in advance for any help, Ben. This is a snippet of my current script: import os
import sys
import arcpy
import pyodbc
common_db_new = [arcpy.GetParameterAsText(0)]
direc = os.path.dirname(__file__)
Broom_db = direc + "\\River_Broom_126.mdb"
Broom_common = direc + "\\River_Broom_126_CommonTables2k.mdb"
Broom_conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+Broom_common)
Broom_cursor = Broom_conn.cursor()
common_conn = pyodbc.connect('DRIVER={Microsoft Access Driver (*.mdb)};DBQ='+common_db_new[0])
common_cursor = common_conn.cursor()
SQL = """SELECT * INTO DeterminandsForSimcat IN '{0}'
FROM DeterminandsForSimcat IN '{1}'""".format(common_db_new[0], Broom_common)
common_cursor.execute(SQL)
common_cursor.commit()
SQL = """SELECT Include
FORMAT(Include,'Yes/No')
FROM DeterminandsForSimcat"""
common_cursor.execute(SQL)
common_cursor.commit()
common_cursor.close()
common_conn.close()
Broom_cursor.close()
Broom_conn.close()
... View more
12-04-2015
05:19 AM
|
0
|
8
|
4596
|
POST
|
Hi, I have a toolbox script which appends data from a personal geodatabase to an Oracle database. I want to include a check to see if the data being imported from the personal gdb is not already in the Oracle database.I have a field (MODELNAME) which is in both the personal gdb table which the data is being appended from and the Oracle table where the data is being appended to. In the gdb the there is only one model name in that field. I want to check if the model name from the gdb already exists in the MODELNAME field in the Oracle database. Here is where I get stuck. I know what I want to do, I just dont know how to do it. I am assuming that I need to use a SQL statement from this. Something like "SELECT * FROM SAGIS_REACH_NETWORK AS r WHERE r.MODELNAME = SimReaches.MODELNAME". I was thinking of doing a count of the number of rows where the model name in the Oracle table match the gdb table. This is what I have so far: model_list = [arcpy.GetParameterAsText(0)]
if model_list != None:
# Only run script if atleast one model is selected i.e. model_list is not empty
try:
if arcpy.ProductInfo() == "ArcInfo" or "ArcEditor":
# Parameters
# Personal Geodatabase we are importing into
outmodel = "Database Connections\\simcatmaster@G01L.sde"
# List tuples with feature classes and tables that we want to import, and their output name in Oracle
# e.g[(in_name,out_name)]
tables = []
tables.append(('\\simcat\\SimReaches','\\simcatmaster.SAGIS_REACH_NETWORK'))
today = datetime.today()
# connect to oracle
oracle_conn = pyodbc.connect("DSN=ORACLE_SIMCAT_x86")
oracle_cursor = oracle_conn.cursor()
# Find the total count of models (geodatabases) selected
modelListLen = len(model_list)
# Declaring the first model position within the list of models selected (model_list)
modelPos = 0
for model in model_list:
# Check if the model selected has already been imported to SAGIS_REACH_NETWORK
SQL = "SELECT * FROM SAGIS_REACH_NETWORK AS r WHERE r.MODELNAME = {0}.MODELNAME;".format(tables[0])
oracle_cursor.execute(SQL).fetchall()
SQLCount = len(oracle_cursor)
print SQLCount Does anyone have any advice as to how I could do this? Thanks in advance for any help, Ben.
... View more
11-26-2015
02:28 AM
|
0
|
3
|
3335
|
POST
|
Hi, I am trying to build a python toolbox which is called from a python addin toolbar button in ArcMap. At the moment I am just trying to test the python toolbox to get it to work from the toolbar button. The problem I am currently having is that everytime I press the toolbar button ArcMap closed down/crashes with nothing else, such as an error message appearing.Below I have the code that I am currently using. Toolbar Script: import arcpy
import pythonaddins
import os
import sys
class AppendModelsOracle(object):
"""Implementation for Append_Models_Oracle.button (Button)"""
def __init__(self):
self.enabled = True
self.checked = False
def onClick(self):
# Toolbox name
toolboxName = "Toolbox"
# Name of tool to be executed
toolName = "Tool"
# Create string with path to toolbox
relPath = os.path.dirname(__file__)
pyt = relPath + os.sep + toolboxName + ".pyt"
# Call geoprocessing tool
pythonaddins.GPToolDialog(pyt, toolName)
pass Python Toolbox Script: import arcpy
import pythonaddins
import os
import sys
class Toolbox(object):
def __init__(self):
"""Define the toolbox (the name of the toolbox is the name of the
.pyt file)."""
self.label = "Toolbox"
self.alias = ""
# List of tool classes associated with this toolbox
self.tools = [Tool]
class Tool(object):
def __init__(self):
"""Define the tool (tool name is the name of the class)."""
self.label = "Tool"
self.description = ""
self.canRunInBackground = False
def getParameterInfo(self):
"""Define parameter definitions"""
model_list = arcpy.Parameter(
displayName="Input GDB",
name="in_gdb",
datatype="DEWorkspace",
parameterType="Required",
direction="Input",
multiValue="Yes")
model_list.filter.type = "Workspace"
model_list.filter.list = ["Local Database"]
return [model_list]
def isLicensed(self):
"""Set whether tool is licensed to execute."""
return True
def updateParameters(self, parameters):
"""Modify the values and properties of parameters before internal
validation is performed. This method is called whenever a parameter
has been changed."""
return
def updateMessages(self, parameters):
"""Modify the messages created by internal validation for each tool
parameter. This method is called after internal validation."""
return
def execute(self, parameters, messages):
"""The source code of the tool."""
model_list_len = len(model_list)
model_list_pos = 0
model_count = 1
for model in model_list:
msg1 = ("\nFirst model in list of selected models is: {0}".format(os.path.basename(model)))
msg2 = ("\n{0} out of {1} models identified.".format(model_list_pos, model_list_len))
arcpy.AddMessage(msg1 + msg2)
model_list_pos = model_list_pos + 1
arcpy.AddMessage(model_list_pos)
model_count = model_count + 1
arcpy.AddMessage(os.path.basename(model))
arcpy.AddMessage("\nAll models identified." + "\nTest Successful.")
pythonaddins.MessageBox("Bloody well work.","Test box 2",0)
return Can anyone see a reason why my toolbar and/or toolbox would be causing ArcMap to shut down? Thanks in advance for any help, Ben.
... View more
11-24-2015
02:54 AM
|
0
|
2
|
4002
|
POST
|
Hi, I am in the process of converting a python script into a python toolbox. The input for my toolbox is either one or more personal geodatabases. Data from these geodatabases is then appended to an Oracle database. The question I have is I am unsure what data type I am suppose to use for my input. I have not seen anything that jumps out at me as the correct data type to use for selecting geodatabases. The only one that I thought might be correct is the 'Database Connection' data type. Could someone please clarify which data type I should be selecting for this input parameter? Thanks in advance for any help. Ben.
... View more
11-23-2015
03:15 AM
|
0
|
1
|
3453
|
POST
|
Thanks for that answer. Am I understanding it correctly that the arcpy.SetProgress function has to be run through a geoprocessing toolbox? I have tried including it in my python script, the script still runs fine but the progress dialog does not appear. The same happens when I run the progress dialog code through the python window. Would this mean that the only way for me to get the arcpy.SetProgress function to work with my script is to transfer my script into a toolbox and then call the toolbox using the arcpy.GPToolDialog function in my python addin? If this is the case is it possible to store this toolbox within the Install folder of the python addin? I am thinking purely about ease of sharing this python addin. Thanks again for your help, this arcpy.SetProgress function seems like the best chance I have of creating such a progress dialog.
... View more
11-18-2015
02:52 AM
|
0
|
2
|
1618
|
Title | Kudos | Posted |
---|---|---|
1 | 06-28-2016 02:35 AM | |
1 | 06-28-2016 10:23 AM | |
1 | 12-15-2015 12:48 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|