|
POST
|
There are also arcpy functions to convert numpy Arrays to rasters and the other way around. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//000v00000130000000 Didn't know about that. Always something new to learn 🙂 Cheers. A
... View more
11-06-2012
03:58 AM
|
0
|
0
|
1464
|
|
POST
|
Hi, In my considered opinion there is no reason to use either of this to for this purpose. Simple list slicing with defined number of columns will do the trick. Simple example: i = range(20)
cols = 4
f = open('D:\\tmp.csv', 'w')
for r in range(len(i)/cols):
f.write(';'.join([str(v) for v in i[r*cols:(r+1)*cols]]) + '\n')
Regards Arek
... View more
11-06-2012
03:10 AM
|
0
|
0
|
1464
|
|
POST
|
Hi, Never have this problem, but usually in cases like this I put tool to model builder and then export to python. Then copy this to your script and make cosmetics 😉 Cheers Arek
... View more
10-30-2012
03:17 AM
|
0
|
0
|
547
|
|
POST
|
I made few changes to your code and test it with xls you've attached, and it seems to be working fine. You may want to check is everything is ok with your wgs 84.prj, and path to it. Also i recommend to skip setting env, unless you wanne use it. Below code with my modifications, also should explain how to use CopyFeatures instead of SaveToLayerFile.
import arcpy
from arcpy import env
# Set environment settings
#env.workspace = 'C:\TEMP\BS_Test.gdb'
try:
# Set the local variables
# in_Table = "firestations.csv"
tb = 'D:\\ApgRImmrpWGS.xls\\ApgRImmrpWGS$'
xc = "X"
yc = "Y"
out_Layer = "BHsWellLocations_layer"
saved_Layer = r"c:\Tmp\BHsWellLocations.shp"
# Set the spatial reference
# spRef = r"Coordinate Systems\Projected Coordinate Systems\Utm\Nad 1983\NAD 1983 UTM Zone 11N.prj"
spRef = r"Coordinate Systems\Geographic Coordinate System\World\WGS 1984"
# Make the XY event layer...
arcpy.MakeXYEventLayer_management(tb, xc, yc, out_Layer, spRef)
# Print the total rows
print arcpy.GetCount_management(out_Layer)
# Save to a layer file
arcpy.CopyFeatures_management(out_Layer, saved_Layer)
except:
# If an error occurred print the message to the screen
print arcpy.GetMessages()
Regards Arek
... View more
10-19-2012
05:28 AM
|
0
|
0
|
2993
|
|
POST
|
Sorry I missed one thing in my code. Error is caused by list as argument, simple correction should help. Script will work, as long as layer names in data frame will be unique. Try this one: 1>>> SubjectLyr = arcpy.mapping.Layer("Y:\\Notification Radius Pkgs\\Dave3\\Shapefiles\\Dave3Subject.shp") # use either \\ or / in paths 2>>> mxd = arcpy.mapping.MapDocument("CURRENT") 3>>> df = arcpy.mapping.ListDataFrames(mxd, "Radius Map")[0] 4>>> wPath = "Y:\\Notification Radius Pkgs\\" # same as in line 1 5>>> arcpy.mapping.AddLayer(df, SubjectLyr,"AUTO_ARRANGE") 6>>> SubjectLyr = arcpy.mapping.ListLayers(mxd, SubjectLyr.name, df)[0] # change reference to layer in mxd 7>>> sourceLayer = arcpy.mapping.Layer(wPath+"Setup10\\LayerFiles\\Subject.lyr") # same as in line 1 8>>> arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True)
... View more
10-18-2012
06:19 AM
|
0
|
0
|
1314
|
|
POST
|
Hi, arcpy.MakeRasterLayer_management is meant to other purpose, so you can skip this. Code below should help. If you want to change layer name use: addLayer.name = new_name before adding layer to map doc.
fc_list=[fc_meanSun,fc_lowSun]
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
for ras_name in fc_list:
fc=fc_path+'\\'+ras_name
addLayer = arcpy.mapping.Layer(fc)
arcpy.mapping.AddLayer(df,addLayer)
Regards. Arek
... View more
10-18-2012
05:51 AM
|
0
|
0
|
1204
|
|
POST
|
Hi, Firstly use \\ or / to separate path. Also after adding layer to map document you have to change reference to this layer (layer on disk and in map document is not the same layer!) Below your code with some changes that make it work:
1>>> SubjectLyr = arcpy.mapping.Layer("Y:\\Notification Radius Pkgs\\Dave3\\Shapefiles\\Dave3Subject.shp") # use either \\ or / in paths
2>>> mxd = arcpy.mapping.MapDocument("CURRENT")
3>>> df = arcpy.mapping.ListDataFrames(mxd, "Radius Map")[0]
4>>> wPath = "Y:\\Notification Radius Pkgs\\" # same as in line 1
5>>> arcpy.mapping.AddLayer(df, SubjectLyr,"AUTO_ARRANGE")
6>>> SubjectLyr = arcpy.mapping.ListLayers(mxd, SubjectLyr.name, df) # change reference to layer in mxd
7>>> sourceLayer = arcpy.mapping.Layer(wPath+"Setup10\\LayerFiles\\Subject.lyr")[0] # same as in line 1
8>>> arcpy.mapping.UpdateLayer(df, SubjectLyr, sourceLayer, True)
Cheers Arek
... View more
10-18-2012
05:11 AM
|
0
|
0
|
1314
|
|
POST
|
Hi, Looking at attached file, I think coordinates format is invalid. To create features in WGS coordinates have to be in decimal degrees and in your file they aren't. Another thing is what you want to achieve by creating lyr on event layer? If you want to save event layer as featureclass use CopyFeatuers_management instead. Cheers Arek
... View more
10-16-2012
06:11 AM
|
0
|
0
|
2993
|
|
POST
|
Use cursor to extract max value then after importing symbology from .lyr use symbology attribute of layer, and set classBreakValues parameter (it should be sorted list of break values). So it should looks something like:
...
with arcpy.da.SearchCursor(lyr, (field_name)) as cur:
max_v = max([v[0] for v in cur])
...
if lyr.supports('SYMBOLOGY'):
lyr.symbology.valueField = field_name
lyr.symbology.classBreakValues = [0, 0.01 * max_v, 0.05 * max_v, 0.5 * max_v, 0.75 *max_v, max_v]
...
arcpy.RefreshActiveView()
Regards, Arek
... View more
10-10-2012
01:18 AM
|
0
|
0
|
572
|
|
POST
|
After importing symbology from .lyr use symbology attribute of layer, and set classBreakValues parameter (it should be sorted list of break values). So it should look like:
...
lyr = arcpy.mapping.ListLayers(mxd, 'layer_name_in_mxd)[0]
if lyr.supports('SYMBOLOGY'):
lyr.symbology.valueField = field_name
lyr.symbology.classBreakValues = [0, 0.01, 0.05, 0.5, 0.75, 1]
lyr.symbology.classBreakLabels = ['<1%', '1-5%', '5-50%', '50-75%', '>75%']
...
arcpy.RefreshActiveView()
Regards. Arek
... View more
10-10-2012
01:11 AM
|
0
|
0
|
572
|
|
POST
|
OK. This presentation + online arcpy help (http://resources.arcgis.com/en/help/main/10.1/index.html#/Reading_geometries/002z0000001t000000/ - reading; http://resources.arcgis.com/en/help/main/10.1/index.html#/Writing_geometries/002z0000001v000000/ - writing) Is all I got. Can you specify what exactly you want to achieve? Maybe then we could be more helpful 🙂 Best Regards. Arek
... View more
09-26-2012
12:43 AM
|
0
|
0
|
807
|
|
POST
|
if arcpy.GetParameterAsText(2) != "":
do stuff with arcpy.GetParameterAsText(2) Right, you can also use simple: if arcpy.GetParameterAsText(2):
do stuff with arcpy.GetParameterAsText(2)
Empty string is treated as Boolean False, so if there is no parameters nothing will be done.
... View more
09-24-2012
10:53 PM
|
0
|
0
|
874
|
|
POST
|
http://www.arcgis.com/home/item.html?id=ddfa7bb180e54e9581d842743a032043 You may find this presentation useful. There is simple explanation how to access geometry by cursor. Regards. Arek
... View more
09-24-2012
06:17 AM
|
0
|
0
|
807
|
|
POST
|
Hi, I thing create dictionary with increment value would be simple and elegant solution. It will look something like:
import arcpy
import sys
in_table = sys.argv[1]
field = sys.argv[2]
val_dict = {}
cur = arcpy.UpdateCursor(in_table)
for row in cur:
value = row.getValue(field)
if value not in val_dict.keys():
val_dict[value] = 0
else:
val_dict[value] += 1
row.setValue(field, value + '_' + str(val_dict[value]))
cur.updateRow(row)
del cur
Cheers Arek
... View more
09-24-2012
01:43 AM
|
0
|
0
|
672
|
|
POST
|
Hi, First of all, don't save constant value raster, if you using it only ones, just use it in multiplication. It will remove few operations (saving, rereading and deleting). Another thing, is type of raster, use "Float" only if necessary, operations or floating numbers are much more complex for processor.
import os
import arcpy
from arcpy import env
from arcpy.sa import *
arcpy.CheckOutExtension("Spatial")
#Set local variables
wks = arcpy.GetParameterAsText(0) # input workspace
inRaster1 = arcpy.GetParameterAsText(1) # input raster layer
env.workspace = wks
#Perform Constant Raster Function
constantValue = arcpy.GetParameterAsText(2) # input weight value
cellSize = 100
outExtent = Extent(871599.89, 982834.44, 912502.09, 1070920.9)
if int(constantValue) == constantValue:
type = 'INTEGER'
else:
type = 'FLOAT'
outConstRaster = CreateConstantRaster(constantValue, type, cellSize, outExtent)
#Perform Times Function
outTimes = Raster(inRaster1)* outConstRaster
outRaster1 = "Wt_" + os.path.basename(inRaster1)
outTimes.save(outRaster1)
#Create script output and delete constant raster
arcpy.SetParameterAsText(3,outRaster1)
... View more
09-24-2012
01:23 AM
|
0
|
0
|
874
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 10-05-2022 08:01 AM | |
| 1 | 03-29-2023 12:37 AM | |
| 2 | 08-06-2013 05:40 AM | |
| 1 | 11-15-2012 10:38 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-29-2023
03:19 PM
|