|
POST
|
Curious... Do you have any imports of 3rd party modules in the script? Perhaps one that attempts to load needed .dll's to function? EDIT: I just remembered something from some of my ArcObjects/.NET development work where I had some bottleneck issues when doing spatial selections/spatial relationship analysis. The solution was to be absolute certain that the participating spatial data sets were in the same projection/coordinate system. Not saying definitively this is the cause of your issue, but perhaps something to double-check.
... View more
11-21-2012
02:51 AM
|
0
|
0
|
2156
|
|
POST
|
Start here: http://code.google.com/p/pyodbc/ You'll have to download and install pyodbc, make sure you get the version that matches the python version you have installed, most likely the version that installed with ArcGIS. ########### import arcpy, pyodbc cnxn = DRIVER={SQL Server};SERVER=cloak;DATABASE=test;UID=user;PWD=password cursor = cnxn.cursor() cursor.execute("{any legal SQL stmt you would execute in SSMS}") cnxn.commit() ########### I use it to get the functionality out of ArcGIS and the speed of SQL. Have you or others experienced issues of secondary runs when pyodbc is run from ArcGIS/ArcCatalog(9.3.1) Toolbox? I get a 9999998 Error when the script/tool with pyodbc is run a second time. note: I don't have this issue with cx_Oracle. Just exploring alternative ways to connect to non-spatial data repositories.
... View more
11-20-2012
06:13 AM
|
0
|
0
|
4733
|
|
POST
|
Hi there Stacy, I'm mainly replying here so that I am subscribed to this thread, but also uncover possible alternatives (for me) as other comments come in as I am new to Python development. Plus I will likely need to implement the code example you've provided! I've actually had a run-in with the locking issue, but was able to mitigate (actually, eliminate) the problem by reading/writing intermediate data to the IN_MEMORY space, then move that processed data to it's final location(s) in their relevent workspaces and repositories (PGDB and FDGB's). I am wondering, is there something in your application architecture that is limiting your ability to utilize this IN_MEMORY space to read/write intermediate data? Is the IN_MEMORY space inadequate for some reason (eg, the data is simply too large)? The multiprocessing requirements do not allow for the use of the IN_MEMORY space? Anyway -- great topic and useful code. Take Care, j
... View more
11-20-2012
03:29 AM
|
0
|
0
|
7036
|
|
POST
|
Hi all I've built a model in model builder (9.2) and need to export the resulting output shape files into a Geodatabase within the same directory. Normally I would use the 'Feature class to Geodatabase' tool within model builder however there are different output shape files created each time I run the model therefore conventional tools are not apopropriate. I'm fairly new to Python and need the barebones of a script that will cut shapefiles from a directory into my Geodatabase. Thanks, Tom Quickly put together, but it worked for me (ArcGIS 9.3.1). import arcgisscripting gp = arcgisscripting.create() inputLocation = "C:\shps" gp.Workspace = inputLocation fcs = gp.ListFeatureClasses() fcs.reset() fc = fcs.next() while fc: ### to work with a File GDB, then use the .gdb extension gp.FeatureClasstoGeodatabase(fc, inputLocation + "\\testFGDB.gdb") ### to work with a Personal GDB, then use the .mdb file extension instead gp.FeatureClasstoGeodatabase(fc, inputLocation + "\\testPGDB.mdb") gp.AddMessage(str(fc) + " loaded into GDB") fc = fcs.next()
... View more
11-19-2012
02:57 AM
|
0
|
0
|
961
|
|
POST
|
I have a base "fishnet" polygon grid. I attempted to create a model that iterates over each cell in that base fishnet grid and subdivide that cell with the Create Fishnet tool into a new feature class. I expected that I simply would need to set the output from my iterate feature iterator as the 'Template Extent' parameter for the Create Fishnet tool. However, while I can see the name of this iterator output model variable in the drop-down list for the 'Template Extent' parameter; the name does not have the blue Model Variable icon. And more importantly, the template extent does not update at each model iteration. Is there a way that I can make my model recognize aan iteration output as a template extent? ( see screenshot below) [ATTACH=CONFIG]19323[/ATTACH] Mark, I know you are looking for a model solution here, but can you implement this with just straight-up Python code? I had a need for doing this same thing and came up with the code below (it is pulled from a larger script/process, but I peiced it together as best I could and it does work on a 9x9 grid example). You will need to alter the inputLocation and inputFC variables, add the cellHeight and Width you want the output grids to be and it should just work. also: this is for ArcGIS 9.3.1, but again it should just work in newer versions.
import arcgisscripting
gp = arcgisscripting.create(9.3)
#you will need to modify these two parameters for your situation. This is an ex of a pgdb FeatureClass
inputLocation = "\\\\C:\Scratch.mdb"
inputFC = inputLocation + "\\exGRID"
# Open a search cursor on a feature class
rows = gp.searchcursor(inputFC)
row = rows.Next()
i = 1
while row:
gp.AddMessage("Attempting to process polgyon " + str(i))
#Get the shape field
shape = row.shape
#Get the extent object
extent = shape.extent
outputName = "Fishnet_" + str(i)
outFC = inputLocation + "\\" + outputName
#Get the origin (lowerLeft) and y-axis (upperLeft) properties of the polygon
ll = extent.lowerleft
ul = extent.upperleft
ur = extent.upperright
originXY = str(ll.x) + " " + str(ll.y)
yaxisXY = str(ul.x) + " " + str(ul.y)
opp_corner = str(ur.x) + " " + str(ur.y)
gp.AddMessage("LowerLeft (x,y): %f, %f" % (ll.x, ll.y))
gp.AddMessage("UpperLeft (x,y): %f, %f" % (ul.x, ul.y))
gp.AddMessage("XMin: %f" % (extent.xmin))
gp.AddMessage("YMin: %f" % (extent.ymin))
gp.AddMessage("XMax: %f" % (extent.xmax))
gp.AddMessage("YMax: %f" % (extent.ymax))
#keep the cell width/height set to zero as it will use the opp_corner to figure it out
cellWidth = 0
cellHeight = 0
#plug in the #rows/#cols you want the output grids to contain
nrows = 10
ncols = 10
gp.CreateFishnet_management(outFC, originXY, yaxisXY, cellWidth, cellHeight, nrows, ncols, opp_corner)
gp.AddMessage("Created " + outputName)
i = i + 1
row = rows.Next()
... View more
11-16-2012
04:43 AM
|
0
|
0
|
1030
|
|
POST
|
James, That did it! Thank you so much! Darina Excellent!
... View more
11-02-2012
07:54 AM
|
0
|
0
|
1646
|
|
POST
|
Have you tried an explicit conversion from numeric type to float? (I could be mistaken on this, but aren't Python "Double" types actually "Float"?). Anyway, try something like this: # convert the sqlserver type from numeric to float arcpyRow.XCoord = float(row.XCoord) # or maybe attempt to use a variable if the above fails xval = float(row.XCoord) arcpyRow.XCoord = xval
... View more
11-02-2012
04:15 AM
|
0
|
0
|
1646
|
|
POST
|
Maybe something like this... (completely untested)
txtList = arcpy.ListFiles("*" + fileSuffix)
for file in txtList:
newFile = os.path.splitext(file)[0] + ".txt"
###...or maybe?
newFile = str(os.path.splitext(file)[0]) + ".txt"
... View more
10-24-2012
11:57 AM
|
0
|
0
|
1565
|
|
POST
|
and I haven't even figured out how to get the file name stripped of the suffix. You could use a variation of this in your loop to strip the extension off the file name...
import os
NameMinusExt = os.path.splitext("TheFileName.gnd")[0]
## the result would be: TheFileName
... View more
10-24-2012
11:48 AM
|
0
|
0
|
1565
|
|
POST
|
Thanks for the reply James. I don't think it's user permissions since I'm able to select from the problem table in SQLDeveloper. If I view the GRANTS in SQLDeveloper for a problem table and one that I'm able to see in arcpy, there is no difference in the grants. (There actually aren't any at all for either table, but that could be not because they're not there, but because of what my login ID has permission to view). I just downloaded cx_Oracle and may take the same tack. If you have any code to share, I'd be most grateful. Sorry for the late reply. Here is some code (THIS IS FOR arcgisscripting(9.3)!!!!) snippet from a larger codebase I have implemented. It may not work if directly plopped into your codebase, you'll have to go thru it carefully --- also, if you have additional fields to map, you will have to add them (this ex only shows string, float and datetime conversion from Ora to ArcGIS). But it is fairly straight forward. (not sure how well this gets formatted as a forum posting, so you might have to clean things up a bit!) Lots of examples out there too, it's not necessarily a "GIS" thing! Here's the reference base: http://cx-oracle.sourceforge.net/html/module.html
### create the temporary table
gp.createtable_management("IN_MEMORY", "TempDT", "", "")
### Build a DSN (can be subsitited for a TNS name)
dsn = cx_Oracle.makedsn("servername", service_name, "database")
oradb = cx_Oracle.connect("user", "password", dsn)
cursor = oradb.cursor()
### Build the SQL statement and execute it on the cursor object
cursor.execute("""SELECT field1, field2
FROM table1
WHERE table1.field1 = somevalue""")
### locate the temporary table we just created and use the results
### of the cursor to contsruct it's structure
tables = gp.ListTables()
for tbl in tables:
if tbl=="TempDT":
for i in range(0, len(cursor.description)):
val1 = str(cursor.description[0])
val2 = str(cursor.description[1])
val3 = str(cursor.description[2])
if val2=="<type 'cx_Oracle.STRING'>":
fldType = "Text"
val3 = cursor.description[2]
gp.AddField(tbl, str(cursor.description[0]), fldType, val3)
if val2=="<type 'cx_Oracle.NATIVE_FLOAT'>":
fldType = "Float"
gp.AddField(tbl, str(cursor.description[0]), fldType)
if val2=="<type 'cx_Oracle.DATETIME'>":
fldType = "Date"
gp.AddField(tbl, str(cursor.description[0]), fldType)
### populate the in_memory table we just constructed from the cx_Oracle cursor
tables = gp.ListTables()
for tblNew in tables:
if tblNew=="TempDT":
### now populate the table
insRows = gp.InsertCursor(tblNew)
cxRows = cursor.fetchall()
for cxRow in cxRows:
insRow = insRows.newRow()
for i in range(0, len(cursor.description)):
insRow.setvalue(str(cursor.description[0]), cxRow)
insRows.insertRow(insRow)
cursor.close()
oradb.close()
... View more
10-24-2012
03:54 AM
|
0
|
0
|
4264
|
|
POST
|
I am having a very similar but subtly different issue: I have an OLE DB connection to an Oracle 11g database using ArcGIS v10 SP2 and python v2.6. I can connect to the database and when I set my arcpy.env.workspace and list the tables, I can see all tables in the entire database. But arcpy.Exists(table) works for some tables and not others. And of course for the one table I'm interested in, it doesn't work. The table I'm interested in is in the schema for the user that the OLE DB connection uses ("survey"). Here's the code: import sys, string, arcpy
from arcpy import env
import traceback
arcpy.env.overwriteOutput = True
arcpy.env.workspace = "C:/Temp/My_DB_Connection.odc"
tableList = arcpy.ListTables()
for table in tableList:
print table # <-- WORKS
if not arcpy.Exists("C:/Temp/My_DB_Connection.odc/SURVEY.CONTROL"):
print "table does NOT exist"
else:
print "Oracle table exists" Prints "table does NOT exist". Also note that when I connect to the DB in ArcCatalog using the same exact connection file, I can see all tables in the DB (not just SURVEY tables, but I do see them all). Perhaps it is a permissions issue for those tables? Not sure exactly if that is your problem, but you may want to check with the Oracle DBA the permissions for the login you are using and the tables you are expecting to see. I get weird results too (ArcGIS 9.3.1) when simply adding an OLE DB conn to an 11g Ora db: some tables/views can be dropped into ArcMap, others cannot (even though I can see them in ArcCatalog). To get around this issue I opted to nix the OleDb connection stuff and pass in SQL statements directly into the database and return just the results I want via cx_Oracle library. Of course this now means I have to go thru the effort to convert the result into something that is ArcGIS friendly (a fairly simple, but limited, field mapping and conversion to an IN_MEMORY table).
... View more
10-23-2012
04:37 AM
|
0
|
0
|
4264
|
|
POST
|
See: http://stackoverflow.com/questions/1711408/help-installing-cx-oracle
... View more
10-15-2012
04:01 AM
|
0
|
0
|
639
|
|
POST
|
So I suppose that this is just the product of the Kriging process itself. Perhaps I am expecting something more along the lines of what IDW would produce. I guess my issues is more about not being certain when and why to apply a certain interpolation over another.
... View more
10-11-2012
07:35 AM
|
0
|
0
|
1157
|
|
POST
|
In the attached image it shows a raster output result of a Kriging. My focus is on the point near the center of the White color cells that is labeled with 7010 (this is the field/value used to Krig). But if you look at the graduated symbology in the TOC it shows the range as 4509.779643 - 5448.454102 [ATTACH=CONFIG]18363[/ATTACH] Why is this? I am expecting the Max to be 7010 (I know this is the highest value found in the point FC). Also, why is the Min value = -535.5955811? I am expecting this to be the lowest value found in the point FC. Sorry for my inexperience with this subject, I am charged with applying some programmatic automation and doing what I can to educate myself on the subject. Thanks!
... View more
10-11-2012
07:12 AM
|
0
|
4
|
2321
|
| 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
|