|
POST
|
2CDSD 2C, for future reference with posting code Posting Code blocks in the new GeoNet For me, what works best is copying it over first, then applying the syntax to the block I just copied over...which is what Curtis shows in the blog. It never seems to work for me if I try to fix it after it is formatted on GeoNet.
... View more
07-08-2015
03:16 PM
|
0
|
1
|
3157
|
|
POST
|
Thanks Steve, Many good tips there that I wil check out. I actually will possible create (now) five or six different types of transects that depend on the terrain quite a bit (i.e. how super cubs can fly)....one of the new options was first talked about this morning In the Avenue program I have only three (contour, straight and straight-hinged), but there were a few areas that seemed to get under sampled. I'm still working on the logic (both from the needs of the biostatistician and program side) since breaking the logic of each step makes life much easier once I start putting all the pieces together. This has always been a great project to play with new challenges. One of the nice things is I've been here from the start of design and running of this project (1992-ish) so I've very in tune with it. But I wouldn't doubt throw I'll throw some additional questions out here when I run into roadblocks. It's usually only run every few years, so super efficiency isn't required, but I can see the transect part being used more often by other project if I do it right. Eventually, I'll have all the script in toolbox and a python addin (not to be confused with a python toolbox). FWIW.
... View more
07-08-2015
03:10 PM
|
0
|
0
|
2596
|
|
POST
|
Thanks Steve. I will give that a try, but that may require me to move the random seed point (x/y) since that is used, (more-or-less, may slide to stay in study area), as the center point of the transect. I'll have to make sure that doesn't negatively impact the intent of the randomness. I will be processing one random point at a time, and will only need about 20k of the contour (10k either side of point, along contour....adjusted if it hits the study boundary). I'm thinking about trying to maybe use an in_memory version of the raster, maybe clipping the raster to an extent 40k on either size of the point. I'm not sure if this is possible, but I would think a smaller raster extent would speed up the process. Just thinking "out loud"..One thing the ContourList command may help with is locating "continuation" contours, for example, when the contour is < 20k (e.g., close to top of mountain). In that case, the plane goes off transect, and restarts on another mountain at same elevation. If I can choose a second contour line for them to continue, it can take some of the human influence out of the randomness. (if that makes sense) I have most of my logic (except the "continuation" option) already written in my Avenue program that I'm translating. But I have to say, ReturnContour in AV3.x works much faster than ContourList at least without setting up environments....so I will try your suggestion. EDIT: Steve, as you mentioned, the SnapRaster really sped up the process (to < 15 seconds), and the contour results are the same. The point isn't on the contour itself, in either case, but I can adjust that as needed. On to the next step. Thanks for that hint!
... View more
07-08-2015
09:11 AM
|
1
|
2
|
2596
|
|
POST
|
z1 was just one point, which was what I need. Anyway, it just finished.....about 10 minutes to run the one point/elevation. I'll have to work on speeding it up since I could easily have 2000 or more to run. It of course returns too much right now, but that again is something that I can work on. Thanks Dan, that was exactly the push I needed in the right direction!
... View more
07-07-2015
07:23 PM
|
0
|
4
|
2596
|
|
POST
|
Thanks Dan. I had noticed that command, but didn't look at it close enough, but it looks promising. I added outCountor = r"C:\ADFG.gdb\c1"
from arcpy.sa import *
ContourList(theDEM, outCountor, z1) And it hasn't crashed....might be an overnight run. But if that works, I'll have to work on getting the extent to be much smaller that it is right now (about 12,100 sq mi...110x110) Thanks for the fast feedback....this really is a great community.
... View more
07-07-2015
07:16 PM
|
1
|
6
|
2596
|
|
POST
|
I’m working on updating one of my old Avenue scripts. Short description (of this particular problem in a longer process): given a set of random points within a study area, I need to create a contour at the elevation value of the random point, and using that as the center, create a transect on that contour at a given length, 50% in each direction….adjusting if necessary to keep within the study area. (and there are other factors I don’t need to get into right now). I’ve been able to grab the xy from a given point, and retrieve the value from the raster. The problem I am having right now is I can’t find an arcpy replacement for ReturnContour (as shown in this line) theFullContour = ElevTheme.GetGrid.ReturnContour(p, z, Prj.MakeNull) My guess is it a NumPy solution (Dan Patterson maybe??), but I’m not sure what to search for. Once I get the (poly)line, I should be ok with geometries.) Does anyone have a simple way in python to return a single contour given an x/y/z and a raster? Anyone in Geoprocessing or Imagery and Rasters ?? Please, python solution only....no C#/arcobjects. Thanks! EDIT: meant to include a snippet of test code for getting the point, in case anyone wants to test on their own data. I'm grabbing point 7 of 2000 because I know it will return a good contour (some will not....too flat, which is handled elsewhere) myPoints = r"C:\ADFG.gdb\myRandomPts2"
theDEM = r"C:\ADFG.gdb\DEM20aExtent"
cnt = 1
for row in arcpy.da.SearchCursor(myPoints, ["SHAPE@XY"]):
if cnt == 7:
x,y = row[0]
print("{}, {}, {}".format(cnt, x, y))
else:
pass
cnt = cnt + 1
#x, y = 377906.9379, 1538997.6698
print("{}, {}".format(x, y))
ptLoc = str(x) + ' ' + str(y)
z1 = arcpy.GetCellValue_management("DEM20aExtent",ptLoc)
print(z1) Message was edited by: Rebecca Strauch added code snippet
... View more
07-07-2015
06:46 PM
|
0
|
8
|
5363
|
|
POST
|
Xander, I would have to agree with you on the MB to Python ugliness. For what it's worth, I found this blog earlier today (old post) Considerations when exporting a model to a Python script | ArcGIS Blog
... View more
07-07-2015
04:13 PM
|
1
|
3
|
3148
|
|
POST
|
Lela, in my workflow I'm usually running one script (from either a custom Toolbox or a Python addin I created), because I typically want to look at the result before I run the next. However, you can stack up scripts, models, tools, etc and the will process in order, however, if there is an error in the first, it may not stop the second from running.. But there are many threads out there on the subject, and a quick search came up with arcgis 10.0 - ArcPy and running Python scripts (with parameters) within another Python script - Geographic Information S… It's 10.0, but I'm sure its about the same for any 10.0+. When looking at some of the comments on that page, it referenced a broken link to a blog from Jason Pardy which lead me to search the blog, and although I didn't find the one references, I did find another Considerations when exporting a model to a Python script | ArcGIS Blog which looks like something you should look at. I'm also interested in finding an answer to your question....not that I need it right now, but always good to know. I use Geonet to research many of my questions....but doing a straight browser search can give you many leads too. But there may be others here that have better ways. Many tools in the toolbox! (thankfully!) EDTI: looks like Jeff already provided an answer.
... View more
07-07-2015
01:39 PM
|
1
|
0
|
2755
|
|
POST
|
Guy, for the agenda on the PC/browser no plug-in is required, but the planner isn't there. It does take a bit for the agenda to "download" before it shows (20 seconds for me, on a fast connection)...wait until disappears...then the agenda is there. The pocket pdf is handy to view on the pc or on a pad...(.my guess is they will still hand those out at the conference). FWIW, I'm finding the app on the ipad is working great, but still use the PC as a second screen for scrolling through the sessions...and that doesn't help anyone without a mobile device.
... View more
07-07-2015
08:18 AM
|
1
|
3
|
2573
|
|
POST
|
Shawn, You didn't mention which API or web app tool your are working with. Assuming it is JavaScript, are you working with Web Application Builder for developers? If so, there are several custom widgets that are close, if not exactly what you are looking for. For example Measure Widget 1.1.1 for Web App Builder others can be found Web AppBuilder Developer Edition &#8211; Customization Resource List in any case, it would help others to know the development environment you are using, and if you Moving Content to a location that fits, you may get more specific help. E.g. Web AppBuilder Custom Widgets Web AppBuilder for ArcGIS (more for the ArcGis online version) or any number of sub places Web Developers
... View more
07-06-2015
10:47 PM
|
1
|
0
|
1143
|
|
POST
|
I'm not one to answer this in full, but I have a few files that I read in each time (thanks to Freddie Gibson and/or Jeff Barrette ) that take care of a few things for me. a util file that takes care of the arcpy.AddMessage vs. the debugging print statement; appends a datetime to the message (since that isn't always done), and creates a log file. (mine is called ADFGutils.py) a "decorator" file that takes care of the try...except part for me. (gpdecorators.py) These can be place in the (example) c:\Python27\ArcGIS10.3\Lib folder, or in another relative location to your calling script. the ADFGutils.py (...named for my dept, but you can name whatever you want) call in your program: from ADFGutils import * Use similar to print or arcpy.addMessage (may duplicate the message in some debuggers) myMsgs() import time
import arcpy
import os
from time import localtime
def timeStamp():
"""
returns time stamp.
"""
return time.strftime(' -- %B %d - %H:%M:%S')
def myMsgs(message):
arcpy.AddMessage(message + ' %s' %(timeStamp()))
print(message + ' %s' %(timeStamp()))
global messageCount
logFolder = r"C:\ESRITEST"
if not arcpy.Exists(logFolder):
arcpy.CreateFolder_management(os.sep.join(logFolder.split(os.sep)[:-1]), logFolder.split(os.sep)[-1])
mdy = curDate()
logName = "logfile_" + "_".join(mdy.split("/")) + ".log"
logFile = open(os.path.join(logFolder, logName), "a") #a=append, w=create new
if message.lower() == "blank line":
logFile.write("\n\n")
print "\n\n"
elif message.lower() == "close logfile":
logFile.write("\n\n***** finished *****\n\n")
logFile.close()
else:
messageCount += 1
logFile.write("0" * (5 - len(str(messageCount))) + str(messageCount) + ". ")
logFile.write(message)
logFile.write("\n")
#print message
#arcpy.AddMessage(message)
def curDate():
rawTime = localtime()
yr = str(rawTime[0]) # Collect the year from the rawTime variable
mo = str(rawTime[1]) # Collect the month from the rawTime variable
dy = str(rawTime[2]) # Collect the day from the rawTime variable
return "/".join([mo, dy, yr])
messageCount = 0
The gpdecorator.py To call in your program from gpdecorators import * To use....at the # catch_errors decorator must preceed a function using the @ notation. @catch_errors def main(): """ Main function to create the new master feature dataset. """ # Script arguments... '''.......your program''' myMsgs('!!! Success !!! ') # End main function if __name__ == '__main__': main() """
A decorator to wrap error handling.
"""
import sys as _sys
import traceback as _traceback
import arcpy
def catch_errors(func):
"""
Decorator function to support error handling
"""
def decorator(*args, **kwargs):
"""
Decorator function
"""
try:
f = func(*args, **kwargs)
return f
except Exception:
tb = _sys.exc_info()[2]
tbInfo = _traceback.format_tb(tb)[-1]
arcpy.AddError('PYTHON ERRORS:\n%s\n%s: %s\n' %
(tbInfo, _sys.exc_type, _sys.exc_value))
print('PYTHON ERRORS:\n%s\n%s: %s\n' %
(tbInfo, _sys.exc_type, _sys.exc_value))
gp_errors = arcpy.GetMessages(2)
if gp_errors:
arcpy.AddError('GP ERRORS:\n%s\n' % gp_errors)
print('GP ERRORS:\n%s\n' % gp_errors)
# End decorator function
return decorator
# End catch_errors function
if __name__ == '__main__':
pass That may not be all your colleague was pointing out, but I know those help me. These most likely could be in one file, btw, but I've never combined them. fwiw.
... View more
07-06-2015
04:00 PM
|
1
|
0
|
1931
|
|
POST
|
must have been short lived...or the link is incorrect. Can you check again Amanda?? I would like to grab it!
... View more
07-06-2015
01:53 PM
|
0
|
3
|
2401
|
|
POST
|
Jim, if you have your own source data for the basemap, you can always create your own basemaps. What they were talking about above is basically "caching a cache", or capturing the ArcGIS Online basemaps for internal use. If you need to be totally inside your firewall, you should look at installing Portal ArcGIS for Server | GIS Web Server Software | Web Map Server I'm not sure if you have access to the esri basemaps that way, but you might be able to create your own from the esri data disks, depending o what detail you are using. But being that you are working for a hospital, my guess is you will want more localized and more detailed data for your basemap.
... View more
07-06-2015
12:52 PM
|
1
|
3
|
7505
|
|
POST
|
Hi Shafi, The tool I use is the stop/start/delete tool in the ArcGIS Server Administration Toolbox http://www.arcgis.com/home/item.html?id=12dde73e0e784e47818162b4d41ee340 by Kevin Hibma I haven't finalized/generalize my scripts yet to incorporate this script into a Stop/Replace/Start routine, so I do it in three steps. Run the script to stop, then do my renaming/replacing to the new FGDB that I already did all the magic to, then run the script to start every thing up again. Downtime can be minimized this way. For my use, I've updated the parameters so I could hard code a default server-name, port, admin account. Once I enter the correct password, the Service List is populated so I can select what I services I would like to stop/start. The script (with a little added comments): '''
This script will stop or start all selected services selected after valid ServerName,
Port, AdminUser, AdminPassword, action (Stop/Start/Delete) are entered, and
services from populated service list are selected
Parameters required:
- ServerName
- Port
- AdminUser
- AdminPassword (SENT IN CLEAR TEXT! and will show in Results tab)
- Stop or Start (or delete....caution with this one...can leave option off ValueList if desired.)
----- Service(s) (multivalue list) ....this will be populated after above are input...
use check boxes to select those you want action to be applied to
Functions:
- gentoken (creates token required for Admin changes)
- stopStartServices
'''
import urllib, urllib2, json
import arcpy
# Functions:
def gentoken(server, port, adminUser, adminPass, expiration=60):
#Re-usable function to get a token required for Admin changes
query_dict = {'username': adminUser,
'password': adminPass,
'expiration': str(expiration),
'client': 'requestip'}
query_string = urllib.urlencode(query_dict)
url = "http://{}:{}/arcgis/admin/generateToken".format(server, port)
token = json.loads(urllib.urlopen(url + "?f=json", query_string).read())
if "token" not in token:
arcpy.AddError(token['messages'])
quit()
else:
return token['token']
def stopStartServices(server, port, adminUser, adminPass, stopStart, serviceList, token=None):
''' Function to stop, start or delete a service.
Requires Admin user/password, as well as server and port (necessary to construct token if one does not exist).
stopStart = Stop|Start|Delete
serviceList = List of services. A service must be in the <name>.<type> notation
If a token exists, you can pass one in for use.
'''
# Get and set the token
if token is None:
token = gentoken(server, port, adminUser, adminPass)
# Getting services from tool validation creates a semicolon delimited list that needs to be broken up
services = serviceList.split(';')
#modify the services(s)
for service in services:
service = urllib.quote(service.encode('utf8'))
op_service_url = "http://{}:{}/arcgis/admin/services/{}/{}?token={}&f=json".format(server, port, service, stopStart, token)
status = urllib2.urlopen(op_service_url, ' ').read()
if 'success' in status:
arcpy.AddMessage(str(service) + " === " + str(stopStart))
else:
arcpy.AddWarning(status)
return
if __name__ == "__main__":
# Gather inputs
server = arcpy.GetParameterAsText(0)
port = arcpy.GetParameterAsText(1)
adminUser = arcpy.GetParameterAsText(2)
adminPass = arcpy.GetParameterAsText(3)
stopStart = arcpy.GetParameter(4)
serviceList = arcpy.GetParameterAsText(5)
stopStartServices(server, port, adminUser, adminPass, stopStart, serviceList) EDIT: I should add, that my scripts to create my new FGDB and feature datasets, and all the scripts to pre-process the data are so specific to my datasets, that they would not help you. But if you have specific things that you have questions about, I may be able to supply snippets...and if needed, you may need to break them off to new questions.
... View more
07-06-2015
10:01 AM
|
1
|
1
|
1736
|
| Title | Kudos | Posted |
|---|---|---|
| 1 | 02-08-2018 08:21 AM | |
| 1 | 10-07-2015 09:48 AM | |
| 1 | 10-25-2015 12:23 PM | |
| 1 | 11-02-2017 09:00 AM | |
| 1 | 11-04-2016 02:11 PM |
| Online Status |
Offline
|
| Date Last Visited |
03-31-2025
04:56 PM
|