POST
|
Well the whole script in 10 would be: import arcpy
MXD=arcpy.mapping.mapdocument('current') #get access to the current mxd
dataframe = arcpy.mapping.ListDataFrames(MXD, "Layers")[0] #grab the dataframe object you want (probably named Layers)
dataframe.zoomToSelectedFeatures() #zoom to the feature in memory
arcpy.RefreshActiveView() #refresh the map so that the extent change shows up
This is written in python 2.6 in the IDLE IDE and saved really wherever you want then added to a toolbox in your toolbox dialog. The help documents are a great place to start for learning this stuff. You could do this in ArcObjects but thats a giant hassle and a whole other ball game code wise. Python.org has lots of resources to get started with python in general and if you want something professionally taught ESRI and many others offer 'Python for ArcGIS' classes. I learned what I know about python from Learning Python by O'Rielly, the ArcGIS help pages and lurking in #python on IRC.
... View more
07-19-2010
07:43 AM
|
0
|
2
|
1723
|
POST
|
You can write a simple script and add it as part of the model, that way you stay in the MB environment.
... View more
07-07-2010
12:34 PM
|
0
|
0
|
1723
|
POST
|
If you have a shapefile with roads that have range attributes you can geocode the address from a table to make them points. You would have to have polygons of your voting districts to then add that data. The voting disctricts may be available from the local government and the addresses may already be geocoded by the local emergancy services for use with E911 systems. Census blocks can be obtained in shapefile format from the Census Bureau's TIGER website as well as from ESRI.
... View more
07-07-2010
12:24 PM
|
0
|
0
|
242
|
POST
|
You dont need to do <>None on your while loops. Python is smart enough to stop when it runs out of lines 😉
... View more
07-07-2010
10:35 AM
|
0
|
0
|
222
|
POST
|
A spatial join joining the voting district to the address point file. This will give you a new point file with each point having the attributes of each address and of the voting district polygon it intersected.
... View more
07-07-2010
10:30 AM
|
0
|
0
|
242
|
POST
|
I dont know about related tables but I know that you cant use an update cursor on a joined table. So on that basis, 1=Yes 2=No 3=Proabably best if un-related thought numbingly slow if your tables are large. I would make some test shapefiles with a few features each and try both methods. Thats the quickest way to test this.
... View more
07-07-2010
10:21 AM
|
0
|
0
|
194
|
POST
|
You have this saved as a BAT? Have you tried saving and running the task as a PY? Im sorry Im not much help with this. I dont have much experience with Server.
... View more
06-29-2010
06:58 AM
|
0
|
0
|
419
|
POST
|
Is python installed on the server? Silly question I know but I only ask because of personal experience.
... View more
06-29-2010
04:55 AM
|
0
|
0
|
419
|
POST
|
If you search google for how to make a world file, you can do it by hand. They arent hard to type out if you know the values for the image already.
... View more
06-28-2010
01:38 PM
|
0
|
0
|
2992
|
POST
|
The problem is that the geoprocessor isnt looking at that x as a variable, just a part of the query string. Build your query outside of that tool and just make the query string a variable. You dont need to escape every quote in the geoprocessing tools, its better to use string literals when making an input variable like this. You may have to convert your date into strings if they are stored as integers so that the string can concatenate.
Query=r'""qwsyear" <= ' + str(x) + r' AND "gweyear" >= ' + str(x) + r'"'
gp.SelectLayerByAttribute("lyr", "new_selection", Query)
>>> x=1957
>>> query=r'""qwsyear" <= ' + str(x) + r' AND "gweyear" >= ' + str(x) + r'"'
>>> query
'""qwsyear" <= 1957 AND "gweyear" >= 1957"'
... View more
06-28-2010
09:46 AM
|
0
|
0
|
228
|
POST
|
Well you can condense this a bit which may solve the problem. theFieldList = gp.ListFields(theBillingTable)
fields=[]
for field in the FieldList:
fields.append(str(field.Name))
if "LINK_TO" not in fields:
gp.AddField_management(theBillingTable,"LINK_TO"," TEXT",3)
gp.AddMessage("Added the field to the table")
LinkToFld = "LINK_TO"
gp.AddMessage(LinkToFld)
gp.CalculateField_management(theBillingTable,LinkToFld,"\"-\"","PYTHON")
else:
gp.AddMessage("The field is already in the table")
... View more
06-28-2010
06:10 AM
|
0
|
0
|
323
|
POST
|
Take a look at this line. It may be as simple as navigating to this data in catalog and copying the path from the top of the window. Code exports from MB are screwy and things like paths can sometimes get messed up as a path within ArcMap can be treated specially if the data was added to the model from ArcMap Table of Contents instead of navigated directly to. Backups__VERSION_DBO_DEFAULT_ = "Database Servers\\LASRV-GIS_SQLEXPRESS.gds\\Backups (VERSION BO.DEFAULT)"
... View more
06-25-2010
11:05 AM
|
0
|
0
|
419
|
POST
|
Take the filenames of the rasters and then slice out the number and then iterate over the list of masks and select the one you want by that number.
for raster in Rasters:
number=raster[3:6]
for mask in Masks:
if number==mask[3:6]:
DO YOUR STUFF HERE
else:
print ('No matching mask'); break
The reason you arent getting a good sort is the same reason sorting by a text field thats full of numbers doesnt put the numbers in the right order. Text doesnt sort like numbers and your list is all strings. This method doesnt need to be sorted to work. You just match the raster to its mask and go.
... View more
06-25-2010
10:54 AM
|
0
|
0
|
176
|
POST
|
You can always just use the merge tool by hand. You would have to manually put each shapefile into the tool for each type but unless you have hundreds of files to merge that shouldnt take very long. I took the code from that link and added the parts to merge lines, but you will have to go in a change the paths to what you need them to be.
#Import modules and create the geoprocessor objectimport arcgisscripting, os
gp=arcgisscripting.create()# Set the workspace
gp.workspace = ("C:\SAM_GIS\SAM_GIS\BIODIVERSITY\Mammals")# Start a blank list for Polygon files
polyList = []
# Start a blank list for Point files
pointList = []
#Start a blank list for the Line files
lineList = []# For each subdirectory
for dir in os.listdir(gp.workspace):
if os.path.isdir(gp.workspace+"/"+dir):
# Get a list of the files in each directory
files = os.listdir(gp.workspace+"/"+dir)
# For each file in a given directory
for file in files:
# Get only files that end with .shp
if (file.endswith(".shp")):
print file
# Describe feature class
desc = gp.Describe(gp.workspace+"/"+dir+"/"+file)
type = desc.ShapeType
#print dir+"/"+file + " type is: " + type
if type == "Polygon":
print dir+"/"+file + " is Polygon"
polyPath = polyList.append(dir+"/"+file)
if type == "Point":
print dir+"/"+file + " is Point"
pointPath = pointList.append(dir+"/"+file)
if type == "Line":
print dir+"/"+file + " is Line"
linePath = lineList.append(dir+"/"+file)
# Hard-code the output merged shapefile names
polyshapefile = "Mergedpoly.shp"
pointshapefile = "Mergedpoint.shp"
lineshapefile = "Mergedline.shp" # Given a list of shapefiles, separate each by a ";"
# and put quotes around the whole thing
def polyshpList(polyPath):
return '"%s"' % ';'.join(polyList)
def pointshpList(pointPath):
return '"%s"' % ';'.join(pointList)
def lineshpList(linePath):
return'"%s"' % ";".join(lineList)# Set the variable to the newly formatted list of shapefiles
polymergedlist = polyshpList(polyPath)
pointmergedlist = pointshpList(pointPath)
linemerged list = lineshpList(linePath# Polygons
try:
print "\nMerging " + polymergedlist + " to get " + polyshapefile + "...\n"
gp.merge_management(polymergedlist, polyshapefile)
gp.clip_analysis("Mergedpoly.shp", "C:\SAM_GIS\SAM_GIS\BIODIVERSITY\CANADAOUTLINEMAP.shp", gp.workspace, ".000001")
print gp.getMessages()
except:
print gp.getMessages()
print "\n *** ERROR: Shapefiles (Polygon) failed to merge *** \n"# Points
try:
print "\nMerging " + pointmergedlist + " to get " + pointshapefile + "...\n"
gp.merge_management(pointmergedlist, pointshapefile)
gp.clip_analysis("Mergedpoint.shp", "C:\SAM_GIS\SAM_GIS\BIODIVERSITY\CANADAOUTLINEMAP.shp", gp.workspace, ".000001")
print gp.getMessages()
except:
print gp.getMessages()
print "\n *** ERROR: Shapefiles (Point) failed to merge *** \n" # Lines
try:
print "\nMerging " + linemergedlist + " to get " + lineshapefile + "...\n"
gp.merge_management(linemergedlist, lineshapefile)
gp.clip_analysis("Mergedline.shp", "C:\SAM_GIS\SAM_GIS\BIODIVERSITY\CANADAOUTLINEMAP.shp", gp.workspace, ".000001")
print gp.getMessages()
except:
print gp.getMessages()
print "\n *** ERROR: Shapefiles (Line) failed to merge *** \n"
print "\nDone."
... View more
06-25-2010
05:15 AM
|
0
|
0
|
1374
|
POST
|
I ended up using the tool in catalog to set it all up. I just went back and did a find-replace to change the file paths. Much quicker than typing all of it. I have a spatial join in one script that is 20685 characters long, most all of it is field mapping. I wrote papers shorter than that in college.
... View more
06-24-2010
01:00 PM
|
0
|
0
|
688
|
Title | Kudos | Posted |
---|---|---|
1 | 11-03-2015 11:33 AM | |
1 | 09-23-2015 10:50 AM | |
1 | 12-14-2015 10:42 AM | |
1 | 12-14-2015 01:10 PM | |
1 | 12-04-2015 08:19 AM |
Online Status |
Offline
|
Date Last Visited |
11-11-2020
02:23 AM
|