|
POST
|
Question...why would I have to create a table in memory... If I have a table in SQL Server. Ok. As long as it is in a Geodatabase. From, http://webhelp.esri.com/arcgiSDEsktop/9.3/index.cfm?TopicName=Geocode_Addresses_%28Geocoding%29 "The input address table can be any format supported by ArcGIS including INFO, dBASE, and geodatabase tables" So for my implementation, that Oracle data/table is not registered with ArcSDE or in any supported format (it's just a non-spatial table that resides outside of any GIS infrastructure). This means that I have to transform it into that supported format and I assumed you needed to do the same because in your OP you mention: "...I have a stand alone table in SQL server."
... View more
10-10-2012
07:22 AM
|
0
|
0
|
1913
|
|
POST
|
THanks for your reply THe SQL connection see very famililar to others so I dont think that is going to be much of a problem. ON the other hand creating an in memory table and then Geocoding to that and then using that to update the original SQL table....not getting my brain around that one....can you explain more...are there examples for this in moemory table creation..and then how wold I apply that table to the SQL Table? Thanks EDIT: 1. Are you saying to create a table like in your second link with the values from the SQL Server table. 2. Geocode against this table creating an output Feature Class 3. Then copy over the XY from the new Feature Class to the Original Table in SQL Server 4. Then Delete the Created table and Feature Class I was mainly pointing out ways to acquire the SQL server data, but yes you could populate a temporary table or an in_memory table with those rows and Geocode from this. You'll have to deal with the field mapping (depending upon the database, it may not map directly to the temp table you need to create) --- here's how I deal with a cursor from an Oracle table (sorry for formatting issues. it doesn't paste well into the editor here and python needs good formatting!):
gp.createtable_management("IN_MEMORY", "TempDT", "", "")
cxRows = cursor.fetchall()
rowcount = cursor.rowcount
for row in range(1, rowcount - 1):
tables = gp.ListTables()
for tbl in tables:
if tbl=="TempDT":
### add the fields
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)
### now populate the table
insRows = gp.InsertCursor(tblNew)
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()
db.close()
***The above are snippets pulled from a larger def() so it may not work directly and require you to modify for your needs. It is intended to be a general outline/view as to how I go from Oracle table to in_memory table. Good luck!
... View more
10-10-2012
06:05 AM
|
0
|
0
|
1913
|
|
POST
|
Although in my Case I would have to point to a SQL table, how different is the syntax for a SQL table versus an Access Database jay, Use pyodbc or pymssql libaries to make the connections to your SQL Server http://sourceforge.net/projects/pyodbc/ http://pymssql.sourceforge.net/examples_pymssql.php I'd also say you could probably just populate an in_memory table to geocode from.
... View more
10-10-2012
04:08 AM
|
0
|
0
|
1913
|
|
POST
|
You can edit an Excel spreadsheet, but it will have to be done with another Py lib that is capable of such a thing. A quick search on Stackexchange turns up a lot of solutions, maybe have a look at http://pypi.python.org/pypi/xlrd Just fyi: I have had a lot of success implementing additional libaries like this. cx_Oracle python lib has been a great tool to integrate non-spatial data that is maintained in our Oracle database(s)! Good luck!
... View more
10-10-2012
03:47 AM
|
0
|
0
|
1414
|
|
POST
|
That looks like a display issue. Check the resampling on each in the layer properties. I bet one is nearest neighbor (the blocky one), and one is bilinear. Another way to see if you got different answers is to just subtract one from the other. You should get all zero's. Best, Eric Eric, Thanks for your input. I did check the resampling property and you were correct that it was set differently for the output generated by the Python code. Although I am not sure this was the complete reason for my issue --- the cell size @528 was ok in the SA tool but when I changed the cell size to 50 (from 528) in the Python script and it generated a much closer representation of what gets built by the SA defaults. Basically, I just set the Semivariogram model to Linear (as needed) and the new cell size:
gp.Kriging_sa(inputFeatureDataset, attributeName, outputRaster, "Linear", "50.00995", "VARIABLE 12", Output_variance_of_prediction_raster)
Thanks a bunch for your help!
... View more
10-09-2012
08:00 AM
|
0
|
0
|
1482
|
|
POST
|
[ATTACH=CONFIG]18288[/ATTACH] [ATTACH=CONFIG]18289[/ATTACH] Images attached to show differences I am seeing. First image Krige was run from SA toolbar. Second image is from Python code.
... View more
10-09-2012
07:04 AM
|
0
|
0
|
1482
|
|
POST
|
ArcGIS 9.3.1 Python 2.5 I am getting differences in raster outputs when a point layer is run thru Kriging process via the Spatial Analyst toolbar/extension and when run in code (Python 2.5). I am wondering if there are some default values the SA tool uses when no values are present in the dialog. There are only 2 inputs I am attempting: Semivariogram model: Ordinary/Linear and Output Cell Size: 528 (the Lag size gets set to this as well). Everything remains the same in the Python code I am using but the output raster is MUCH smoother than the output generated by the Python code. Even after reclassifying the output raster, it is still very coarse in comparison to the output (temporary) raster that gets generated by the SA tool. Any input is much appreciated!
def genContourKRIG(inPTS, zfld):
try:
# Set the output workspace name
path = oLoc #os.path.expanduser("~")
gp.Workspace = path
rastername = str(gp.GetParameter(1))
gp.overwriteoutput = 1
# Set the input feature dataset
inputFeatureDataset = inPTS
# Set the output raster name
if rastername !="":
outputRaster = rastername
else:
outputRaster = "Krig_1"
# Don't write out the variance raster
Output_variance_of_prediction_raster = ""
# Set the output extent
desc = gp.describe(inPTS)
xmin = 877223.554167 #desc.Extent.XMin #hard-coded for now
ymin = 368517.887500 #desc.Extent.YMin #hard-coded for now
xmax = 877223.554167 #desc.Extent.XMax #hard-coded for now
ymax = 368517.887500 #desc.Extent.YMax #hard-coded for now
gp.Extent = "877223.554167 368517.887500 877223.554167 368517.887500" #hard-coded for now
# Set the attribute field
attributeName = zfld
# Check out Spatial Analyst extension license
gp.CheckOutExtension("Spatial")
# Process: Kriging...
gp.Kriging_sa(inputFeatureDataset, attributeName, outputRaster, "Linear", "528", "VARIABLE 12", Output_variance_of_prediction_raster)
except:
# If an error occurred while running a tool, then print the messages
gp.AddMessage(gp.GetMessages())
... View more
10-09-2012
03:16 AM
|
0
|
3
|
2086
|
|
POST
|
You should mark your own post as the answer. It makes it easier for someone looking for the correct answer to find your post. When doing a search, you're returned a list of threads, with the answered ones marked by a green "A". Wouldn't you look at those threads first? Okay will do... Done!
... View more
10-04-2012
11:47 AM
|
0
|
0
|
1102
|
|
POST
|
Not going to mark my own post as the answer, but should someone need to do this the solution is to use the TableView and FeatureLayer object instead of the objects themselves (from what I can tell anyway). tab = "IN_MEMORY\TempDT" gp.MakeFeatureLayer_management (fc, "pointFC") ### convert the FC memtabname = "inmemtab" gp.MakeTableView_management("IN_MEMORY\TempDT", memtabname) ### convert the in_memory table gp.AddJoin_management("pointFC", "STATION", memtabname, "gis_station", "KEEP_ALL") if gp.Exists(tmpLayer): gp.Delete_management(tmpLayer) gp.CopyFeatures_management("pointFC", tmpLayer) (tmpLayer is a .shp file that I save to the user's local drive and tab was generated by filling a cursor from a cx_Oracle.connect call)
... View more
10-04-2012
10:56 AM
|
0
|
0
|
1102
|
|
POST
|
ArcGIS 9.3.1 Python 2.5 I have a "IN_MEMORY" table verified by reviewing the gp.messaging: newrows = gp.searchcursor("IN_MEMORY\TempDT") newrow = newrows.next() while newrow: gp.AddMessage("Inserted: " + str(newrow.gis_station) + ", " + str(newrow.station) + ", " + str(newrow.sample_date) newrow = newrows.next() Now I'd like to join this with a FeatureClass in a PGDB. I suppose that I will then have to issue a copyfeatures_management in order to see the result? I really have no idea how else to see the joined FC in ArcMap. Anyway, there is no error, but the output doesn't inlcude the joined fields either so any help is appreciated: tab = "IN_MEMORY\TempDT" memtabname = "inmemtab" gp.MakeTableView_management(tab, memtabname) gp.AddJoin_management(memtabname, "gis_station", fc, "STATION", "KEEP_ALL") gp.copyfeatures_management(fc, tempFC)
... View more
10-04-2012
07:56 AM
|
0
|
3
|
1718
|
|
POST
|
Py is case sensitive so "Int" should be "int". Then in your 2 calculation statements you a have mismatch in the brackets. Have you tried testing this in the python ide directly. Cheers, N Thank you, Neil. I simply needed to change Int to int. Jumping from C#.NET/VB.NET to Python (I am new to Python) and creating Geoprocessing objects has been interesting. Simple things can really trip you up and seem to be quite difficult to pickup for some reason! Thanks again.
... View more
09-27-2012
05:30 AM
|
0
|
0
|
908
|
|
POST
|
ArcGIS 9.3.1 I am attempting to calculate a field with a specific formula, which actually works correctly when I plug it into the FieldCalculator in ArcGIS 9.3.1 --- however, I am getting a different result when I place the formula into a Python script. edit: "fff" is just a field that holds an incremental value starting at 1. This works in the Field Calculator: 40 - (Int(( [fff] - 1) / 35) + 1) + 1 My attempt to calc the field in the script is like: rowsr = gp.UpdateCursor(outLabelsFC) rowr = rowsr.Next() i = 1 while row: rowr.setvalue("row", (40 - ((rowr.fff - 1) / 35) + 1) + 1) rowsr.updateRow(rowr) i = i + 1 rowr = rowsr.Next() Python doesn't like the "Int", so I have tried: 40 - ((rowr.fff - 1) / 35) + 1) + 1 and... 40 - (long((rowr.fff - 1) / 35)) + 1) + 1 Both of the above generate a different result from run in the field calculator. Can you help explain why or what I am missing here? Thanks!
... View more
09-27-2012
04:41 AM
|
0
|
2
|
1447
|
|
POST
|
Thanks for your ideas and input! I came up with formulas for a field calculation process, so not sure how they will relate to looping over rows with an .UpdateCursor --- which I may end up having to use some of your approach below. Also: the calcs can start at the Y-Axis cell or the Origin cell depending upon how the actual formula is written. Thanks again and I will keep this thread updated with progress. j Here is an example of some code that I got to work after running the Fishnet tool. I created a two new fields called 'ROW' and 'COLUMN_' and then used the following functions to update them: fc = "fishnet"
def updateROW(x, y, z, n):
while x <= 25:
rows = arcpy.UpdateCursor(fc)
for row in rows:
if row.OID == x and x > y and x <= z:
row.ROW = n
x += 1
rows.updateRow(row)
else:
y += 5
z += 5
n += 1
row.ROW = n
x += 1
rows.updateRow(row)
def updateCOLUMN():
x = 1
n = 1
while x <= 25:
rows = arcpy.UpdateCursor(fc)
y = x
for row in rows:
if row.OID == y and y <= 25 and n < 6:
row.COLUMN_ = n
y += 5
rows.updateRow(row)
x += 1
n += 1
updateROW(1, 0, 5, 1)
updateCOLUMN() You will need to update some of the variables depending on the size of your Fishnet. The above example is executed on a 5x5 fishnet. For the updateROW function, the 'while' loop is the total number of polygons, and the 'y' and 'z' increment values are based on the number of rows. For the updateCOLUMN function, the 'while' loop is the total number of polygons, the 'y' variable in the 'if' statement is the total number of polygons, 'n < 6' represents one less the number of columns, and the 'y' variable is incremented by the number of columns. The only problem with the above code is that it starts at the bottom left corner of the fishnet feature class rather than the top left. You would need to populate a field with values of the OID field in descending value, then use that field in the function. I have not thoroughly tested this, and there is a probably a more elegant way to do this, but this may help you get started.
... View more
09-25-2012
11:30 AM
|
0
|
0
|
3025
|
|
POST
|
I think a change in approach is needed as this whole selecting by location of polygon extents is very messy. Not saying it is not a viable way to go about it, and I will most certainly be able to utilize much of the code I have developed to this point, but this is just a complex way to go about things that calls for much simpler tactics. New thinking is to implement similar functionality as found in the Fishnet Tool but extend it a bit to inlcude some additional automation (populate the Grid cells as we need them to be from my OP). Invoking LABELS, adding row/col columns, calculating these columns with fairly simple formulas and then populating a polygon FC with the values will work just fine and much more efficiently.
... View more
09-25-2012
10:57 AM
|
0
|
0
|
3025
|
|
POST
|
Hi James, How was the polygon GRID created? Did you use the 'Create Fishnet' tool in ArcToolbox? If not, is there an ObjectID that increments from left to right? And, is there an equal amount of rows and columns? Hi Jake -- I *can* build the GRID with the Fishnet tool/toolbox. Yes, there is an objectID, but I may or may not increment in that manner. (some polygon layer(s) to be used as input may have been built with Arc/Info fishnet and generate as coverages. But I am attempting to come up with a solution that can be done with existing ArcGIS 9.x and 10.x Toobox tools and custom tools --- however it needs to be is fine with me. What I have so far is a messy method of clumisly grabbing Y-Axis to select the upper left polygon, then stores an point for the upper-right and lower-left of this polygon. Then I can move right from the upper-right point (doing a select by location) and move down to the next row using the lower-left point (doing a select by location). Again -- it's very clumsy and I still have not figured out the exact loop process/requirement. Any additional input is appreciated!
... View more
09-24-2012
12:45 PM
|
0
|
0
|
3025
|
| 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
|