|
POST
|
There's also another similar thread on this topic from yesterday too: http://forums.arcgis.com/threads/103648-Scratch-Workspace Some good info in there.
... View more
02-28-2014
04:03 AM
|
0
|
0
|
4968
|
|
POST
|
Isn't the scratch.gdb designed to *always* be available and *guaranteed* to exist? If so, why attempt to delete it (if that's even possible)? Edit: Also, the suggested "clean up" is not saying to delete the .gdb or the workspace. Rather it is saying, delete the contents of the .gbd: http://resources.arcgis.com/en/help/main/10.1/index.html#//00570000006w000000
import arcpy
import os
inFC = arcpy.GetParameterAsText(0)
tempFC = arcpy.env.scratchGDB + os.path.sep + "tempFC"
arcpy.CopyFeatures_management(inFC, tempFC)
# Do some work here...
# Clean up when done...
#
arcpy.Delete_management(tempFC)
Why not use the "in_memory" workspace instead?
... View more
02-28-2014
03:30 AM
|
0
|
0
|
4968
|
|
POST
|
Anyway if Python does it that is nice, but only about 20 people on this forum could have come up with that solution. I demand solutions from ESRI that are designed for non-programmers to do a basic operation like data conversion involving a recasting of a field. Resorting to Python as the only option is unacceptably unfriendly from my perspective. Field mapping is always a tough bug 🙂 In any event, I think your demand is not that...well.... demanding.
... View more
02-27-2014
03:18 AM
|
0
|
0
|
502
|
|
POST
|
Why is Python needed at all to create a new feature class/table that converts the field types? As long as you are disconnecting from the source data why not just use the Feature Class to Feature Class tool or the Table to Table tool? They can alter the field map type of the coordinate fields from string to double and output a new FC/table and perform the desired conversion directly to the new output. It is only if you want to use the original source and maintain a connection to it that you have to look for alternatives outside of ArcMap. For those you need to set up the on the fly conversion on the server side. From what I understand, the data source is a non-spatial table in an Oracle database. I am not exactly sure how to use the Feature Class to Feature Class tool in this instance as the source is simply attributes not registerd with any SDE. Also, from the docs, http://resources.arcgis.com/en/help/main/10.1/index.html#//001200000027000000 the Table to Table conversion input data types does not seem have an Oracle table as an option either. The OP is going to have to perform some way to connect and query the data source, then create some mechanism that will transform the result to an output format desired or needed (my example shows that it will be saved as a GDB table).
... View more
02-27-2014
02:28 AM
|
0
|
0
|
2171
|
|
POST
|
This is one option using python script (not a model) and the cx_Oracle library. This would allow you to put the CAST from string to numeric of your x_coord/y_coord fields in the Oracle db. The basic idea is to fill a cursor with the results of the SQL, append those cursor rows to a new array/list, covert the list to a NumPy array and finally convert that to a FeatureClass. This example is pulled from an implementation I have that does something similar but you will have to straighten out the SQL for your needs and it will not work if you just copy/paste, but it should get you close to what you want I think. Hope this helps!
import arcpy
import cx_Oracle
import numpy as np
### Build a DSN (can be subsitited for a TNS name)
dsn = cx_Oracle.makedsn(param1, param2, param3)
oradb = cx_Oracle.connect("username", "password", dsn)
cursor = oradb.cursor()
sqlQry = """SELECT MyTableOrView.SomeField1 AS SomeTEXTField,
CAST(TO_CHAR(MyTableOrView.x_coords, 'fm9999999.90') AS FLOAT) AS x_coords,
CAST(TO_CHAR(MyTableOrView.y_coords, 'fm9999999.90') AS FLOAT) AS y_coords
FROM MyTableOrView"""
cursor.execute(sqlQry)
datArray = []
cxRows = cursor.fetchall()
for cxRow in cxRows:
datArray.append(cxRow)
#close the conn to ora
cursor.close()
oradb.close()
del cxRows, cursor
numpyarr_out = np.array(datArray, np.dtype([('SomeTEXTField', '|S25'), ('x_coords', '<f8'), ('y_coords', '<f8')]))
#convert the numpyarray to a gdb feature class
outFC = r'C:\MyGDB\xyPoints_FromStrings
if arcpy.Exists(outFC):
arcpy.Delete_management(outFC)
arcpy.da.NumPyArrayToFeatureClass(numpyarr_out, outFC, ("x_coords", "y_coords"))
Even better code that elimiates the "datArray" construction as it is not needed. Just use the cxRows list as-is! (I need go back and update some things now -- sometimes posting on these threads makes you re-evaluate things!)
import arcpy
import cx_Oracle
import numpy as np
### Build a DSN (can be subsitited for a TNS name)
dsn = cx_Oracle.makedsn(param1, param2, param3)
oradb = cx_Oracle.connect("username", "password", dsn)
cursor = oradb.cursor()
sqlQry = """SELECT MyTableOrView.SomeField1 AS SomeTEXTField,
CAST(TO_CHAR(MyTableOrView.x_coords, 'fm9999999.90') AS FLOAT) AS x_coords,
CAST(TO_CHAR(MyTableOrView.y_coords, 'fm9999999.90') AS FLOAT) AS y_coords
FROM MyTableOrView"""
cursor.execute(sqlQry)
datArray = []
cxRows = cursor.fetchall()
#close the conn to ora
cursor.close()
oradb.close()
del cursor
numpyarr_out = np.array(cxRows, np.dtype([('SomeTEXTField', '|S25'), ('x_coords', '<f8'), ('y_coords', '<f8')]))
#convert the numpyarray to a gdb feature class
outFC = r'C:\MyGDB\xyPoints_FromStrings
if arcpy.Exists(outFC):
arcpy.Delete_management(outFC)
arcpy.da.NumPyArrayToFeatureClass(numpyarr_out, outFC, ("x_coords", "y_coords"))
... View more
02-26-2014
07:08 AM
|
0
|
0
|
2171
|
|
POST
|
jamesfreddyc after adding the quote i ran and the script. I get no error but now the points are not being populated anymore...? Python window >>>
completed in 0.05 secs.
>>>
completed in 0.03 secs.
>>>
completed in 0.07 secs.
>>>
completed in 0.04 secs.
>>>
completed in 0.08 secs.
If you believe the Timer code is causing this, then remove it. It's just a suggestion to determine the processing time for things, and it seems to work for you now, but I am not sure how it could cause other code to no longer work.
... View more
02-25-2014
10:39 AM
|
0
|
0
|
2671
|
|
POST
|
mzcoyle i did import the time model but i got the following error, File "C:\Users\talmeida\AppData\Local\ESRI\Desktop10.1\AssemblyCache\{BB229966-100D-4482-A3FE-B298BD262597}\AddPoints_addin.py", line 65
timetest = completed in %.02f secs." % (t.interval)
^
SyntaxError: invalid syntax I am not understand how to emplement the second arcpy.da.searchCursor with the spatial join. Sorry python newbie here. gabrisch i will look into 64-bit background geoprocessing. You are missing the quote at the begining: timetest = "completed in %.02f secs." % (t.interval)
... View more
02-25-2014
10:01 AM
|
0
|
0
|
2671
|
|
POST
|
When confronted with performance issues, I like to implement timers along the way at various processing points to get a good idea of where bottlenecks are occuring. You do get fancy with it, or just put in print statements strategically and run a stopwatch to see where things slow down. Use the in_memory workspace where possible: typically I see 1/2 the time to process things there compared to disk reads/writes. Here's a time class you can use. Put it at the very top of your script:
class Timer:
def __enter__(self):
self.start = time.clock()
return self
def __exit__(self, *args):
self.end = time.clock()
self.interval = self.end - self.start
Usage:
t = Timer()
with t:
CC_list.sort()
AddressID = CC_list[-1] + 1
AddressID = 'CC' + str(AddressID)
row_values = [(x, y, (x, y), AddressID)]
cursor = arcpy.da.InsertCursor(fc, ["X_Coord", "Y_Coord", "SHAPE@XY", "ADDRESSID"])
for row in row_values:
cursor.insertRow(row)
del cursor
# Stop the edit operation.
edit.stopOperation()
# Stop the edit session and save the changes
edit.stopEditing(True)
timetest = completed in %.02f secs." % (t.interval)
print timetest
... View more
02-25-2014
06:32 AM
|
0
|
0
|
2671
|
|
POST
|
Apologies, I should have included that info. as it is important; I'm using the Make Query Table tool. That's my bad. Missed it. Well... I wonder if you can perform the conversion directly in the SQL as part of the MakeQueryLayer_management implementation. I will hunt around to see if there are examples. My thought is, can you issue a "CAST" or "TO_NUMBER" statement in the sql somewhere? Edit: I noticed that you are attempting to implement MakeQueryTable! Man, that stuff just looks messy. If it were me, I'd go towards python script and implement the cx_Oracle library --- you have so much more control. I know that is outside of the bounds for your OP and sorry I don't have a good solution other than this. BUT, the cx_Oracle lib is very awesome 🙂
... View more
02-25-2014
05:46 AM
|
0
|
0
|
2601
|
|
POST
|
Unfortunately this isn't an option as it is an third party application database. Any tampering would breach our support agreement 😞 How exactly are you "sucking in" the Oracle data as you mentioned in your OP?
... View more
02-25-2014
05:39 AM
|
0
|
0
|
2601
|
|
POST
|
Fix the database, it's that important. I just see no value in doing gymnastics to wrestle things that should be modeled for what they are at the database tier. If it's a date, store it as such. Decimals, floats, integers? Then that's what they are period. Get with the database admin, and make it right. You will save yourself tons of headaches, not just in the immediate, but long-term life-cycles of the tools and applications you build will be better off.
... View more
02-25-2014
05:33 AM
|
0
|
0
|
2601
|
|
POST
|
I am not able to set a workspace to an .mdb in my quick testing.
... View more
02-20-2014
10:13 AM
|
0
|
0
|
1528
|
|
POST
|
Okay, but what is the input table that you dropped into ArcMap and you want to convert to a .dbf file?
... View more
02-20-2014
09:40 AM
|
0
|
0
|
1528
|
|
POST
|
The table I want to output to DBF is inside a .mxd file, but this script doesn't seem to require an input file, only a directory. The table name is "AJD_rate". Where am I going wrong? TIA The example shows you how to convert a list of GDB tables ("inTables"). They are setting the workspace then just specifying the names of the tables inside of that geodatabase ("workspace") to output .dbf files to that output folder. The question is, what is your input table? Saying "the table in a .mxd file" is not enough. What is it? Where is it? etc...
... View more
02-20-2014
09:17 AM
|
0
|
0
|
1528
|
|
POST
|
Thanks for checking, but yes. It's .xls. I copied and pasted the path straight from Catalogue. The other weird anamolay is that, I can write the script through the python shell, line for line adn then it will work. When I do it from the pything window as a script, it throws that same error all the time. Maybe related to 64-bit processing? Have a look at the .xls/.xlsx reference in this: http://resources.arcgis.com/en/help/main/10.1/index.html#//002100000040000000 Sorry for such abstract answers, I find this topic entirely confusing and have not had to deal with these issues as of yet.
... View more
02-20-2014
06:41 AM
|
0
|
0
|
1113
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-17-2020 10:47 AM | |
| 1 | 10-25-2022 11:46 AM | |
| 1 | 08-08-2022 01:40 PM | |
| 1 | 02-15-2019 08:21 AM | |
| 2 | 08-14-2023 07:14 AM |
| Online Status |
Offline
|
| Date Last Visited |
01-22-2025
02:28 PM
|