POST
|
Hi Anne, Indeed you spatial reference is not defined correctly. Change: spref = 4326 ... into: spref = arcpy.SpatialReference(4326) This creates an actual spatial reference object from the WKID. In case the tables contain the same attributes and represent different contiguous areas, it will be better to merge the points together before you perform the interpolation. Interpolation is, as the name suggests, not an extrapolation. This means that the values at the borders of the raster resulting from the interpolation will not be very reliable. Another thing I notice in your code is the line: out_layer = "F:/work/python" This line of code is pointing to a folder, which in this case is the same folder as the folder that holds the tables. Instead of a folder you should provide a name here, like for instance "measurements". The layer created by this tool is temporary and resides in memory. Within the loop (for tbl in tables) the arcpy.CopyFeatures_management should be executed. This will require a location and name of the output featureclass to be created. Let's assume you would have an input folder with tables and an output folder to store the featureclass. Your code could like something like this: import arcpy, os
from arcpy import env
ws_in = "F:/work/python" # could use arcpy.GetParameterAsText(0)
ws_out = "F:/work/python/output" # could use arcpy.GetParameterAsText(1)
env.workspace = ws_in
tables = arcpy.ListTables()
xc = "long"
yc = "lat"
spref = arcpy.SpatialReference(4326)
XYeventname = "measurements"
for tbl in tables:
arcpy.MakeXYEventLayer_management(tbl, xc, yc, XYeventname, spref)
# assuming you have DBF tables, strip the extension:
fclass = os.path.join(ws_out, tbl.strip(".dbf"))
# make the featureclass
arcpy.CopyFeatures_management(XYeventname, fclass) In the code for each table an XY event layer is created in memory. It will be named "measurements" and this layer is overwritten with each table. Using the os module the output workspace "ws_out" is joined with the table name, although in this case the ".dbf" is stripped from the name. The resulting variable "fclass" contains the path and name to the featureclass to be created. Using the copy features tool, the layer is written to a featureclass. What is important here, is that the variable "fclass" defined what type of output is written. If it references to a name in a folder , it will be a shapefile, but if you are pointing to a name in a file geodatabase, it will create a featureclass in a geodatabase. The reason for not using the same input and output folder, is that a shapefile is created with the same name as the (DBF) table. However, a shapefile consists of a DBF file as well to store the attributes. If you would write the shapefile with the same table name to the same input folder you would get some nasty errors. Another thing is the attached Excel file. If you would work on this it would change things a bit, since when working with Excel files, the Excel file itself is the workspace and worksheets or named data ranges will be the tables. Kind regards, Xander
... View more
02-19-2014
12:27 PM
|
0
|
0
|
1594
|
POST
|
Although I don't think this has anything to do with arcpy / ArcGIS, there is a module you could load called calendar: import calendar
print calendar.month(2014,2) results in: February 2014 Mo Tu We Th Fr Sa Su 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 sorry, but the formatting changes the output. So I added an image: [ATTACH=CONFIG]31572[/ATTACH] See for more functionality: http://docs.python.org/2.7/library/calendar.html?highlight=calendar#calendar Kind regards, Xander
... View more
02-19-2014
02:29 AM
|
0
|
0
|
1232
|
POST
|
Hi Amy, I think this will do the job: import arcpy, os # access your table(s) intbl = r'C:\path\to\your\FileGeodatabase.gdb\inputtable' outtbl = r'C:\path\to\your\FileGeodatabase.gdb\outputtable' # optionally create output table, using the input table as schema # CreateTable_management (out_path, out_name, {template}, {config_keyword}) outpath, outname = os.path.split(outtbl) arcpy.CreateTable_management(outpath, outname, intbl) # have a close look at the fieldnames, some names may be restricted # and are changed by ArcGIS when imported from for instance Excel flds = ['number','Code','Year'] # do a search cursor on the input table and an insert cursor on the output table outcurs = arcpy.da.InsertCursor(outtbl, flds) with arcpy.da.SearchCursor(intbl, flds) as incurs: for row in incurs: numbers = row[0].split(',') for number in numbers: # for each 'number' a record is written outcurs.insertRow((number.strip(), row[1], row[2])) del outcurs Kind regards, Xander
... View more
02-19-2014
02:11 AM
|
0
|
0
|
2053
|
POST
|
Hi Anne, Good for you that want to understand the Python code that solves your problem. In order to give you some pointers, it is necessary to know a little more: what version of ArcGIS are you using? do you have any programming knowledge? About Python In case you don't have (much) experience with Python, consider the next resources: The thread below provides some useful links to resources: http://forums.arcgis.com/threads/96424-Learning-Python A good way to start can be using the Python window in ArcGIS, since you obtain context sensitive Help. Also after you manually execute a ArcGIS tool, you can use the option Copy as Python Snippet in the Results window. When working with looping through feature classes and tables, have a look at cursors (especially the data access cursors): Accessing data using cursors And you can follow free courses online at Esri: http://training.esri.com/gateway/index.cfm?fa=search.results&searchterm=python Depending on your knowledge and needs, there are many options. Also the Forums are a very useful resource. Always look at the posts by jscheirer (Jason Scheirer). He is on the Python team at Esri and also posts on: http://arcpy.wordpress.com/ I heard about the book "Programming ArcGIS 10.1 with Python" which appears to be a good resource, and there will be a new one "Mastering Python Programming for ArcGIS". About your question I assume your post in this threads is related to what you are asking here: http://forums.arcgis.com/threads/69130-ArcGIS10.0-PythonWindow-Make-XY-Event-Layer-.csv-amp-WGS-1984-Errors-000622-amp-000628?p=366433&viewfull=1#post366433 From this thread I extracted that in your workspace you have a number of DBF tables: AB10_.dbf, AB11_.dbf, AB15_.dbf, CFHMS_.dbf, CFMHN_.dbf, FA_.dbf, HSFHome_.dbf, HSFVAN_.dbf, KF18_.dbf, KF1W_.dbf, LASA_.dbf, MB_HAck_.dbf, PCM10_.dbf, PMB28_.dbf, pmc9_.dbf, SHROCK_.dbf, simo09_.dbf, SIMO94_.dbf, SP150_.dbf, sp42_.dbf, T13East_.dbf, T13West_.dbf, TB53_.dbf, TB63_.dbf, WSFBOW_.dbf, WSFDALLAS_.dbf I assume they all have the the same coordinate fields: "Lat" and "long". Please note that in your code in the other thread you assign the Lat to x and Long to y (it should be the other way around!). After converting the DBF's to shapefiles, you want to perform inverse distance weighted interpolation on each attribute. What I don't completely understand is whether you want to merge all the tables together first, or whether for each table/shapefile and attribute the IDW should be performed. Main question here is what you want to do with the rasters that result from the operation. Looking at the table names, it seems that each table covers a different area. Is that right? In that case merging the features would be an option, but if you want to do that, you will have to look at the schema's of the tables (do they have the same fields?). If the schema's are different, you will probably have to use cursors and more programming to do that or some nasty field mapping. I could advise you on that, but will need to have a look at the data first. I don't know if that's an option for you... Please note that looping through each field of a shapefile to perform the IDW will result in more rasters then you want, since your lat and long fields will also be used. You will have to include some more intelligence to do this right. Let me know if I can help you. Kind regards, Xander
... View more
02-18-2014
03:48 AM
|
0
|
0
|
1594
|
POST
|
Hi Anne, The "Error 000622" is referring to invalid parameters for the tool. In this case due to the fact that you specify the list of tables in the MakeXYEventLayer tool, rather than the table itself. Please observe the code below: tables = arcpy.ListTables()
for tbl in tables:
arcpy.MakeXYEventLayer_management(tbl, xc, yc, out_layer, spRef)
"tables" is a variable with the list of tables found in the current workspace then you do a for loop, accessing each table "tbl" in the list "tables" specify the variable "tbl" (the single table) to be used in the MakeXYEventLayer tool Another thing to remember is that you use your latitude as X-coord and you Longitude as Y-coord. This should be the other way around: xc = "long"
yc = "Lat" Kind regards, Xander
... View more
02-18-2014
03:12 AM
|
0
|
0
|
562
|
POST
|
Hi Justyna, I suppose you used the Focal Statistics tool and switched the option "Ignore NoData" on, right? This is OK. What you need to realize though, is that pixels that have NoData value in your input raster, but have Data cells in their direct vicinity will receive a value too. To set these pixels to NoData again, you can you the Con Tool (Spatial Analyst\Conditional\Con). Use your input raster (first image in your post) from the previous step as conditional raster, leave the expression blank, use the focal statistics raster as "true raster" and leave the "false raster" empty. This will set the pixels outside the area to NoData. Kind regards, Xander
... View more
02-06-2014
07:01 AM
|
0
|
0
|
675
|
POST
|
Hi Adriane, That is a pretty large raster; about 63% of the earths circumference... I'm kinda curious; what type of raster data is this, how large is it (several TBs?), and more importantly why do you want to do this? In general it is a lot easier to project the vector data (shapefile) to the projected coordinate system van the raster. If you project a raster you will probably apply some resampling and create a second dataset (which, depending of the cell size, will probably be huge too). Kind regards, Xander
... View more
02-06-2014
06:16 AM
|
0
|
0
|
303
|
POST
|
Hi Marianne, What you could also try is to use the properties of the data you're accessing. So read the "lengthFieldName" properties after doing a describe on your data: desc = arcpy.Describe(inFeatures)
fldLength = desc.lengthFieldName
Next, construct the expression. Make use of "AddFieldDelimiters" which will add the appropriate field delimiter if necessary: minLength = 300
expression = "{0} < {1}".format(arcpy.AddFieldDelimiters(inFeatures, fldLength), minLength)
In my (non-versioned) SDE the expression will be: "Shape.len" < 300 In a FGDB it will be: Shape_Length < 300 Then continue with the UpdateCursor: fields = ['OID@', 'SHAPE@', 'GM_LABEL', 'GM_USER_DEF']
uCursor = arcpy.da.UpdateCursor(inFeatures, fields, expression) Kind regards, Xander
... View more
02-06-2014
05:45 AM
|
0
|
0
|
545
|
POST
|
Hi David, You're nearly there... I guess the problem is that the row you write should have the same dimensions as the row you read. I renamed the x_shift and y_shift variables to x_new and y_new for readability. I didn't test this, but if I think this could work. import arcpy
fc = r'c:\yourFGDB.gdb\yourLines'
# update cursor (be careful with this and try it on a copy of your data)
fields = ["SHAPE@","XCentroid","YCentroid"]
with arcpy.da.UpdateCursor(fc,fields) as curs:
for row in curs:
geom = row[0]
x_new = row[1]
y_new = row[2]
array = arcpy.Array()
for part in geom:
lastpnt = part[len(part) - 1]
lastpnt.X = x_new
lastpnt.Y = y_new
part[len(part) - 1] = lastpnt
array.add(part)
curs.updateRow([arcpy.Polyline(array), x_new, y_new]) Kind regards, Xander
... View more
02-05-2014
04:30 AM
|
0
|
0
|
1649
|
POST
|
Hi Malcolm, Your second statement using the IsNull tool treats the NoData cells appropriately. NoData is handled differently by many tools, and normally results in NoData in your output. So although you think the Con statement results in either True or False, it also has a hidden case NoData. I recommend you to read the Help Topic on "NoData and how it affects analysis" which explains this behavior. Kind regards, Xander
... View more
02-05-2014
12:05 AM
|
0
|
0
|
664
|
POST
|
Yes you can. Just follow these steps: Convert you TIN to raster (use an appropriate cell size) Convert you building shapefile to raster (use the height as value, and the same cell size) Combine both rasters using a CON statement (Spatial Analyst) Convert the resulting raster to ASCII grid Kind regards, Xander
... View more
02-04-2014
11:52 PM
|
0
|
0
|
1686
|
POST
|
Hi Ananya, Tip 1:specify a workspace without trailing slashes: replace: inputPath = "F:\\GIS\\_Projects\\NPMRDS\\GDB\\NHS_npmrds_2013.gdb\\" by: inputPath = "F:\\GIS\\_Projects\\NPMRDS\\GDB\\NHS_npmrds_2013.gdb" Tip 2: It is better to use os.path.join to join a location and a name: Add this to the beginning of the script: import os and change your code to: inputTable = os.path.join(inputPath, speedTable) (this should give the same result as you already had) Do the same for inputFC, tmpQueryTable, QueryTableFeatureClass: inputFC = os.path.join(inputPath, featureClass)
tmpQueryTable = os.path.join(inputPath, "QueryTable")
QueryTableFeatureClass = os.path.join(inputPath, "copyFeatures") Tip 3: your fieldList contains objects and not the fully qualified field names. In order to get this right, the easiest way would be to execute the tool manually. See instructions here: http://resources.arcgis.com/en/help/main/10.2/index.html#//00170000006r000000 After a successful run, open the "Results" window and right click on the successfully executed tool. This will reveal the option "Copy as Python Snippet". Now you are able to paste the python code to your Python IDE and examine what the content of each parameter has been. Adapt you script to create the same type of parameters. Tip 4: expression is not valid The expression uses names of variables, but should use the content of the variables. Use this instead and verify if you need to use fully qualified names in the expression. expression = "{0} = {1}".format(tmc1, tmc4) this would yield: "NHS_tmc = tmc" Kind regards, Xander
... View more
02-04-2014
11:22 PM
|
0
|
0
|
405
|
POST
|
Hi David, Try the code below on a copy of your data and see if this is what you want. import arcpy fc = r'c:\yourFGDB.gdb\yourLines' x_shift = 5 y_shift = 5 # update cursor (be careful with this and try it on a copy of your data) fields = ["SHAPE@"] with arcpy.da.UpdateCursor(fc,fields) as curs: for row in curs: geom = row[0] array = arcpy.Array() for part in geom: lastpnt = part[len(part) - 1] lastpnt.X += x_shift lastpnt.Y += y_shift part[len(part) - 1] = lastpnt array.add(part) curs.updateRow([arcpy.Polyline(array)]) Kind regards, Xander
... View more
02-04-2014
10:07 PM
|
0
|
0
|
1649
|
POST
|
Hi Todd, Sounds to me that that's the way to go. You should have a look to what distance of the edge the distortion is present and let that define the amount of overlap. Good luck, hope it works... Kind regards, Xander
... View more
01-20-2014
06:07 AM
|
0
|
0
|
630
|
POST
|
Hi Mary, Imagine a graduate slope in an near flat area (the green line in the attached image). When translating this data to integer, it will create a "jump" at an elevation of 0.5 (see blue dashed line); all decimal values from 0 to 0.5 will be 0 and all values from 0.5 to 1 will be 1. At this "jump" location, the slope will be high, while the rest of the slope will be 0. [ATTACH=CONFIG]30267[/ATTACH] Kind regards, Xander
... View more
01-05-2014
09:23 PM
|
0
|
0
|
1798
|
Title | Kudos | Posted |
---|---|---|
1 | 01-21-2020 07:21 AM | |
2 | 01-30-2020 12:46 PM | |
1 | 05-30-2019 08:24 AM | |
1 | 05-29-2019 02:45 PM | |
1 | 10-18-2024 12:14 PM |
Online Status |
Online
|
Date Last Visited |
3 weeks ago
|