|
POST
|
I am a beginner to Python in ArcGIS and would like to perform a calculation on a raster that's a bit complicated than what Raster Calculator can do. I know the python code for my expression, so I thought I could do a simple function in Raster Calculator (e.g Multiply by 2.0) and then see the python code for that, and modify as required. Can I do this, and if so, how can I get to see the python script involved in this? Thanks in advance Hi Michael, Yes you can. Below you see a visual explanation of how it's done: [ATTACH=CONFIG]28638[/ATTACH] You execute your simple Raster Calculator expression. After execution you can open the Results window (Geoprocessing menu, Results). When you right click on the Raster Calculator a menu appears where you can select the option "Copy As Python Snippet". This gives you the Python code. You can change this and for instance execute the new statement from the Python window. Now here's why you shouldn't do that: If you look at the syntax there are a lot of quotes (three at the start, three at the end of the expression and around each raster). This makes the statement more complex than actually needed. The same thing goes for using the field calculator, which makes an expression a lot more complex that simply using a cursor to update a field (just have a look at all the threads discussing the proper syntax for field calculator)... You can also do this in a more simplistic way, all from Python. In this case I assume all the rasters you need are in the TOC, you have Spatial Analyst extension switched on, your environment setting are all set and you will work with the Python window. Enter the following code: import arcpy
myInputRaster = arcpy.Raster("theNameOfMyRasterInTheTOC")
myResult = myInputRaster * 2
myResult.save("theNameOfMyOutputRaster") With this code you: import the arcpy library you define a raster object based on the name or your raster in the TOC "theNameOfMyRasterInTheTOC" You calculate the result (change the expression) you save the resulting raster with the name "theNameOfMyOutputRaster" to you current workspace You could actually use the tool "Times" to multiply by 2: arcpy.sa.Times("theNameOfMyRasterInTheTOC",2) ... but that will make complex expressions more complex to write. That's why I recommend you to use "arcpy.Raster()" to create a raster object, which enables you to use "+,-,/,*" etc If you want to share the expression you wish to execute I can give it a look and provide you with a small Python snippet. Kind regards, Xander
... View more
10-27-2013
11:56 PM
|
0
|
0
|
680
|
|
POST
|
Hi, Not sure what you exactly want: merge cells together so that for instance Cel A1 and B1 apear as a single cell? or combine data into 1 field. Considering the first option, I really don't know. If this is not something you can define in your report layout file, then you would have to dig into the Excel model and program it. In case you just want to concatenate data from 2 (or more) fields into 1 field, you can prepare the data itself (add a column and use the field calculator) or do this in your report layout file. Merge data together in Report Layout On the right side of the screen you will see "Fields" and below that "Calculated" Right click on Calculated and choose "Add": [ATTACH=CONFIG]28566[/ATTACH] Your field will be named "Field1" In the properties specify a formula like: myFieldName1 + " - " + myFieldName2 [ATTACH=CONFIG]28567[/ATTACH] Reference your new (calculated) field "Field1" in your report designer [ATTACH=CONFIG]28568[/ATTACH] Hope this works for you. Kind regards, Xander
... View more
10-24-2013
04:47 AM
|
0
|
0
|
825
|
|
POST
|
"Feature attachments" is the new feature from ArcGIS 10 on wards. How to extract feature attachments and save to disk using Python? Hi, In this blogpost (please read): http://anothergisblog.blogspot.nl/2012/06/working-with-blob-data-at-101-arcpyda.html ... a nice example is included of how to read attachments: from arcpy import da
import os
with da.SearchCursor(r"c:\temp\demo.gdb\table",['blobFieldname','fileName']) as cursor:
for row in cursor:
binaryRep = row[0]
fileName = row[1]
# save to disk
open(r"c:\saveFolder" + os.sep + fileName, 'wb').write(binaryRep.tobytes())
del row
del binaryRep
del fileName You can find more on Cursor and blob fields (scroll down to end of page) through this link: http://resources.arcgis.com/en/help/main/10.2/index.html#//002z0000001q000000 Kind regards, Xander
... View more
10-24-2013
04:29 AM
|
0
|
0
|
3899
|
|
POST
|
I am planning to work with the Solar Radiation modeling tools over a large area from Virginia to North Carolina. One of the required inputs to the Area and Point tools is "Latitude". The tool sets this value automatically based on the input raster. However, it seems that if the study area is as large as mine then using one value is not appropriate. Will I need to break the study region up into sections and mosaic them back together? If so, it seems that the sections would need to overlap so that the edges are modeled accurately. Any advice on how to handle solar radiation modeling across a large study area would be very helpful. Hi Todd, It seems that the tool has not been designed to work with large variations in Latitude. The Help on "Area Solar Radiation (Spatial Analyst)" states: The analysis is designed only for local landscape scales, so it is generally acceptable to use one latitude value for the whole DEM. With larger datasets, such as for states, countries, or continents, the insolation results will differ significantly at different latitudes (greater than 1 degree). To analyze broader geographic regions, it is necessary to divide the study area into zones with different latitudes. In your case the Latitude varies several degrees (from 39.466133 to 33.842074). If you look at a tool like the Clear Day Solar Radiation calculator (www.ksre.ksu.edu/irrigate/Software/CDRCalc.xls�??) you can derive that the effect of the Latitude on clear day solar radiation will be about 2% in the summer, but rises to 28% in winter time! Taking a central Latitude will still give results that are 12-13% off at the Northern and Southern edges (in the winter). In this case splitting the area up in horizontal slices (<1 degree Latitude) and scripting the analysis (Python) in which you provide for each "slice" the central Latitude of that slice would probable provide the best result. Kind regards, Xander
... View more
10-23-2013
11:33 PM
|
0
|
0
|
712
|
|
POST
|
Hi Dan (and Dan), Both Combine and Zonal Statistics (as table) will get you there. With the Combine option you can convert the result to Excel and make a pivot table. I think the easiest way is to use the "Zonal Statistics as Table (Spatial Analyst)" as Dan first suggested. You will have to use your hydrology raster as dataset that defines the zones and your canopy polygons (converted from polygons to raster) as your value raster. The result will give you all the statistics you need: The COUNT will give you the area of each zone (if you multiply it be cell size) The SUM will give you the number of pixels with canopy per zone MEAN * 100 (or SUM / COUNT * 100) will give you the percentage of canopy per hydrology value Some considerations: If the zone input is a raster dataset (which it is), it must have an attribute table. This means it has to be of type Integer (cannot be Float). The attribute table is usually created automatically for integer rasters, but may not be under certain circumstances. You can use "Build Raster Attribute Table" to create one. You can also Reclassify your hydrology values into meaningful classes and use those classes as zones. Kind regards, Xander
... View more
10-23-2013
11:03 PM
|
0
|
0
|
3343
|
|
POST
|
Any thoughts?? Hi Kevin, I had a closer look at the script, and noticed you changed a few things. The line: lstRstr = ' ' should be: lstRstr = '' You initially set the variable to single space, when it should be an empty string. Later the code checks for an empty string and will not find it. This causes the list of rasters to contain a "space" for the first raster name. The line: arcpy.Clip_management(raster, "#", "wse_grid", FP_Poly, "0", "ClippingGeometry") should be: arcpy.Clip_management(raster, "#", wse_grid, FP_Poly, "0", "ClippingGeometry") In this case the output raster will have a unique name for each raster and not always "wse_grid". The line: arcpy.MosaicToNewRaster_management(lstRstr, Input_Model,"wse_100_Yr"," ", "32_BIT_FLOAT", "3", "1", "MAXIUM", "FIRST") should be: arcpy.MosaicToNewRaster_management(lstRstr, Input_Model,"wse_100_Yr"," ", "32_BIT_FLOAT", "3", "1", "MAXIMUM", "FIRST") The provided mosaic_method was not valid due to typo. I also notice that you blanked the output coordinate system. This may not be a problem if you environment settings are correct. Try again and see what happens. Kind regards, Xander
... View more
10-22-2013
06:38 AM
|
0
|
0
|
2350
|
|
POST
|
I did not use proportional symbols because I wanted to be able to make the layer transparent. Is there a way to make a layer with proportional symbols transparent? Hi Elizabeth, A layer with proportional symbols, just like a layer with symbols with an applied size by attribute can be drawn transparently (see the transparent setting on the Display tab of your layer properties). However, there will be no transparency between point symbols when symbols overlap (those symbols should be in different layers to draw transparently on top of each other). I looked at the "How to apply size to point feature symbology" option and noticed that the point size will be stretched between the values in your attribute field, applying a point size of approximately 42 to the highest value. Kind regards, Xander
... View more
10-21-2013
09:57 PM
|
0
|
0
|
737
|
|
POST
|
Hi Marcin, Sorry, my bad. I had an error in the code. The line that states: with arcpy.da.SearchCursor(fc, fields) as cursor: ... should actually be: with arcpy.da.SearchCursor(tbl, fields) as cursor: In many samples "fc" is used as variable to refer to a featureclass and I forgot to change it to "tbl". Kind regards, Xander
... View more
10-21-2013
12:19 PM
|
0
|
0
|
2266
|
|
POST
|
I am displaying my county data (no. of cases) by finding the mean center of each county and displaying the mean center point as a single symbol by my chosen value. (Properties, Symbology, Advanced, Size, Size points by value x). How is the size or area of the circle calculated? Is my value the radius or diameter? I have chosen to display by this method so I can use transparency. Thank you very much Hi Elizabeth, If you want to give a meaningful size to your symbols you can better use the proportional symbols: [ATTACH=CONFIG]28486[/ATTACH] In this case you can define exactly what the size represents. You can find more explanation here: Using proportional symbols Kind regards, Xander
... View more
10-20-2013
11:30 PM
|
0
|
0
|
737
|
|
POST
|
Hello, I'm looking for the easiest way to multiply raster by the table records. Here's what I mean in details: I have: 1) raster (DEM) - further called as "input_DEM" 2) specified numeric values stored in a table in 1 column - further called as "value_from_n_row", where 'n' is the row number I need to create a few new rasters by this way: "input_DEM" * "value_from_1_row" = "output_raster_1" "input_DEM" * "value_from_2_row" = "output_raster_2" "input_DEM" * "value_from_3_row" = "output_raster_3" etc. If there's a way to do this automatically? Sorry if my question is trivial, but I didn't found any solution yet. Thanks for any support! 🙂 Hi Marcin, There is standard tool that does the job. It is however pretty straight forward to do this in Python. See the code snippet below: import arcpy import os dem = arcpy.Raster('Input_DEM') tbl = 'YourTableName' fldName = 'YourFieldName' outFolder = r'c:\folder\subfolder' fields = [fldName] cnt=0 with arcpy.da.SearchCursor(fc, fields) as cursor: for row in cursor: value_from_row = row[0] cnt+=1 outName = outFolder + os.sep + "dem_{0}".format(cnt) result = dem * value_from_row result.save(outName) del row del dem del tbl In this code the following assumptions are made (basically to keep the code simple): environment settings are specified correctly (workspace, cell size, extent, ...) spatial analyst extension is enabled the table ("YourTableName") and DEM ("Input_DEM") are in the TOC the values are stored in field "YourFieldName" Change the "YourTableName" and the name of the DEM "Input_DEM" to the actual name of the objects in the TOC. Also change the "YourFieldName" to the actual name of the field in your table holding the values you want to use. Also specify a valid output folder (or file geodatabase) to store the resulting rasters. What happens in the code is that for each value in your table a new raster is created by multiplying the DEM with that value. The resulting raster is stored in your output folder with the name "dem_#" (where "#" is a consecutive number). The code can be executed from the Python window. You can read more about this in the Help topic "What is the Python window?". The code makes use of arcpy data access module which is available from version 10.1. You can also use a "normal" search cursor to loop through the values in the table. This a also available in version 10.0, but the syntax is different. Kind regards, Xander
... View more
10-20-2013
11:10 PM
|
0
|
0
|
2266
|
|
POST
|
Wayne is right, ArcObjects will be the way to go. It is possible to use COM objects (ArcObjects) in Python. If you want to know a bit more, the following links may be helpful: http://forums.arcgis.com/threads/2567-Accessing-ArcObjects-through-Python http://www.pierssen.com/arcgis/upload/misc/python_arcobjects.pdf http://stackoverflow.com/questions/12190807/com-objects-arcobjects-in-python Good luck, Xander
... View more
10-20-2013
10:43 PM
|
0
|
0
|
4601
|
|
POST
|
Hello! I am a neophyte to GIS. I have historical data for all of my ambulance calls for the past year with attributes including day of week and time of day. Using Arc Desktop Explorer I was able to import the x- and y-coodinates to display the point data for say the 6pm hour on a Thursday. I am now using ArcMap and would like to now be able to display the data as what I refer to as "hotspots" or density mapping. I'm not sure if that is the correct terminology. What I mean by that is an area would display darker in color in areas where the number of ambulance calls are greater in number. I'd also like to be able to select different hours in my query and have the hotspot map update as the query changes. I'm sure this is possible, I'm looking for someone to please point me in the right direction. Thank you for your time and anticipated assistance. Thank you! Anthony Cascio Director Mobile Health Service Robert Wood Johnson University Hospital Hi Anthony, I saw this thread on the forum today (http://forums.arcgis.com/threads/91996-Hot-Spot-Analysis-ِAccidents-Analysis) where Larry Gaudieri refers to a tutorial "specifically targeting emergency or response data". It links to this location: http://www.arcgis.com/home/item.html?id=6626d5cc81a745f1b737028f7a519521 and consists of PDF document and a map package with the data. Please look at that tutorial and things will become much clearer. The content was placed online by Lauren Rosenhein. She is a Geoprocessing Product Engineer at Esri and very passionate about spatial analysis. I had the chance to talk to her at the DevSummit in March this year and she told me that there is a huge difference between performing an (optimal) hot spot spatial statistics analysis or visualizing your data as hot spots. Please bear that in mind. On the other side there is the visualization of hot spots. A very nice example of this is shown in a video where Mansour Raad demonstrates the ArcGIS tools for analyzing and querying big data and billions of records: http://video.esri.com/watch/2191/big-data-in-arcgis If you have an ArcGIS Online prescription you can make use of Maps for Office and make hot spot visualizations of your data in Excel. Read more about this here: http://doc.arcgis.com/en/maps-for-office/help/find-hot-spot.htm And of course there is the possibility to program something yourself using one of the Runtime SDK's Esri provides or use the REST interface: https://developers.arcgis.com/en/rest/analysis/api-reference/find-hot-spots.htm I hope this gets you started. Kind regards, Xander
... View more
10-16-2013
07:03 AM
|
0
|
0
|
645
|
|
POST
|
I'm working with a set of 88 counties in Ohio, and I need to cluster them into groups of 3 based on minimum aggregate distance between each possible cluster of 3 (I created polygon centroids for each county). This will be done without replacement. Once a county is assigned to one cluster, it is not available for others. Put another way, if there is A, B, C, and D in close proximity to one another, does A/B/C or B/C/D create "tightest" group based off sum of the distances between A-B, B-C, and A-C versus B-C, C-D, and B-D. I am aware of the Grouping Analysis tool in version 10.1 (not positive that would do the trick...), but unfortunately I do not currently have access to that platform. Help please! Thanks in advance. Hi Gabe, You are right that Grouping Analysis will not work for your case. Although you can specify the number of groups, the size of the groups will vary. Since this is a nice challenge I tried something which is far from perfect. It evaluates for the first point which other 2 points are closest. Those 3 points are stored in a dictionary with points (counties) that are no longer available. It takes the next point and so on. So the result below: [ATTACH=CONFIG]28364[/ATTACH] There are a few downsides to this method: This will not result in the best solution since not all possibilities are evaluated. The higher the group number the less counties will still be available and the less optimal the result will be. Just check the result for groups 27 and 29. Since there are 88 counties, county 88 is not group (group = 99) As you can see there's not much intelligence in this process. One could test all possibilities (88 * 87 * 86 = 658416) or make it more intelligent to come up with the best result. Here's the code (stand-alone 10.2) I wrote: #-------------------------------------------------------------------------------
# Name: OHIO.py
# Purpose: group point data OHIO
# Author: Xander Bakker
# Created: 16-10-2013
#-------------------------------------------------------------------------------
def main():
print "Loading libs (arcpy)"
import arcpy
import math
print "Libs (arcpy) loaded..."
fc = r'C:\Project\_Grouping\fgdb\Grouping.gdb\OHpntSP1'
# I assume that field exists and is of type integer
fldOut = 'group01'
maxOID = 0
dict1 = {}
fields = ['OID@','SHAPE@X','SHAPE@Y']
with arcpy.da.SearchCursor(fc, fields) as cursor:
for row in cursor:
OID = row[0]
if OID > maxOID:
maxOID = OID
X = row[1]
Y = row[2]
XY = "{0}#{1}".format(X,Y)
if dict1.has_key(OID) == False:
dict1.update({OID:XY})
del cursor
del row
print "Loop ready, dict filled..."
# loops
group = 0
dictSol = {}
dictOIDused = {}
for id1 in range(1,maxOID-2):
if dictOIDused.has_key(id1) == False:
minDist = 999999
minSol = ''
for id2 in range(id1+1,maxOID-1):
if dictOIDused.has_key(id2) == False:
for id3 in range(id2+1,maxOID):
if dictOIDused.has_key(id3) == False:
XY1 = dict1[id1]
XY2 = dict1[id2]
XY3 = dict1[id3]
X1 = float(XY1.split('#')[0])
Y1 = float(XY1.split('#')[1])
X2 = float(XY2.split('#')[0])
Y2 = float(XY2.split('#')[1])
X3 = float(XY3.split('#')[0])
Y3 = float(XY3.split('#')[1])
sumDist = getSumDist(X1,Y1,X2,Y2,X3,Y3)
if sumDist < minDist:
minSol = '{0}#{1}#{2}'.format(id1,id2,id3)
minDist = sumDist
else:
# skip, id3 already in use
pass
else:
# skip, id2 already in use
pass
# end of loop through id2, so solution is available
group += 1
dictOIDused.update({int(minSol.split('#')[0]): group})
dictOIDused.update({int(minSol.split('#')[1]): group})
dictOIDused.update({int(minSol.split('#')[2]): group})
# print "minSol={0} and minDist={1}".format(minSol,minDist)
else:
# skip, id1 already in use
pass
# update cursor
fields = ['OID@',fldOut]
with arcpy.da.UpdateCursor(fc, fields) as cursor:
for row in cursor:
id = row[0]
if dictOIDused.has_key(id):
group = dictOIDused[id]
else:
group = 99
row[1] = int(group)
cursor.updateRow(row)
del row
del cursor
print "ready..."
def getSumDist(X1,Y1,X2,Y2,X3,Y3):
import math
d1 = math.hypot(X2 - X1, Y2 - Y1)
d2 = math.hypot(X3 - X1, Y3 - Y1)
d3 = math.hypot(X3 - X2, Y3 - Y2)
return d1 + d2 + d3
if __name__ == '__main__':
main()
... View more
10-16-2013
06:13 AM
|
0
|
0
|
450
|
|
POST
|
I have a script that unselects all the selected features in my Map view but it loops through each layer in the dataframe and this takes a lot of time. I want to write a script that would be as fast as the Unselect the currently selected Features in all layers within ArcMap itself? This is my code below; mxd = arcpy.mapping.MapDocument("Current")
df = arcpy.mapping.ListDataFrames(mxd)[0]
for lyr in arcpy.mapping.ListLayers(mxd):
... arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
...
Runtime error Traceback (most recent call last): File "<string>", line 2, in <module> File "C:\Program Files (x86)\ArcGIS\Desktop10.1\arcpy\arcpy\management.py", line 6461, in SelectLayerByAttribute raise e ExecuteError: Failed to execute. Parameters are not valid. ERROR 000840: The value is not a Table View. ERROR 000840: The value is not a Raster Layer. ERROR 000840: The value is not a Mosaic Layer. Failed to execute (SelectLayerByAttribute). Any Suggestions? Thanks Strange, if I run the (slightly changed) code it does run for me (in 10.2) import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
dfs = arcpy.mapping.ListDataFrames(mxd)
for df in dfs:
for lyr in arcpy.mapping.ListLayers(mxd,"*",df):
if lyr.isFeatureLayer:
arcpy.SelectLayerByAttribute_management(lyr, "CLEAR_SELECTION")
for tbl in arcpy.mapping.ListTableViews(mxd,"*",df):
arcpy.SelectLayerByAttribute_management(tbl,"CLEAR_SELECTION")
What type of layers do you have in your TOC? Kind regards, Xander
... View more
10-16-2013
12:17 AM
|
0
|
0
|
4601
|
|
POST
|
Hi Larry, The (optimized) Hot spot analysis does not account for large areas without data. It is not an interpolation, but a statistical analysis of the number of incidents. If there are no incidents, clustering will be low, which will not result in a hot spot. Some reading: How Optimized Hot Spot Analysis Works How Hot Spot Analysis (Getis-Ord Gi*) works Kind regards, Xander
... View more
10-15-2013
11:31 PM
|
0
|
0
|
707
|
| Title | Kudos | Posted |
|---|---|---|
| 6 | 12-20-2019 08:41 AM | |
| 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 |
| Online Status |
Offline
|
| Date Last Visited |
11-26-2025
02:43 PM
|