|
POST
|
Hi I'm trying to extraction band information from raster images using overlapping buffers. I tried using Jamie's code and it takes a long time. I can't ran Curtis' code. Does anymore have a code that works faster? Thanks Even if you used my current (10x-compatible) version (ftp://ftpext.usgs.gov/pub/nonvisible/cr/nact) it would not be any faster than Jamie's code,as i also do one at a time. Have you tried Sue's tool? I haven't tried it yet, but it seems like a really good solution.
... View more
10-30-2012
09:14 AM
|
0
|
0
|
2374
|
|
POST
|
I need to see is a log showing the success or failure of the Python portion of the code. Is there a way of getting Python to dump a log file out to specific location while it is running in SAS? If "print" and arcpy.AddMessage() output is not captured by SAS, yes, the only thing left is to write a log file somewhere. You need a try/except to capture a message if the script fails, for example try: ... do your work ... except Exception, msg: errMsg = "script failed\n" + str(msg) # write a message to gp out arcpy.AddError(errMsg) # print a message to stdout print "** " + errMsg # write to a log file f.open("c:\\temp\\out.txt","w") f.write(errMsg + "\n") f.close()
... View more
10-29-2012
12:49 PM
|
0
|
0
|
1782
|
|
POST
|
Hi, Two years on - I have the same problem! Any calculation with Python gives me the error msg: Python Not Installed. Both ArcGIS 10 and Python are installed in C:/Program Files (x86). However I am on a network computer, and do not have a 😧 Drive! Would anybody know how I find out where ArcGIS 10 looks for Python on my computer, so I can copy-paste my Python folder there? Thanks! Sid. Sid, I think the easiest solution to this problem is (as admin) open Add/Remove programs and 1) uninstall any Python entries and 2) Open ArcGIS Desktop, do a Modify install and remove Python, then open ArcGIS Desktop, Modify, reinstall Python. It's generally a bad idea to copy/paste/delete Windows installed programs as there are lots of path settings behind the scenes that will be rendered incorrect!
... View more
10-24-2012
09:26 AM
|
0
|
0
|
3748
|
|
POST
|
I discovered a problem with TIN coordinate systems when importing a TIN using the LandXML to TIN tool. First the tool did not recognize the current output coordinate system environment, and to boot, the Define Projection tool does not work with TINs. This problem was verified with 10.0 sp5 and 10.1 SP1. NIM085938 Cannot use Define Projection Tool on TINs. NIM085906 LandXML to TIN tool is not respecting the environment setting for output coordinate system. Two workarounds were identified: 1. Open the properties of the TIN and then manually define it 2. I wrote a little python function that works around the issue. (You could use this within a Python script, implement this as a script tool, or use it in ModelBuilder inside the Calculate Value tool.) import os
import shutil
import arcpy
def DefineProjectionForTin(tin,prj):
# workaround for a bug - define a projection for a TIN
# 1. Create a temporary raster
# 2. Define its projection
# 3. Copy the prj.adf file to the TIN
wks = os.path.dirname(tin)
tempGrid = arcpy.CreateScratchName("","","RasterDataset",wks)
arcpy.CreateRasterDataset_management(wks,
os.path.basename(tempGrid))
arcpy.DefineProjection_management(tempGrid,dataPrj)
shutil.copyfile(os.path.join(tempGrid,"prj.adf"),
os.path.join(tin,"prj.adf"))
arcpy.Delete_management(tempGrid)
return tin
# example usage
#
# Note you could have this be an argument
# to the tool of type "Coordinate System" and
# get it with GetParameterAsText()
#
# dataPrj = arcpy.SpatialReference(102003) # USA Albers CONUS
# DefineProjectionForTin(r"C:\Workspace\tins\bottom_temp1", dataPrj)
... View more
10-24-2012
09:12 AM
|
1
|
4
|
7337
|
|
POST
|
I don't know if it's a python issue or an ESRI/arcpy issue and I don't know why, but this last tidbit of info (try:except) solved a problem I've been having off and on for months. Halle-freaking-lujah ! Thank you. Even better is a try - except - finally, to make sure things are cleaned up no matter what happens. (Layers, table views, open files, cursors, etc.) For example:
try:
lyr1 = arcpy.MakeFeatureLayer("myfile.shp","myLyr")
# ... do stuff with lyr 1
except:
# ... do stuff you want to do if it fails
finally:
# do stuff you want to do no matter what, for example, try to delete the layer:
try:
arcpy.Delete_management(lyr1)
except:
pass
... View more
10-24-2012
07:45 AM
|
0
|
0
|
3491
|
|
POST
|
We are trying to set up an automated processing environment for our data (which includes TIN datasets), so any documentation that lists out any rules for TINs would be very helpful. For historical reasons, the naming rules for TINs are similar to the naming rules for coverages. The long pathname issue isn't intrinsic to TINs -- many tools can be broken by excessively long pathnames. You mentioned issues with spaces in paths. I have found with raster datasets that you can sometimes avoid problematic path issues by making sure your script passes layers, not datasets, as tool input (assuming the tool will accept a layer). This hides the path so it isn't accessed until it gets down to the arcobjects code inside the tool. In some situations this has allowed the paths to work when the raw dataset path has not. Unfortunately, i don't think there is a "Make Tin Layer" tool, though you can create a .lyr file from a TIN layer in ArcMap.
... View more
10-23-2012
10:38 AM
|
0
|
0
|
980
|
|
POST
|
Have any of you tried rebuilding statistics on the slope raster first?
... View more
10-19-2012
07:49 PM
|
0
|
0
|
1722
|
|
POST
|
Today I got a message script tool working along the lines of the one discussed in the ArcGIS Blog for use in generating messages inside ModelBuilder. First, an example of how it works, set up as a script tool with two text arguments, the first "MESSAGE","ERROR","WARNING", the second your message. What's new about this one over the one linked from the blog is that with this version, you can do error codes by using the format: "id arg1,arg2". (Sure would be nice if a tool was provided that does this in ModelBuilder.) Updated for ArcGIS 10x / Pro - currently testing
Executing: Message WARNING "id 591 First,Last"
Start Time: Thu Oct 18 11:58:10 2012
Running script Message...
WARNING 000591: First parameter not Last.
Completed script Message...
Succeeded at Thu Oct 18 11:58:10 2012 (Elapsed Time: 0.00 seconds)
#
# GP Script tool - Message
# for use in ModelBuilder
import arcpy
# Two text parameters:
# 0) Message type: ERROR, INFORMATIVE, WARNING
# 1) Message text
msgType = arcpy.GetParameterAsText(0).upper()
msgText = arcpy.GetParameterAsText(1)
try:
# id message, format: "id 345 arg1,arg2"
if msgText[:2].upper() != "ID":
raise Exception
else:
msgList = msgText[3:].split()
msgID = int(msgList[0])
# pick up arguments, comma-separated
msgArgs = " ".join(msgList[1:]).split(",")
msgArgs = [msgType, msgID] + msgArgs
arcpy.AddIDMessage(*msgArgs)
except:
# text messages (no ID message)
if msgType == "WARNING":
arcpy.AddWarning(msgText)
elif msgType == "ERROR":
arcpy.AddError(msgText)
else:
arcpy.AddMessage(msgText)
arcpy.SetParameterAsText(2,True)
... View more
10-18-2012
10:16 AM
|
1
|
4
|
6477
|
|
POST
|
I wrote some tools along these lines, and used Windows TEMP. In ModelBuilder, I got the path from the system environment variable TEMP using the Calculate Value tool. Set the output data type to Folder. Expression: env("TEMP") Code Block: def env(envVar): import os return os.environ[envVar] If you're python scripting, just use os.environ tmpXML = os.environ["TEMP"] + "/" + "xxtemp.xml"
... View more
10-15-2012
04:04 PM
|
0
|
0
|
1673
|
|
POST
|
Scratch that. Just need to know why the Aggregate Points tool outputs a different attribute table when used in Model Builder and when used outside of model builder. I need the Shape_Area attribute field, for selection purposes, in model builder and it is not there, along with Shape_Length. (Only returns ID and Shape). Dale wasn't totally clear on that. Geodatabase feature classes automatically create Shape_Area and Shape_Length fields when they are created. Shapefile output doesn't have either of these fields. make sure that the output of Aggregate Points is being written to a geodatabase (file or personal--I recommend personal) Really Dale - that's the first time i've heard personal geodatabases recommended! Care to elaborate?
... View more
10-15-2012
03:54 PM
|
0
|
0
|
940
|
|
POST
|
This is a feature of Python 2.x. When you divide two integers, you will will get integer output: >>> 1 / 2
0
>>> 1 / 2.0
0.5
>>> float(1) / 2
0.5
(post #1000!)
... View more
10-15-2012
03:43 PM
|
0
|
0
|
462
|
|
POST
|
There appear to be 3 (!) installs of Python on the system. One in C:\Python27, one in C:\Python27\ArcGIS10.1, and one in C:\Python27\ArcGISx6410.1. My main issue is in Desktop, I can't use any Python functions, because whenever I try to import arcpy, it can't find numpy. The Python27/ArcGIS10.1 installed with Desktop, the Python27/ArcGISx6410.1 is installed with either Desktop x64 background GP, or ArcGIS Server. I don't know how the third one got installed. I'm guessing last, because Windows is clearly set up to have that Python in the path. Sounds to me like the best approach is to uninstall the python installed in C:\Python27. (It will be in Add/Remove Programs) Then do a repair install of Desktop and Workstation (from add/remove programs). (Note, cross post to https://community.esri.com/groups/arcgis-for-desktop-installation-support?sr=search&searchId=9e9fd9be-e541-4f8f-a0c7-fa7183d43b18&searchIndex=0 (Bonus question: What's the 'C:\\Windows\\system32\\python27.zip' doing there?) This is a deprecated path from the early days of Python before the current setup (startup scripts, PYTHONPATH, site-packages) was implemented for startup.. You can safely ignore it.
... View more
10-15-2012
03:34 PM
|
0
|
0
|
4961
|
|
POST
|
Ok, that explains why the setting has been reset when I reopen the tool. Environment set from the tool with th Environments button only apply to that run of the tool -- if you open the tool again from the search box or toolbox, all the environments are set new from the application environment. However the environment is saved in the results, so the environment are "remembered" if you open the tool from the Geoprocessing Results window. Shouldn't it still run as I've specified right when I set it? Yes it should. Provided the particular tool honors that environment setting. According to the tool ref (9.3 and 10), IDW does recognize the current mask setting.
... View more
10-09-2012
08:26 AM
|
0
|
0
|
1552
|
|
POST
|
The problem with overlapping polygons for Zonal Statistics is of the past. If you iterate over your features within a feature class and pass each one to zonal statists it works perfectly and writes out the results into a single table. If anyone would like I would gladly post my model. I wouldn't say it's a thing of the past. Setting up the model is not trivial for people new to ModelBuilder, especially how you aggregate the results. Please do post your model, IMHO this is a good "real-world" example of how iteration can be used to great advantage in Arc 10. The tool Sue just posted is better than a brute-force iteration though - it separates your overlapping polygons into non-overlapping groups - if you have thousands of overlapping polygons, this could mean a few hundred iterations instead of thousands.
... View more
10-09-2012
08:05 AM
|
0
|
0
|
2843
|
|
POST
|
row.top = str(arcpy.GetRasterProperties_management(raster, "top")) Thanks, Jake, I learned something new today. If you str() a result object, you'll get a string representation of its the result's value. If you know this is a single value and what type it is, this does make for a simple way to get the value:
>>> r = arcpy.GetRasterProperties_management("cdl20091.tif","top") # result object
>>> r
<Result '3173073.79641599'>
>>> r.getOutput(0) # result object output
u'3173073.79641599'
>>> str(r) # returns string rep of result output
'3173073.79641599'
>>> float(str(r)) # convert to float
3173073.79641599
... View more
10-05-2012
11:28 AM
|
0
|
0
|
1999
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 08-11-2021 01:26 PM | |
| 5 | 12-10-2021 04:58 PM | |
| 1 | 02-27-2017 09:30 AM | |
| 2 | 12-04-2023 01:05 PM | |
| 1 | 04-12-2016 10:17 AM |
| Online Status |
Offline
|
| Date Last Visited |
06-19-2024
12:10 AM
|