POST
|
Sounds like you could do this without out python. You could create two new fields in your table for the center Lat and Long and use the field calculator to calculate the values. If you'd rather use python you could do something like this...
input = "test_points"
fieldName_01 = "cenLat"
fieldName_02 = "cenLong"
expression_01 = "(!StartLat!+!EndLat!)/2"
expression_02 = "(!StartLong!+!EndLong!)/2"
#Add fields
arcpy.AddField_management(input,fieldName_01,"DOUBLE")
arcpy.AddField_management(input,fieldName_02,"DOUBLE")
#Calculate coordinate between the points
arcpy.CalculateField_management(input,"centLat",expression,"PYTHON")
arcpy.CalculateField_management(input,"cenLong",expression,"PYTHON")
These might be helpful if you decide on the python route... Add Fields: http://resources.arcgis.com/en/help/main/10.1/index.html#//001700000047000000 Calculate Field: http://resources.arcgis.com/en/help/main/10.1/index.html#//00170000004m000000
... View more
02-01-2013
12:53 PM
|
0
|
0
|
781
|
POST
|
One way you could check this is to see if the dataframe's extent contains the point layer's extent.
import arcpy
mxd = arcpy.mapping.MapDocument("C:\GIS\dfTest\Map1.mxd")
mxd.activeView = "PAGE_LAYOUT"
df = arcpy.mapping.ListDataFrames(mxd)[0]
lyr = arcpy.mapping.Layer('point')
#Test if df extent contains the extent for the layer symbology
df.extent.contains(lyr.getExtent("True"))
... View more
05-17-2012
04:15 AM
|
0
|
0
|
288
|
POST
|
Should be fixed now. 🙂
#==========================
# DEFINITION QUERY
#==========================
# Benjamin Gale - May 2012
#==========================
import arcpy
#Get parameters
lyrName = arcpy.GetParameterAsText(0)
defQuery = arcpy.GetParameterAsText(1)
lyr = arcpy.mapping.Layer(lyrName)
lyr.definitionQuery = defQuery
#Refresh ActiveView
arcpy.RefreshActiveView()
#Save layer (will only occur if the layer is a .lyr file)
lyr.save()
... View more
05-16-2012
06:54 AM
|
0
|
0
|
408
|
POST
|
Not sure if this is the sort of thing you were looking for but I might have something that will work for you. However, it requires a look up table containing map names and the text you want displayed. To use the code, the maps you want to run the code on should ALL contain the same text for the element you want to change. For example, when I was testing the code I had the text '<TextVariable>' on each map and it was set to be the text replaced by what was stored in the look up table for that map document. So in my test, the text that said '<TextVariable>' became 'Map 001' in Map1.mxd, it became 'Map 002' in Map2.mxd and so on. This solution would require you to change the text after the map is completed. Also, the code can't be run on a map that is currently open.
#============================================
# Change Text Based Using Look Up Table
#============================================
import arcpy
import os
mxds = [r"C:\My_Stuff\GIS\Text\Map1.mxd","C:\My_Stuff\GIS\Text\Map2.mxd"] #List of mxds
table = [r"C:\My_Stuff\GIS\Text\DynamicText.gdb\LookupText"] # Lookup table
for mxd in mxds:
rows = arcpy.SearchCursor(table)
mapp = arcpy.mapping.MapDocument(mxd)
for row in rows:
val = row.getValue("MapName") #Fieldname containing map names
if val + ".mxd" == os.path.basename(mxd):
txt = row.getValue("Text") #Fieldname containing text string
txt_elms = arcpy.mapping.ListLayoutElements(mapp,"TEXT_ELEMENT")
for elm in txt_elms:
if elm.text == "<TextVariable>": #Text in all maps to be replaced
elm.text = txt
mapp.save()
del rows, row
You could also set the code to look for element names rather than text Also, while I didn't have any trouble with the code, if you use the code you may want to test it on copies of you maps first given that it saves the changes made.
... View more
05-15-2012
06:53 PM
|
0
|
0
|
1094
|
POST
|
I think this should do the trick. The attached tool (removed: see attachment in post below) is already setup to be used in a model or on its own.
import arcpy
#Get parameters
lyrName = arcpy.GetParameterAsText(0)
defQuery = arcpy.GetParameterAsText(1)
lyr = arcpy.mapping.Layer(lyrName)
lyr.definitionQuery = defQuery
#Refresh ActiveView
arcpy.RefreshActiveView()
... View more
05-15-2012
08:58 AM
|
0
|
0
|
408
|
POST
|
I'm not 100% sure which piece of your code is giving you the error. I use a similar code and was able to preform the process on some of my own data. I didn't include the output coordinate so that would have to be added back in. #Set Variables
inWS = r"C:\My_Stuff\ConvertPTtoRaster\SHP" # In workspace
outWS = r"C:\My_Stuff\ConvertPTtoRaster\Output" # Out workspace
arcpy.env.workspace = inWS
arcpy.env.overwriteOutput = 1
arcpy.env.extent = "2470500 7661500 2477000 7666800"
arcpy.env.cellSize = 25
ptFeatures = list()
ptFeatures = arcpy.ListFeatureClasses("","Point") #Only use points features
for fc in ptFeatures:
fName = arcpy.Describe(fc).basename
arcpy.PointToRaster_conversion(fc,"Z",outWS + "\\" + fName,"MAXIMUM","",25) With your code. inWS = "E:\\MichaelBrady\\Graduate_work\\MAIN\\Classes\\spring2012\\ind_study\\nexrad\\data\\irene_nexrad\\nexrad_Irene_Working" # In workspace
outWS = inWS # Out workspace
arcpy.env.workspace = inWS
arcpy.env.overwriteOutput = 1
arcpy.env.extent = "-236 -1476 661 -806"
arcpy.env.cellSize = 1
ptFeatures = list()
ptFeatures = arcpy.ListFeatureClasses("","Point") #Only use points features
for fc in ptFeatures:
fName = arcpy.Describe(fc).basename
arcpy.PointToRaster_conversion(fc,"Globvalue",outWS + "\\" + fName,"MAXIMUM","NONE",1) Hope it works!
... View more
05-05-2012
02:59 PM
|
0
|
0
|
559
|
POST
|
Might be possible...but my attempts keep running into the ArcInfo requirement wall. Depending on how many features you have you might be able to do this with the free-version of the ET GeoWizard though. I think the feature limit for the free version is 100 feature per layer... http://www.ian-ko.com/
... View more
05-04-2012
09:51 AM
|
0
|
0
|
132
|
POST
|
I've been doing some testing on my script and now I am somewhat confused too. I've tried the script in the Python window of ArcMap for a number of mxds. Usually I'd copy/paste the present data frame so I had two data frames to test on. Most of the time the script works perfectly but I have had one set of data that keeps causing me to get an error (below). The error for me seems to occur in the last line when I try to apply the symbology. However, because I did my test in the ArcMap python window I am not sure if it is the same error that you are getting.
Runtime error <class 'arcgisscripting.ExecuteError'>: ERROR 000967: The input layer type must be a feature layer, raster layer, or tin layer. ERROR 000840: The value is not a Layer.
The error appears to be complaining about my input put not being the right kind of layer... The thing that I'm confused about in my case is that when I check the feature the error occurs on it says it IS a feature layer. Strangely there doesn't seem to be anything special about the data that would make it cause this error...
>>> symbologyLayer.isFeatureLayer
True
>>> layer.isFeatureLayer
True
>>> for lyr in layerList:
... if lyr.isFeatureLayer:
... print "TRUE"
...
TRUE
TRUE
TRUE
TRUE
TRUE
>>> for lyr in symbologyList:
... if lyr.isFeatureLayer:
... print "TRUE"
...
TRUE
TRUE
TRUE
TRUE
TRUE
So now I am a little puzzled at what might be the problem for either of us...
... View more
02-14-2012
09:59 AM
|
0
|
0
|
602
|
POST
|
Were you using my code? If so, did you make any changes to it before getting the error? I just retested the script and got an error too...primarily due to a typo. It appears I missed a bracket when I put the code up. I have fixed it though and tested the code below in PythonWin, in ArcMap and as a stand alone file. If you made some changes to it...or used another script...I'd probably need to see it to determine where the error came from. (The error sounds like the variable didn't get set to a layer object). Sorry about my blunder. Hope this helps : ) import arcpy mxd = arcpy.mapping.MapDocument('>>MXDPATHHERE<<') df = arcpy.mapping.ListDataFrames(mxd) #Create list of layer from first dataframe symbologyList = arcpy.mapping.ListLayers(mxd,"",df[0]) layerList = list() #Remove first dataframe from list df.remove(df[0]) #Add the rest of the layers to a list for d in df: layerList.extend(arcpy.mapping.ListLayers(mxd,"",d)) #Compare the layers. If they are the same feature change the symbology. for symbologyLayer in symbologyList: for layer in layerList: if symbologyLayer.dataSource == layer.dataSource: arcpy.ApplySymbologyFromLayer_management(layer, symbologyLayer) mxd.save() del mxd
... View more
02-12-2012
06:31 PM
|
0
|
0
|
602
|
POST
|
You could probably do something like this to apply the symbology from the first dataframe to the others. I only tested it with two frames though (one to grab the symbology from and one to apply it too). You should be able to grab the symbology from layers in more than one data frame with a bit of tweaking. To compare if layers in different data frames are the same this example compares the layer's data sources. I'm not sure how to apply this to the labels though... Hope it helps! : )
import arcpy
mxd = arcpy.mapping.MapDocument('CURRENT')
df = arcpy.mapping.ListDataFrames(mxd)
#Create list of layer from first dataframe
symbologyList = arcpy.mapping.ListLayers(mxd,"",df[0])
layerList = list()
#Remove first dataframe from list
df.remove(df[0])
#Add the rest of the layers to a list
for d in df:
layerList.extend(arcpy.mapping.ListLayers(mxd,"",d)
#Compare the layers. If they are the same feature change the symbology.
for symbologyLayer in symbologyList:
for layer in layerList:
if symbologyLayer.dataSource == layer.dataSource:
arcpy.ApplySymbologyFromLayer_management(layer, symbologyLayer)
... View more
02-08-2012
05:22 PM
|
0
|
0
|
602
|
POST
|
Think this should work. I tested it on a folder of shp files.
arcpy.env.workspace = "WORKSPACE"
mxd = arcpy.mapping.MapDocument('CURRENT')
fclist = arcpy.ListFeatureClasses()
for fc in fclist:
name = fc.split(".") #Splits the .shp from the name
arcpy.MakeFeatureLayer_management(fc,name[0])
... View more
02-07-2012
04:44 AM
|
0
|
0
|
104
|
POST
|
Strange the second should have worked. I made it into a tool and tested it on a mxd that I broke the data sources in and it appeared to work. I'll put the tool I made below in case it will work for you. Just extract the toolbox and script into the same folder and specify an mxd and new path. Leaving the old path blank should update all the layers. If it still doesn't work there may be a step I am over looking or am not aware of. What is the scenario for the new paths compared to the old ones? Is the data for the layers arranged or named differently? EDIT: I should note running the tool with the target mxd open appears to crash ArcMap.
... View more
02-06-2012
10:09 AM
|
0
|
0
|
186
|
POST
|
From the code you posted the only thing that I really notice is that it appears that you are changing your input variables before you use them. folderPath = r"" oldpath = "" newpath = r"" I took those out and changed the extention.lower() to extention.endswith (looked like you were checking if the file was an mxd?). I think it should work now.
import arcpy, os
#Parameters (workspaces)
folderpath = arcpy.GetParameterAsText(0)
oldpath = arcpy.GetParameterAsText(1)
newpath = arcpy.GetParameterAsText(2)
#Loop through folder
for filename in os.listdir(folderPath):
fullpath = os.path.join(folderPath, filename)
if os.path.isfile(fullpath):
basename, extension = os.path.splitext(fullpath)
if extention.endswith("mxd"):
mxd = arcpy.mapping.MapDocument(fullpath)
mxd.findAndReplaceWorkspacePaths(oldpath, newpath)
mxd.save()
If not... It might be easier to test the basic workflow then add in your loop. You could try making a tool out of this...it will only do one mxd at a time but it should work. If you leave the input for oldPath empty it should update the workspaces for all the layers to the new path.
import arcpy
#Inputs
mxdIn = arcpy.GetParameterAsText(0) #ArcMapDocument
oldPath = arcpy.GetParameterAsText(1) #Workspace
newPath = arcpy.GetParameterAsText(2) #Workspace
#Set mxd
mxd = arcpy.mapping.MapDocument(mxdIn)
#Change workspace paths of layers
mxd.findAndReplaceWorkspacePaths(oldPath, newPath)
#Save mxd (overwrites mxd)
mxd.save()
... View more
02-04-2012
03:42 PM
|
0
|
0
|
186
|
POST
|
I think you can do this with python. The script below will take the coordinates from the 1st data frame in a mxd (in the units of the frame's coordinate system) and create a polygon out of it. I made it store the x, y values in the attribute table too. Again the values will be in the frame's coord. system units. I imagine you'll probably want to make it loop through multiple mxds since you have so many. I wasn't sure of some of your specifics or exactly what you wanted the user to input so I thought I'd leave it at the example below for now. Hope it helps : )
import arcpy
#Input
inMXD = "FILEPATH" #PLACE HOLDER
outFeature = "FILEPATH" #PLACE HOLDER
#Set MXD and (first) Dataframe
mxd = arcpy.mapping.MapDocument(inMXD)
df = arcpy.mapping.ListDataFrames(mxd)[0]
#Set default output Coordinate System to the same values as the dataframe.
arcpy.env.outputCoordinateSystem = df.spatialReference
#Initial Variables
point = arcpy.Point()
array = arcpy.Array()
#Get data frame bounding values
dfxMax = df.extent.XMax
dfxMin = df.extent.XMin
dfyMax = df.extent.YMax
dfyMin = df.extent.YMin
#Create list of coordinates
coordList = [[dfxMin,dfyMin],[dfxMax,dfyMin],[dfxMax,dfyMax],[dfxMin,dfyMax]]
for coordPair in coordList:
point.X = coordPair[0]
point.Y = coordPair[1]
array.add(point)
#Re-add first point to array to close polygon
array.add(array.getObject(0))
#Create Polygon
polygon = arcpy.Polygon(array,df.spatialReference)
#Creature Feature
arcpy.CopyFeatures_management(polygon, outFeature)
#Add fields for calculated x and y values
coords = [dfxMax, dfxMin, dfyMax, dfyMin]
fieldNames = ["xMax","xMin","yMax","yMin"]
i = 0
for fieldName in fieldNames:
arcpy.AddField_management(outFeature, fieldName, "DOUBLE")
arcpy.CalculateField_management(outFeature, fieldName, coords)
i = i + 1
... View more
02-03-2012
10:23 AM
|
0
|
0
|
158
|
POST
|
From you description I am I thinking this issue might be caused from the toolbar you are using when in layout view. While in layout view... If you are using the layout toolbar (has pieces of paper in the icons and a zoom percent) then the actions you preform, like zooming or panning, will affect the entire page. However, using the tools toolbar should only effect the data frame (map) on the page and the everything else on the page should remain as is. Another possibility is that you put the text in the data frame in which case it would always act the same as the map. However, from you description this seems less likely. Hope that helps. = )
... View more
02-03-2012
06:46 AM
|
0
|
0
|
192
|
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|