POST
|
Thanks Lauren, Your message was really helpful. Best Babak
... View more
01-18-2019
08:17 PM
|
0
|
0
|
526
|
POST
|
Hello When I run "Get Raster Properties" tool in ArcMap to calculate the max, min and mean of my raster, as soon as the tool run ends the popup window disappears and it does not show the results. How can I solve this problem and keep and see the results popup window? Thanks
... View more
01-17-2019
08:54 PM
|
0
|
2
|
788
|
POST
|
Great help, Thank you I changed the parameter value to string and it worked. Best
... View more
02-27-2017
06:50 PM
|
0
|
0
|
313
|
POST
|
Hi I try to specify an argument for output shape file to create it (outputShape = sys.argv[4]) and to get the shape file name from parameters. Then I set the output file parameter as a feature class and output. But my output parameter doesn't work. the script is as follows. Why Cannot I get the output name from parameters? Thanks ------------------------------------------------------------------------------------------------------------- # the path to workplace
arcpy.env.workspace = sys.argv[1]
# The path to the CSV file
inputCSVfile = sys.argv[2]
#Get the template shapefile
templateShapeFile = sys.argv[3]
# The name of the output shape file
outputShape = sys.argv[4] <<<-------------------------------------------------- Here???? it doesn't work,Why???
# open CSV file
inFile = open(inputCSVfile, "r")
# create feature class
arcpy.CreateFeatureclass_management(arcpy.env.workspace, outputShape, "POINT", templateShapeFile, "DISABLED", "DISABLED", templateShapeFile) --------------------------------------------------------------------------------------- -----------------------------------------------------------------------------------------------------
... View more
02-26-2017
09:23 PM
|
0
|
2
|
1239
|
POST
|
When I use python codes to add rasters to my map the raster symbology chenges to stretched. I like it to be colormap. How can I change it to colormap using python codes without keeping a template in my map. Please see the picture. Thanks for help. Babak [ATTACH=CONFIG]22665[/ATTACH]
... View more
03-15-2013
07:14 PM
|
0
|
1
|
442
|
POST
|
Hi Babak, In the query, try stripping the double quotes: lyr.definitionQuery = '{0} in ({1})' .format(newName.strip('"'), queryList) Thank you Kerry It works.
... View more
03-15-2013
07:21 AM
|
0
|
0
|
219
|
POST
|
I have some codes in my script like this.
queryList = selectedFids.replace(';', ',')
newName = arcpy.AddFieldDelimiters(lyr, "[OBJECTID]")
lyr.definitionQuery = '{0} in ({1})' .format(newName, queryList)
In the second line for AddFieldDElimiters properties I have to use Quotes for [OBJECTID] to work. In my SQL query I must only use [OBJECTID] without quotes, but quotes come to my query from newName. I need to get rid of the quotes in the sql query. How can I do that? Please help me. Best regards Babak
... View more
03-14-2013
05:03 PM
|
0
|
2
|
402
|
POST
|
not sure if i completely understand, but your script looks like you´re working with layers inside arcmap in the current mxd. If you want to copy selected features of a layer to a new feature class, CopyFeatures will respect the selection: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//001700000035000000 Dear Rafael My problem looks simple. I need to get rid of quotes in my SQL expression. I will post a new thread for it. I appreciate if you please give me yor idea. Thak you for your help. Babak
... View more
03-14-2013
04:51 PM
|
0
|
0
|
1756
|
POST
|
as the others before said, you can use the same code you used for a shapefile: # describe the feature layer to access the the selected set
desc = arcpy.Describe(lyr)
# FIDSet will contain the selected features
selectedFids = desc.FIDSet But you will only get a list of values if you have selected some features before running the code. Dear Rafael You and other friends are right FIDSet still works in my script. My problem is in another part of the script. I first write the whole codes to illustrate what I am doing and then I show you the problem . These are the codes:
import sys,os,math,string,arcpy
from arcpy import env
# Read from current map
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Data Themes")[0]
layer = arcpy.mapping.ListLayers(mxd, "*", df )
#layer_list = [layer for layer in arcpy.mapping.ListLayers(mxd) if 'FID' in [field.name for field in arcpy.ListFields(layer, 'FID')]]
for lyr in layer:
if lyr.isGroupLayer == False:
# describe the feature layer to access the the selected set
desc = arcpy.Describe(lyr)
# FIDSet will contain the selected features
selectedFids = desc.FIDSet
# If there are selectedFids (a selection set), write them to a new feature
# class in the current workspace.
if len(selectedFids) > 0:
queryList = selectedFids.replace(';', ',')
newName = arcpy.AddFieldDelimiters(lyr, 'OBJECTID')
lyr.definitionQuery = '{0} in ({1})' .format(newName, queryList)
arcpy.RefreshActiveView()
This script must exclude unselected features in the feature class. My problem is in the last three lines here
queryList = selectedFids.replace(';', ',')
newName = arcpy.AddFieldDelimiters(lyr, "OBJECTID")
# This query will exclude unselected fatures
lyr.definitionQuery = '{0} in ({1})' .format(newName, queryList)
For query it must be something like [OBJECTID] in ...... But if I don't put quotes in newName line it will be wrong. How should I write it? Thank you for your help. Babak
... View more
03-14-2013
07:28 AM
|
0
|
0
|
1756
|
POST
|
You can use describe to figure out what the 'oidFieldName' is (whether it be FID, OID, OBJECTID, or something else). oidFieldName = arcpy.Describe(myLayer).oidFieldName Worth mentioning - If you have v10.1, the data access cursors allow a MUCH faster and better way of getting a list of the selected OID values than the .fidSet describe property: oidValueList = [r[0] for r in arcpy.da.SearchCursor(myLayer, ["OID@"])] Hi Chris Thank you for your and other friends' help. 1- I have to write the codes for V 10.0. 2- When I use the following codes:
# describe the feature layer to access the the selected set
desc = arcpy.Describe(lyr)
# FIDSet will contain the selected features
selectedFids = desc.FIDSet
It returns a list of selected FIDs then I can manipulate them. When there is no FID field and I use the following codes as you suggested.
desc = arcpy.Describe(lyr)
if desc.hasOID:
selectedOID = desc.OIDFieldName
It returns only the name of OID for example OBJECTID nothing more. I want it to work like FIDSet. What is the problem. I appreciate your help. Babak
... View more
03-13-2013
05:33 PM
|
0
|
0
|
1756
|
POST
|
I know how to use describe method when there is an FID field in layer's attribute table. I use the following codes
# describe the feature layer to access the the selected set
desc = arcpy.Describe(lyr)
# FIDSet will contain the selected features
selectedFids = desc.FIDSet
But when a layer is added to a map from a GeoDatabase it has an ObjectID* fields instead of FID. How can I describe an OBJECTID* field usng describe method? I appreciate if somebody helps me. Thanks Babak
... View more
03-13-2013
07:31 AM
|
0
|
9
|
6130
|
POST
|
For future reference, "doesn't work" is not useful and makes it difficult for people to answer your question. What was the problem exactly - i.e. did you get an error message, did your script crash, what line did it crash on, did python crash with some sort of windows error, did your computer reboot, did smoke come out of your computer vents, etc...? 😉 Luckily, I think I can see your problem. MX is a number, you can't add a number to a string, you'll get a TypeError. You can use the following instead: "CHARTSCALE = '" + str(MX) + "'"
#or
"CHARTSCALE = '%s'"%MX Hi Luck You are absolutely right. I had to describe what exactly happened. Thanks for the codes. I will try them and thank you for your reminder. Cheers Babak
... View more
03-07-2013
07:40 PM
|
0
|
0
|
419
|
POST
|
Hi I have created the following script to select the biggest extent in the mapview using an select by attribute tool which must contain an expression for where clause. I have also followed other posts like Kirsten 's post who has tried to solve exactly the same problem. My problem is that the expression doesn't work.
# Import modules
import sys,os,math,string,arcpy
from arcpy import env
# Read from current map
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd, "Data Themes")[0]
lyr = arcpy.mapping.ListLayers(mxd, "CHS_Chart_Extents", df)[0]
#The DataFrame extent object is converted into a polygon feature so it can be used with the SelectLayerByLocation function.
dfAsFeature = arcpy.Polygon(arcpy.Array([df.extent.lowerLeft, df.extent.lowerRight, df.extent.upperRight, df.extent.upperLeft]),
df.spatialReference)
# Select the extents into the df map view
arcpy.SelectLayerByLocation_management(lyr, "WITHIN", dfAsFeature, "", "NEW_SELECTION")
# Create the search cursor
#
cur = arcpy.SearchCursor(lyr)
# This list will keep the numbers
featureList = []
#This loop will go through rows to find chart Numbers
for row in cur:
featureList.append(row.CHARTSCALE)
# This is the maximum scale in mapview
MX = max(featureList)
# this message says that the script is OK so far
arcpy.AddMessage(max(featureList))
# Now I need to select only the biggest extent in the mapview with maximum extent
arcpy.SelectLayerByAttribute_management (lyr, "NEW_SELECTION", "CHARTSCALE = '" + MX + "'")
My problem is here
# This is the maximum scale in mapview
MX = max(featureList)
# Now I need to select only the biggest extent in the mapview with maximum extent
arcpy.SelectLayerByAttribute_management (lyr, "NEW_SELECTION", "CHARTSCALE = '" + MX + "'")
How sould I write my where clause to work? Thanks
... View more
03-07-2013
05:32 PM
|
0
|
2
|
899
|
POST
|
One thing you could do is to have a template .lyr file that has the symbology set up exactly as you want. Then, use Apply Symbology from Layer. Thank you for your help and reply Best regards Babak
... View more
02-21-2013
11:27 AM
|
0
|
0
|
265
|
POST
|
Hi Experts I have used python codes to add some raster layers to my map. when the script adds rasters to the map it changes their symbology from colormap to Stretched. How can I change the raster layers symbology again to Colormap using python codes when they are added into table of content. I appreciate for your help. Best regards Babak
... View more
02-21-2013
06:45 AM
|
0
|
2
|
408
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:24 AM
|