I recently posted this thread in the geoprocessing forum with not much response.
I have tried to soldier on but keep hitting issues. Everything I know about Geoprocessing and Python I have hacked together from google searches.
Would someone please be able to take a look at my script here and see where it is going wrong? In short I am trying to test my theory that I can pass in an XY and a list of id's as two parameters. then create a point based on the xy and a select on my feature class where the id's are equal to the id's passed in and then use the result of the above 2 operations as inputs for a call to the "generatenear" tool to get the distances from my XY to all the selected features. I'm sure this should be pretty straight forward but my python skills aren't up to the challenge.
I have tried to use the in_memory workspace and this seems to be the cause of most of my problems! I have hardcoded the values for the origin point and some feature id's but in the real version these would need to be passed in parameters from a call to the python script. The intent is to publish the script as a GP tool so it can be consumed via REST by one of our company websites. Some pointers, links to relevant tutorials info etc.. would be greatly appreciated:
I appreciate you guys aren't going to write the code for me, but I am struggling a fair bit. Am I far off? I don't get any errors but the output in the IDLE debugger window is:
How do I check if there is something in myOutput and how would I expose this so it can be consumed by a REST get operation?
GP services can be quite tricky....
Just had a very brief look at your code. I do not see where it is returning anything? Where is the output to go back to the client. And if this is a table, how is the client supposed to use it?
And BTW I don't think you need coords specified down to the sub-atomic level.
xy = (414038.9985242901,130874.00962267019)
thanks for your comment. The co-ords are as returned by another REST call to the findaddresscandidates service that we already have published. The end user inputs a postcode the client calls to the service returns the XY and this would then be used as the first passed in parameter for my script
Nice to see the good old British National Grid but boy this is a loaded question. Almost all the advanced topics in one. I suggest some changes in the attachment but you still have a long way to go.
Some key points are:
Well... not to discourage you. I did this kind of thing before and it kinda worked, but we never used it in production. It was like scratching your left ear with your right hand behind your head.
You may want to consider publishing both the data and the Generate Near Table tool as services and using these in the client fully over the RESTful interface.
thanks for the feedback. Guess this was simple in explanation only, the execution not so simple huh! I did consider publishing the generatetool as a service as - as you point out if I already have a rest end point to accept the postcode and get an XY and I publish the featureset as a service which could be queried with a select using the passed in ID's - the inputs for the generatenear can all be gotten in REST and then it would be a 3rd call to do the distance calculations. the issue I hit pretty quickly was generatenear needs its inputs as features but a simple XY is not a feature.
I figured if I had to do more geoprocessing to take an XY and make it a point in a feature class that I might as well go the whole hog and do the lot in a script.
If you (or anyone else!) have any tips on the easiest way to publish the generatenear as a REST service so I can leave everything up to the client and just make a bunch of resources available over http then I'd love to hear them.
A few things I notice; do you want to return the results of the table to the client? In which case you'll need to use arcpy.SetParameter, assign it the next parameter, and then set what you want returned, arcpy.SetParameter(2,myOutput). You don't need to use your own try: except block unless you're going to catch the exceptions properly and return the messages. I would get rid of the try: except block and let the GP framework return the error for you. Also, print statements won't work in a tool. You'll need to use arcpy.AddMessage(). Finally, what problem are you running into with the tool?
Thanks very much for your reply. I was running the script above just as a script in IDLE initially so as to check if it works before wrapping it in a tool and publishing it. Yours and Filips input has been very helpful.
The issue I seem to be hitting is getting the generatenear tool to actually work. It doesn't seem to like the inputs.
I have just tried publishing the generatenear on it's own, with inputs coming from dummy features I created in a gdb just to see if I can get it to work and then view the resultant python script.
This is where I hit my newest problem - which is that we are on Server standard here and I just found out that to publish advanced geoprocessing tools you need Server advanced or at a minimum the spatial analyst server extension. Hopefully this is useful to anyone else stumbling across this thread. I will update this thread as we get nearer to a solution
Thanks to everyone who has offered input and advice so far.