|
POST
|
Great, that worked thanks! What if there are more than one feature feature datasets in the gdb and each feature dataset has a feature class with the same name?
... View more
10-04-2011
08:13 AM
|
0
|
0
|
1299
|
|
POST
|
We have migrated a bulk of our GIS data from shapefiles into feature classes within feature datasets (ArcGIS-file geodatabase-feature datasets). I am trying to develop a Python script to automatically replace the most popular datasets in an mxd with the paths to the new data. My problem is that both the data model (shapefile to feature dataset feature class) has changed, and the feature class name has changed. The replaceDataSource() and replaceWorkspacePaths() methods do not have parameter for connecting to feature datasets. See http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/MapDocument/00s30000000n000000/ The code posted below works if I move my feature class out of the feature dataset within the file geodatabase (meaning the syntax is good). Still, how to I set the replaceDataSource to a feature data set? try:
import arcpy.mapping, os, sys, string, traceback
mxd = arcpy.mapping.MapDocument("CURRENT")
for dataframe in arcpy.mapping.ListDataFrames(mxd):
BrokenLinkList = arcpy.mapping.ListBrokenDataSources(dataframe)
for item in BrokenLinkList:
print item.datasetName
if item.datasetName == r"LummiReservationFullBoundary":
print "droppin' in"
#The path to the new directory...
newWorkspace = r"Z:\Data\Boundaries\Administrative\Lummi.gdb\TribalBoundaries"
#The new dataset name...
datasetName = r"LummiReservation"
#This should have a "FEATUREDATASET" options to replace FILEGDB_WORKSPACE.
item.replaceDataSource (newWorkspace, "FILEGDB_WORKSPACE", datasetName, False)
arcpy.RefreshTOC()
#mxd.save()
del mxd
print "Done"
except arcpy.ExecuteError:
msgs = arcpy.GetMessages(2)
arcpy.AddError(msgs)
print msgs
except:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
msgs = "ArcPy ERRORS:\n" + arcpy.GetMessages(2) + "\n"
arcpy.AddError(pymsg)
arcpy.AddError(msgs)
print pymsg + "\n"
print msgs
... View more
10-03-2011
10:50 AM
|
1
|
4
|
5039
|
|
POST
|
Here is the code to populate an attribute in the attribute table with a 0 or 1 for 5% of your records. If you want to select 5% of those records that have some other attribute value, then just insert a select by attribute where I have it marked, then only 5% of the selected records will be assigned a 1. '''Selects a random number of records from a feature class and populates a
user-defined field with either a 1 or a 0 based on the input parameters. For
example, if percent_to_include is set to 5, then a random ~5 percent of the
records will be asigned a value of 1, the rest a value of 0.
'''
try:
import operator, os, random, traceback, sys, arcpy
##Path to the feature class.
fc = r"Z:\GISpublic\GerryG\RestorationandMitigationConcept\20110425IvyPlotMonitoring\transects.shp"
##The attribute to populate with 1 or 0...
attribute = r"issample"
##The percent threshold to include as a random selection.
percent_to_include = 5
##INSERT YOUR SELECT BY ATTRIBIUTE HERE
uc = arcpy.UpdateCursor(fc)
for row in uc:
x = random.random() * 100
#arcpy.AddMessage(x)
if x <= percent_to_include:
row.setValue(attribute, 1)
else:
row.setValue(attribute, 0)
uc.updateRow(row)
print "Done"
except:
tb = sys.exc_info()[2]
tbinfo = traceback.format_tb(tb)[0]
pymsg = "PYTHON ERRORS:\nTraceback info:\n" + tbinfo + "\nError Info:\n" + str(sys.exc_info()[1])
print pymsg + "\n"
... View more
07-22-2011
08:52 AM
|
0
|
0
|
363
|
|
POST
|
No, you would think! The centroid returns the midpoint of the line if and only if that point falls on the line, otherwise it returns the coordinates of the label point (which seems to be defined by magic:)). I have a script that I tested on a line shaped like three sides of a square, and the centroid is not close to the midpoint of that line. Using the midpoint function from calculate geometry does return the true midpoint coordinates of that line, but there is no Arcpy/Python property that returns that same coordinate value.
... View more
07-07-2011
06:36 AM
|
0
|
0
|
739
|
|
POST
|
I would like to use Python to get the midpoint of a line. There are a number of geometry properties that will return the centroid, the label point�?� http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Polyline/000v000000n2000000/ �?�but what I am looking for is the coordinate values of the position which is exactly halfway along the line�??s length. It is possible to calculate the midpoint using the calculate geometry functions by right clicking a new field in the attribute table and selecting calculate geometry, but I can find no way to get that calculation into a Python code block. Any ideas?
... View more
07-06-2011
02:31 PM
|
0
|
2
|
3970
|
|
POST
|
ESRI has posted a script that will do what you want. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/Writing_geometries/002z0000001v000000/ Will a little work you can get this script up and running, your polygons created, and learn a lot about scripting in Python.
... View more
06-10-2011
12:25 PM
|
0
|
0
|
1068
|
|
POST
|
Why not just clip the Thiessen polygons to the county border?
... View more
06-07-2011
09:45 AM
|
0
|
0
|
1842
|
|
POST
|
This code worked to remove a \n escape sequence from a string, maybe you can alter the code to work for a \u x = somestringwithanescapesequence" x = repr(x) x = x.replace(r'\n', "")
... View more
04-08-2011
07:15 AM
|
0
|
0
|
2946
|
|
POST
|
Try this tool http://resources.arcgis.com/gallery/file/map-templates/details?entryID=BC061D5E-1422-2418-7FCE-CC0FBB0C0825
... View more
03-18-2011
09:06 AM
|
0
|
0
|
2339
|
|
POST
|
try this... def tvol(a, b, area): if (a >=2): return int(round(a*b/100))
... View more
02-23-2011
06:47 AM
|
0
|
0
|
2301
|
|
POST
|
Try using this... OCCAT__tif = "D:/Documentation/draft_12/Corridas/4/ScriptInputs/OCCAT_"+ instep + ".tif" OC_01_tif = "D:/Documentation/draft_12/Corridas/4/ScriptInputs/OC_"+ instep + ".tif" not this OCCAT__tif = "D://Documentation//draft_12//Corridas//4//ScriptInputs//OCCAT_"+ instep + ".tif" OC_01_tif = "D://Documentation//draft_12//Corridas//4//ScriptInputs//OC_"+ instep + ".tif"
... View more
02-22-2011
06:21 AM
|
0
|
0
|
298
|
|
POST
|
You can't. You need to have ArcGIS installed on the computer to take advantage of the geoprocessing functions in arcpy.
... View more
12-29-2010
07:31 AM
|
0
|
0
|
532
|
|
POST
|
Having suffered enough frustrations with 10 bugs and crashes, I decided to finally reinstall 9.3.1 throughout our department. Since we have many mxds as 10 mxds I thought I could write a nice little script to convert them all to 9.3.1 mxds and get on with work using 9.3.1. Unfortunately, I too, get the �??this map created in a later version of ArcGIS�?? message. Too bad this function, like so much of 10, did nothing but waste my time. Maybe, if this method works sp2, and someone is still tired of 10, here is the code to convert all the v10 mxd to 9.3 mxds in a new directory. [HTML] #Convert all the v10 mxds in TheFolder, and any subdirectory in TheFolder, to #an earlier version of mxd to CopyToHere directory. try: import arcpy, os, sys TheFolder = r"Z:\GISpublic\GerryG\ATLAS\Copyof2010LummiAtlas" CopyToHere = r"Z:\GISpublic\GerryG\ATLAS\Copyof2010LummiAtlas\93mxds\\" for root, dirs, files in os.walk(TheFolder): for file in files: if file.endswith("mxd") or file.endswith("MXD"): print root print file mxd = arcpy.mapping.MapDocument(root + "\\"+ file) #Only make copies of mxd that have a dateSaved value (v10 only) if mxd.dateSaved: print mxd.dateSaved mxd.saveACopy(CopyToHere + file, "9.3") print "Done!" sys.exit() except: print arcpy.GetMessages(2) print ErrorDesc.message print "Error" sys.exit()[/HTML]
... View more
12-28-2010
11:18 AM
|
0
|
0
|
778
|
|
POST
|
I am not sure if this is your problem but when you are finished with a cursor be sure to use something like del row, rows By not deleting the row and rows (or whatever you name them) you can get schema locks when you try to run another cursor on the same data.
... View more
12-28-2010
07:27 AM
|
0
|
0
|
690
|
|
POST
|
I have a data frame, point shapefile, and elevation GRID all in the same coordinate system, datum, and projection, WA State Plane North. When using the Add Surface Information toolbox tool (ArcGIS 10) to populate the point file with GRID values the z factor (optional) parameter is grayed out with a setting of 3.28083... This setting needs to be a 1 since the z values are in feet and the pixel values are in feet ohterwise the output values get scaled by this value. I am not sure why the tool thinks it needs to do a meters to feet conversion given the data. I played around with different surface models (usgs) and I am able to set this parameter there. Any ideas why this would be happening, other than a bug in ArcGIS would be great. Oh, and exporting the tool to Python solved the problem in the short run since I was able to reset the parameter there. Thanks Gerry
... View more
12-06-2010
03:10 PM
|
0
|
1
|
3360
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 06-26-2025 08:30 AM | |
| 1 | 10-29-2024 03:51 PM | |
| 1 | 06-26-2024 08:32 AM | |
| 1 | 12-06-2023 11:53 AM | |
| 1 | 06-12-2012 07:42 AM |
| Online Status |
Offline
|
| Date Last Visited |
09-23-2025
10:15 AM
|