|
POST
|
I'd imagine those rasters you are seeing are intermediate data that isn't cleaned up when it crashes since you specified your input directory as your working directory, all intermediate data will be created there. Also, I am not sure how you are accessing your ZonalStatistics tool since it isn't under the gp, it is under sa. The tool call should look like this. arcpy.sa.ZonalStatistics(...) Are you running this from inside an Arc session or stand alone?
... View more
07-11-2012
08:00 AM
|
0
|
0
|
3788
|
|
POST
|
The imports for mine were setup like this. master import dataset_conversion, dataset_conversion27_83, dataset_conversion83_CSRS def func(): dataset_conversion.export() dataset_conversion27_83.conversion() dataset_conversion83_CSRS.conversion() first child import arcpy, datetime, sys def export(): try: ... I tested this way and it works as well. Master import arcpy,testing_arcpy print testing_arcpy.test() Child def test(): import arcpy import arcpy.sa arcpy.env.workspace = r"C:\GIS\testing" return arcpy.env.workspace
... View more
06-27-2012
01:57 PM
|
0
|
0
|
1412
|
|
POST
|
I have imported child scripts that call arcpy without any problems. Are you sure by this line
import arcpy.sa You don't mean this? from arcpy import sa
... View more
06-27-2012
12:27 PM
|
0
|
0
|
1412
|
|
POST
|
This works just as you said, thank you so much for the quick reply. Regards. No problem. And if you want something a little prettier, you can do something like this. Untested and not really optimal, but a step in the pythonic direction. import arcpy
# Local variables:
events = "ProductionGIS.GISADM.NCS_SUB_CODE_EVT Events"
layer_list = ["ProductionGIS.GISADM.NCS_CLEARANCE",
"ProductionGIS.GISADM.NCS_MILEPOST",
"ProductionGIS.GISADM.NCS_EQUATIONS",
"ProductionGIS.GISADM.NCS_SIGN",
"ProductionGIS.GISADM.NCS_SIGNAL",
"ProductionGIS.GISADM.NCS_INTERLOCKING",
"ProductionGIS.GISADM.NCS_SWITCH",
"ProductionGIS.GISADM.NCS_XING"
]
result_list = []
nodes_list = ["Equations","Switch"]
milepost_additions = ["Milepost","Signal"]
node_count = 0
milepost_count = 0
for layer in layer_list:
arcpy.SelectLayerByLocation_management(layer, "INTERSECT", events, "", "NEW_SELECTION")
result = arcpy.GetCount_management(layer)
result_list.append([layer.split("_")[-1],int(result.getOutput(0))])
for name,count in result_list:
name = name.capitalize()
arcpy.AddMessage("{0} Point Count = {1}".format(name,count))
if name in nodes_list:
node_count += count
if name in milepost_additions:
milepost_count += count
arcpy.AddMessage("Nodes Point Count = {0}".format(node_count))
arcpy.AddMessage("Milepost Helper Point Count = {0}".format(node_count+milepost_count))
... View more
06-27-2012
12:17 PM
|
0
|
0
|
1186
|
|
POST
|
I would sum like this. arcpy.AddMessage("Milepost Helper Point Count = {0}".format(featurecount3+featurecount7+featurecount5+featurecount2))
... View more
06-27-2012
11:26 AM
|
0
|
0
|
1186
|
|
POST
|
Like I said, I have never tried this process before, but you might want to try an insert cursor to get the feature by feature data without taking all the data associated with the entire feature class that comes through in a copy. You can also try creating a dummy feature as the first feature in the empty feature class and assign it x,y,z values to force it to be Z enabled. These are just shots in the dark really, hopefully someone else can shed some more insight into the situation than I can.
... View more
06-27-2012
07:46 AM
|
0
|
0
|
2586
|
|
POST
|
Have you tried inserting Z values to each X,Y vertex in the new Z enabled feature class? Where are your Z values coming from? I've added elevation to a feature class by pulling the average from a DEM to a defined polygon mask, but never actually added Z values to a feature class. There is this in the help that may give you some more information on how to go about solving your problem. http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00q80000009s000000.htm Edit: Also, try setting the Z-values in the environment settings as per this thread. http://forums.arcgis.com/threads/22826-Converting-2D-Features-to-3D
... View more
06-27-2012
05:20 AM
|
0
|
0
|
2586
|
|
POST
|
The easier way to go about this would be to write two functions. One for 10.0 and one for 9.3 and test the version when the script executes to determine which function to execute.
... View more
06-26-2012
05:44 AM
|
0
|
0
|
2355
|
|
POST
|
arcpy.mapping.MapDocument should immediately return an error when a relative path is used. For me it does. There is something off with your system variable or paths settings maybe. import os
import arcpy
arcpy.env.workspace = r"C:\GIS"
mxd = arcpy.mapping.MapDocument(r"Test\point_2_line.mxd")
mxd.saveACopy(r"Test\testing4.mxd")
Returns this error. Traceback (most recent call last):
File "C:\GIS\Python\test_mxd_relative_path.py", line 7, in <module>
mxd = arcpy.mapping.MapDocument(r"Test\point_2_line.mxd")
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\arcobjects\mixins.py", line 443, in __init__
assert (os.path.isfile(mxd) or (mxd.lower() == "current")), gp.getIDMessage(89004, "Invalid MXD filename")
AssertionError: Invalid MXD filename. The only way I can get the error you are seeing is using chdir. import os
import arcpy
os.chdir("C:/GIS")
arcpy.env.workspace = r"C:\GIS"
mxd = arcpy.mapping.MapDocument(r"Test\point_2_line.mxd")
mxd.saveACopy(r"Test\testing4.mxd")
Returns this error Traceback (most recent call last):
File "C:\GIS\Python\test_mxd_relative_path.py", line 9, in <module>
mxd.saveACopy(r"Test\testing4.mxd")
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\utils.py", line 181, in fn_
return fn(*args, **kw)
File "C:\Program Files (x86)\ArcGIS\Desktop10.0\arcpy\arcpy\_mapping.py", line 668, in saveACopy
self._arc_object.saveACopy(file_name)
AttributeError: MapDocObject: Unable to save. Check to make sure you have write access to the specified file and that there is enough space on the storage device to hold your document.
... View more
06-21-2012
05:28 AM
|
0
|
0
|
3379
|
|
POST
|
It looks like you are only inputting 4 points to create your polygon, you need 5 points to create a closed rectangle.
... View more
06-20-2012
02:23 PM
|
0
|
0
|
2201
|
|
POST
|
Thanks both of you for your help. I tried the copy raster method and took much longer than the shutil. It works well for the formats I am exporting (.asc and .tif). Here is the code if anyone is interested. import arcpy
import os
import shutil
source_dir = r"source\dir"
arcpy.env.workspace = source_dir
table = r"selection_table"
outDirBase = r"output\folder"
if not os.path.exists(outDirBase):
os.mkdir(outDirBase)
def GetList(table):
name_list = []
s_curs = arcpy.SearchCursor(table)
for row in s_curs:
name = row.Name
name_final = "XX_"+name.split("_")[1]
name_list.append(name_final)
return name_list
nts_list = GetList(table)
dir_list = [("bare_earth_DEM_ascii","be"),
("bare_earth_hillshade_tif","be"),
("full_feature_DSM_ascii","ff"),
("full_feature_hillshade_tif","ff"),
("intensity_image_tif","ii")]
# Get directory name and associated file prefix from tuple list
for directory,pref in dir_list:
# Create a variable to hold the full path to the export directory
new_dir = os.path.join(outDirBase,directory)
# If this folder doesn't exist, create it
if not os.path.exists(new_dir):
os.mkdir(new_dir)
# Create a variable to hold the full path to the source directory
in_dir = os.path.join(source_dir,directory)
# Loop through grid locations in the list of selected grids
for nts in nts_list:
# Assign the associated prefix to the current grid in the list
var_in = pref+nts[2:]
# Create a list of files in the source directory to test against
file_list = os.listdir(in_dir)
# Loop through all files in the source directory
for filename in file_list:
# If the current file matches the
if filename.startswith(var_in):
print "copying {0}".format(filename)
shutil.copy2(os.path.join(in_dir,filename),os.path.join(new_dir,filename))
... View more
06-20-2012
01:50 PM
|
0
|
0
|
2255
|
|
POST
|
Coordinate systems are the same.... still generated an empty output. There is only one data frame.... it seems as if my data isn't in the same area as the clipper...which isn't the case but that's the error I'm getting using both syntax from above: "000117 Warning empty output generated: A common occurrence of this warning occurs when the Extent (or XYDomain) environment has been set previously for a geographically distinct area. Since the Extent environment is used to limit the features used, an inappropriately set Extent environment could exclude all features." It definitely works for me. How are you incorporating this script? Is it part of a larger tool or are you just executing this section in the python window?
... View more
06-20-2012
01:46 PM
|
0
|
0
|
2201
|
|
POST
|
If they are directly on the line I would use Intersect. An intersect with a large XY tolerance/resolution environment setting should work as well if they are a little off. Never tested that though.
... View more
06-20-2012
12:15 PM
|
0
|
0
|
645
|
|
POST
|
Hi Devon, You could create a polygon object based on the MXD's data frame extent, and then use the object to clip the feature class. Here is an example: import arcpy
from arcpy import env
from arcpy import mapping
env.workspace = r"C:\temp\python\test.gdb"
mxd = mapping.MapDocument(r"C:\temp\python\County.mxd")
df = mapping.ListDataFrames(mxd)[0]
xmin = df.extent.XMin
ymin = df.extent.YMin
xmax = df.extent.XMax
ymax = df.extent.YMax
pnt1 = arcpy.Point(xmin, ymin)
pnt2 = arcpy.Point(xmin, ymax)
pnt3 = arcpy.Point(xmax, ymax)
pnt4 = arcpy.Point(xmax, ymin)
array = arcpy.Array()
array.add(pnt1)
array.add(pnt2)
array.add(pnt3)
array.add(pnt4)
array.add(pnt1)
poly = arcpy.Polygon(array)
arcpy.Clip_analysis("Hospitals", poly, "Hospitals_clip")
del mxd Hey Jake, just wondering what the reasoning is behind everything broken up like that? This is a similar code I use, I don't remember if I wrote it or stole it from someone. If I did steal it credit to them.
import arcpy
mxd = arcpy.mapping.MapDocument("CURRENT")
df = arcpy.mapping.ListDataFrames(mxd,"Layers")[0]
extent = df.extent
array = arcpy.Array()
array.add(extent.lowerLeft)
array.add(extent.lowerRight)
array.add(extent.upperRight)
array.add(extent.upperLeft)
array.add(extent.lowerLeft)
polygon = arcpy.Polygon(array)
...
... View more
06-20-2012
11:34 AM
|
0
|
0
|
2201
|
|
POST
|
Your chdir is what is doing it. You are setting the relative path via python not the arcpy module. I'd also recommend removing the trailing slashes at the end of your directory strings. FYI I just tested and this works. import os
import arcpy
os.chdir("C:/GIS/test")
arcpy.env.workspace = "C:/GIS/Test"
mxd = arcpy.mapping.MapDocument("point_2_line.mxd")
mxd.saveACopy("ortho_test_rename/testing3.mxd")
... View more
06-20-2012
05:32 AM
|
0
|
0
|
3379
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 05-17-2011 10:36 AM | |
| 1 | 08-16-2012 10:48 AM | |
| 1 | 10-31-2012 08:39 AM | |
| 1 | 07-16-2012 01:52 PM | |
| 1 | 03-15-2012 10:57 AM |
| Online Status |
Offline
|
| Date Last Visited |
08-22-2024
11:12 PM
|