As a result for my graduation paper I am trying to create a new toolbox for ArcGIS using Python scripting. The problem is I am stuck with my code because none of the existing functions in Arcpy does what I need to do. So my question is, is it possible to create a new function in Arcpy or this is restricted to ESRI developers?
Another way to solve this problem would be implement some changes in the tool Cost Distance from Spatial Analyst. So my other question is, do I have access to the coding of the native tools from ArcGIS? And if I have, can I change it to achieve my goal? Or this is also restricted?
Thanks,
Gabriel
You can create your own functions using Python and the Python arcpy site-package. All of ESRI's tools are proprietary, and therefore, most have restricted access. You can check to see if you can edit the tools in the ArcToolbox. For example, you can see the Cost Distance tool is restricted:
While the Spline with Barriers tool can be edited by right-clicking on the script tool.
You can create your own python toolbox for ArcPy following this help: http://resources.arcgis.com/en/help/main/10.2/index.html#//001500000022000000
also checkout the environment variables for your existing tool, it might have some options that you are looking for.
I know this is a year late, but I would like to add a couple ideas to what has been posted for folks like me who are searching for python toolbox help.
For educational purposes, begin by creating a model in Model Builder. This is one way to use ESRI's proprietary tools in new ways. Decide what you want to do and look at ESRI's presence on GitHub. The developers there have a lot of open-source tools ready to use in ArcMap. Here is one such repository: GeospatialPython
Side note, contributing to a repository is a great resume builder.
After creating your working model builder, right click on it in ArcCatalog and select 'export as Python script'. Open the script in your favorite IDE and begin cleaning it up!
Now that you have a python script, it is ready to become a python toolbox. Use gDexter42's link and get to work on that.
My team has some interesting uses for python toolboxes and I am currently creating my very first one.
We use a runner scripts to debug our software. (hard-coded parameters)
We use inheritance for functions that we use over and over again (class BaseToolboxMixin(object):) Stack Exchange Article on Mixins
Most importantly, we have created our own python module around the tool.
The .pyt file we made simply imports arcpy, the module we created, executes the module from a list we created in our 'toolbox_loader.py' file, and has a class that calls the init file that created the module in the first place. >20 lines of code.
As our team creates more tools for the module/python toolbox, we will add them to the list. They will appear inside our toolbox alongside all the ESRI tools. "Seamless integration" was thrown around a lot at the Dev Summit this year.
ESRI is encouraging creativity and open-source usage (check out esri leaflet). I wouldn't constrain my thinking because ESRI's tools are proprietary.
All of this functionality began as a model in ArcMap. Not everyone is going to need to create their own module - complete overkill for most tasks - but it is good to know that the ceiling for Python functionality is high. I am not an experienced developer, but I was able to go from nothing to a functional python toolbox in about 25 man-hours of work. Someone who knows their stuff could do it in a morning.
Related
I have written a Python script which models an academic problem which I wish to publish. I will put the source on Github and some academics that just happen to know Python may get my source and play with it themselves. However there are probably more academics that may be interested in the model but that are not python programmers and I would like them to be able to run my model too. Even though they are not programmers they could at least try out editing the values of some of the parameters to see how that affects the results. So now my question is how could I arrange for a non-python programmer to run a Python program as easily (for them) as possible. I would guess that my options may be...
google colab
an online python compiler like this one
compiling the program into an exe (and letting the user set parameters via a config file)
something else?
So now a couple of complications that makes my problem trickier.
The output of the program is graphical and uses matplotlib. As I understand it, the utilities that turn python scripts into exe files struggle or fail altogether when it comes to matplotlib.
The source is split into two separate files, one small neat file which contains the model and the user might like to have a good look at it and get the gist of it even if they're not really a python programmer. And a separate large ugly file which just handles the graphics - an academic would have no interest in this and I'd like to spare them the gory details.
EDIT: I did ask a related question here - but that was all about programmers that won't mind doing things like installing python and using pip... this question is in relation to non-programmers who would not be comfortable doing things like that.
Colab can handle the 2 problems, but you may need to adapt some code.
Matplotlib interface: Colab can display plots just fine. But you may want user to interact with slider, checkbox, dropdown menu. Then, you need to use Colab's own Form UI, or pywidgets. See an example here
2 separate python files: you can convert one of them to a notebook. Then import the other. Or you can create a new notebook that import both files. Here's an example.
For my bachelor thesis I have to convert DICOM data to a 3d model and import this into unity so I can create a virtual reality. So the data out of 3DSlicer has to be updated in Unity automatically. You can say I have to link the two programs. What do you think is the best way to do this? Should I create a Matlab or Python module or is there a better way?
I am sorry if there is already a similar question but I have searched for answers on the internet and unfortunately I couldn't find an answer.
I would really appreciate your help.
Since slicer is compatible to python codes. you can try to access to the unity codes, if you use ubuntu it is probably easier to use a shell script to call the unity functions you need withing the python codes of slicer.
I did it with ANSYS softwares to link two different softwares together and export an output from the first software and pass it to the second software.
Rather than this automatic way, this is a guideline about how to export data from other apps to Unity
https://docs.unity3d.com/Manual/HOWTO-exportFBX.html
I'm exploring 2D interpolations for the purpose of writing a script in Python. I've been using the PIL (Pillow) modules to quickly display the results of the algorithms - this is best for cases when interactive input isn't necessary (i.e. testing on a random set of points).
For interactive testing I've found jsfiddle to be the most lightweight solution, but I admit it isn't ideal to rewrite functions in another language merely to be able to move points around, and input specific shapes of quads.
simple example, 4 verts drawn at random (JavaScript in JS fiddle; would like to do the same in Python)
What would be a fastest way to play around with a Python script graphically? Is there a Python counterpart of jsfiddle? I googled 'Python fiddle', of course, but it's not what I'm looking for. What I need is a simple canvas implementation and click events support.
Thanks in advance,
Well, there is Python Fiddle, but I think this question is going to be closed by admins as being off-topic on Stack Overflow; see this thread here.
I'd also come to think of Jupyter and Anaconda. The latter includes the former. These will harness matplotlib, amongst others, and Jupyter gives you a Matlab-like interpreter that shows you variable values for each line and you're able to step by step look at those variables and any graphs you are making.
As mentioned in previous answer, there is Jupyter notebook – a software for interactive Python programming including graphical output.
You can run Jupyter locally or on your own server, but there are free cloud versions:
https://colab.research.google.com/
https://notebooks.azure.com/
Hello Python developers!
I'm a Java one and I know that there is a way of running Java code on the fly, but my question is, is there any way to do that with Python?
The main goal here is to enable middle-school students to start coding with chromebooks from day one on Python.
I've been looking for some resources, but I got nothing so far.
Thanks a lot!
http://shell.appspot.com might be of your interest. (there's a link to the source code too)
Hey, I just recovered a link to a nice page I used in the past. It shows the execution flow of a Python script. Students I taught found it very useful in terms of comparing with other languages they new already, e.g. Java, how stack and arguments are being passed to the functions, memory allocations, etc:
http://people.csail.mit.edu/pgbovine/python/tutor.html
(click on "Visualize execution" button beneath the window with the code)
IPython allows you to run python interactively from a web environment. You can try a demo here: IPython. You can set this up on a local computer and have you students view it from their machines.
Coderbuddy let's you create and run AppEngine applications online, without having to download the AppEngine SDK, Python, or anything for that matter.
I use that when I do workshops, so I don't have to bother with making sure that everyone has the SDK and proper configurations in their machines. We just go straight to coding. :)
im willing to create a project same as JUNOS cli or cisco cli,
I came through gnu readline, but im confused as there are too many functions and methods to implement. any how i want a cli with auto complete using tab and space bar with question mark to display commands with help text.
I have two questions :
I have found code in python and perl but the im not use to python that code is complete and i just want to know if i should continue with python. im more experienced in perl but the code i found so far isn't complete for perl.
readline.parse_and_bind('tab: complete')
should i use the same complete function for both help and autocomplete feature. where as i have gone through another function
readline.set_completion_display_matches_hook(print_suggestions)
what you suggest :P im completely new to it!
I must say that I struggle to understand which specific point you are addressing in your question. But here is a suggestion anyway:
Start out with the cmd module. It gives you a nice little framework to build a command-line interpreter. It supports tab completion out of the box (provided readline is available). Start implementing your command-line interface. Once this stabilizes you can think about adding more comfort, e.g. tab completion for command arguments, help keys, and the like. This way, you have a working app to deal with, and can address readline details more specifically when you really need them. I wouldn't wade through the whole readline API upfront, if I were in your shoes.
We had to create a cli like JunOS/Cisco/VyOS and we built it on top of ishell, which uses readline for this job.
From the project page:
ishell helps you to easily create an interactive shell for your application. It supports command completion, dynamic arguments, a command history, and chaining of commands.
You can check the project at github: https://github.com/italorossi/ishell
Cisco example:
PS: I'm the author :).