Transcript
00:01Hi. Welcome to Using Geoprocessing Services.
00:03So some of you may have come to the session we did yesterday, and we talked about creating services using desktop to publish it...
00:11...and this session's going to talk about how do you write web apps using JavaScript, Flex, and Silverlight.
00:20I think, you know, the things to think about here are the...no matter what language you're using...
00:27...the patterns and the way that you use it is the same.
00:29You know, all...you know, across all the languages.
00:32So we don't do a separate session for each of the language types, because there's just so much overlap between them.
00:39So even if you don't see the language that you're using, the patterns and the way that you program it is the same.
00:46So it's applicable.
00:47So the programming patterns are the same, and also the application patterns are the same in the way that things get used.
00:55So with that, actually, my name...I'm really sort of mostly on there for name.
01:00Monica's going to do most of the presentation and walk through the applications and how they work.
01:09Hey, good evening all.
01:11I'm Monica Joseph, and I'm a product engineer at geoprocessing services team. I work with Scott.
01:18How many of you actively use geoprocessing services in web applications?
01:26Okay, a few of them. Okay.
01:28And just to get a feel for it, how many of you are Python and ModelBuilder...
01:32...you're familiar with Python and ModelBuilder?
01:36[Inaudible]. Okay.
01:38And how many of you use Flex API?
01:42Okay. JavaScript?
01:46Good, because most of the samples today are going to be on JavaScript...
01:49...but the application patterns and how you use it, do it, they're all same across all APIs.
01:55So let me not leave out Silverlight API.
01:58How many of you [use] Silverlight API?
02:00Okay. Quite a few of you. Okay.
02:03Okay. So what I'm going to do is just brush up a little bit on the basic concepts, and then we'll move on...
02:11...and we'll talk about 10.1, what we have done at 10.1, a lot of new enhancements, exciting enhancements at 10.1.
02:18We've tried to make it better for web application developers specifically so 10.1 looks very good, so.
02:25Have you tried 10.1 beta or prerelease?
02:28[Inaudible audience response]
02:29Prerelease. Okay. Okay. Okay. Okay.
02:34Okay. Let's get started.
02:36So what is a GP service?
02:38A GP service is nothing but a tool running on server.
02:42A tool is running on desktop, and it runs fine, and it's good, a model, a script.
02:47What you do is you publish it and then it goes to ArcGIS Server.
02:51Once it goes to ArcGIS Server, the functionality of the tool is available as geoprocessing REST service...
02:59...and you can use them in your JavaScript APIs, Flex APIs, Silverlight APIs, even mobile APIs.
03:07So most often, developers talk about geoprocessing tasks.
03:12They don't talk about geoprocessing service but geoprocessing tasks.
03:15A geoprocessing task is nothing but a set of tools that live within the context of a geoprocessing service...
03:22...and each task corresponds to a tool, and it has a unique geoprocessing functionality...
03:29...and each task has a REST URL, and this is the functionality that you will be using in your web applications.
03:39So to talk about little bit more about geoprocessing task, each and every task has task parameters.
03:47What are task parameters?
03:48They are very simple.
03:50They are input and output of a tool.
03:52So web application are clients and the input parameters to the server.
03:56The server runs the geoprocessing functionality based on the input that you provided...
04:01...and then what happens is it returns the output to the user or the client.
04:06So the two types are input and output parameters.
04:11Next thing is, what are the different task parameter types that we support, the inputs that you could pass in?
04:16They are restricted to a few types.
04:19Some of them are feature set, record set, rasters, linear unit, file, integer long double, date, Boolean.
04:29These are the only info data types that you can pass to the server, geoprocessing server.
04:37And there's another thing called task operation.
04:40So what is a task operation?
04:42A task operation is the one that allows you to run the tool.
04:47It's kind of a command line to run the tool, to ask the server to run the tool.
04:52So there are two types of operation.
04:54One is execute task, and the other one is submit job.
04:57So what is an execute task?
04:59An execute task is one request, one response model and usually used for really fast geoprocessing services.
05:09And the other one is submit job operation, and the submit job operation is for long-running processes.
05:16Think of it this way.
05:17Execute task is more or less like a fast-food restaurant.
05:21You go in, you check in, and you check out.
05:23So fast and real quick.
05:25Whereas in the case of submit job, it's more or less like a French restaurant you go to on Valentine's Day.
05:32You get a nice table, you sit down, you relax, you enjoy.
05:35And then when you come out, they also give you a doggie bag.
05:38So that's what submit job is.
05:41So we'll talk more about what happens behind the scenes in execute task and submit job as we progress. Okay?
05:49So now let's come to what we are interested in, task in web applications.
05:54How do you use geoprocessing task in web applications?
05:58Simple four step.
06:00First, initialize the task.
06:02Second one, get ready your parameters that you want to pass to the GP service, GP task.
06:08Third, run the task, which is execute the operation.
06:12It might be submit job or execute task.
06:15Last, GP service, GP task. It returns results to you.
06:19So use the result in your web application.
06:23So it is simple four step, and these four step is common across all ArcGIS APIs, which includes Android, IOS, everything.
06:33The same functionality everywhere.
06:36So let's go and take a look at a demo about how to use a geoprocessing task in web applications.
06:59Let me show you a very simple model that lives in desktop.
07:16Sorry about that.
07:24Okay. What the model does is basically, we have a project data.
07:28We have a data of different polygons, and each and every polygon represent what kind of land area it is...
07:35...whether it is a water area or whether it's an agriculture area or is it a bad [inaudible].
07:41It shows different kinds of land use for a particular region.
07:47So what I'm going to do is I'm going to send a polygon to this tool as an input.
07:52And what the tool is going to do is it's going to find the intersecting polygons within the...
07:59...all the intersecting polygons within the polygon that I sent, and then it's going to aggregate them...
08:05...based on the type of land use, and then it's going to sum up all the area of the polygon and send it back to me.
08:13So this is the tool in ArcMap.
08:21I'm going to quickly show you the data that I have behind the scenes.
08:36Okay, there you go.
08:37So this is the land cover data I'm talking about.
08:40So you could...if I closely zoom in, you could see that each and every one of them is a single polygon...
08:44...and each polygon has a type.
08:50So you could see the land cover.
08:52This one is water, and I have different types in it.
08:56So this is the type I'm going to use.
09:05Has a lot of other data types.
09:07So what happens basically is this is what the tool is doing.
09:11It's finding the intersecting polygons, grouping them based on the land use, and then finding the total area of the polygon...
09:18...and it's returning back to us.
09:19So let's go take a look at it.
09:20What I can do is I could run this tool and you can publish it to ArcGIS Server.
09:24So how does functionality will show up in a web application?
09:35Okay. So all data on it, so there is a graphic somewhere and do it one more time.
09:40So what I'm going to do this time is, let me zoom in a little bit.
09:45So this is the area where I have my data.
09:48So I'm going to find what are all the land use in this particular polygon.
09:54One, two, three, four.
10:01So it's running the geoprocessing tool.
10:03I've sent the polygon, and it's running the geoprocessing tool at the server...
10:07...and it brought back the area for each and every land use.
10:11And based on that, I've created a chart so you could see the different...
10:18...the legend shows you the different land use in this particular region.
10:21You could see that forest is the highest land use, and then there's little bit of water and some wetlands.
10:29And so like that we could give different polygons and we can look at different land use area for that particular region that we have.
10:37So this is a very typical and common geoprocessing functionality that you will notice.
10:43You send in a feature set, and then you have a huge project data and then it does some functionality...
10:48...and it returns you some analysis values, which you can use in your web application.
10:54So let's quickly go and take a look at the code.
11:00So this is a JavaScript code, but...
11:02Increase the font size.
11:05Oh, Scott, font size. Is it visible? Good? Okay.
11:12Yeah, they're good.
11:13Ah, okay.
11:15So the first thing that I do is you have to do the Dojo that require Esri task dot GP.
11:21That's the first thumb rule.
11:22You've got to do that before you start using any of the geoprocessing functionality in your web application.
11:28And then if it's going to a Silverlight API, the same way you have to use the Silverlight library for that.
11:34And the same way for Flex.
11:35It automatically adds it so you don't have to worry about it.
11:40The first thing that I do is get the GP URL.
11:43So what is a GP URL?
11:44It's nothing but the REST endpoint of the geoprocessing task I'm trying to access.
11:50So this is my task, Land Use Report, so that's the one I'm using.
11:55So the next thing, second, first step is initialize the geoprocessing task.
11:59How do we initialize a geoprocessing task?
12:01We just create a new instance of geoprocessor object and we've given the GP task URL. Simple.
12:09And then the next thing is we set the output spatial reference.
12:13So this is something very common and usually missed out.
12:16So the significance of setting up output spatial references, then the GP runs, and it returns results.
12:24The output can be in a different spatial reference than your web map spatial reference.
12:28In such cases, it will not draw properly or it might move away and it'll be drawn somewhere else.
12:34So the spatial reference is very important.
12:36So what happens when you set the output spatial references?
12:39When geoprocessing service returns the results, it returns the result in the output spatial reference that you requested.
12:47So, for example, your web application is in 4326, then whatever may be the result of the geoprocessing task...
12:54...it will always project it to 4326, and then it will send it back to you.
12:58So you can be accurate about your result.
13:01So that's a good thing about it, so always, by default, as a best practice, do this.
13:08And then the second step is, I'm using execute land use.
13:12What happens is when I create a polygon, it gives me a geometry of the polygon.
13:17I'm using the geometry of the polygon, creating a graphic right there.
13:24I've assigned a symbol, and I'm creating a graphic, and then I'm adding it to the map. There you go.
13:31And then what I'm going to do is I need to create parameters.
13:34What are my parameters? I need to send a polygon.
13:36What is a polygon?
13:37A polygon is a feature set data type.
13:40So what I need to do is I need to create a feature set from this geometry and from this graphic.
13:46And that's exactly what I'm doing.
13:47What I've done is I've created a feature set, and then I'm setting up the features based on the geometry.
13:54I get the value from the graphic, and then I'm going to set, create a parameter object where I pass in the feature set value.
14:03And so my parameters are ready now.
14:05The next thing that I have to do is run the task at the server.
14:08So how do I do that?
14:10I have to use GP task execute and pass in the parameters that I have.
14:15Since it is a synchronous task, I've set it up as a synchronous task because it's very fast.
14:20Usually it comes back in two to three seconds, so I've set it as an asynchronous...
14:26...a synchronous geoprocessing service so it is gptask.execute method.
14:30And before I did the execute, you will notice that I have done some event handling.
14:36So what I do is whenever there is an execute method on the geoprocessor, it gives you two events.
14:43It raises two events.
14:45One is on task complete, and the other one is on execute complete and on error.
14:51So what happens is when your task completes, it raises an event and gives you back the result.
14:55And when it is error, it gives you back the error.
14:58And so I'm going to cache both the events, and I'm handling it.
15:02So on execute complete if I go look at it, I'm going to call on execute complete.
15:07I'm calling the on task success methods, so that's where it is.
15:11So what happens is when it raises the event, it gives me a result object.
15:15What is the result object?
15:17It's nothing but an array of parameters, output parameters.
15:22So what exists in each and every element of the array?
15:25Each and every element of the array has the name of the parameter and then the data type of the parameter...
15:31...and then it has a property called value.
15:33The value is the crucial thing for me because that gives me the value.
15:37So I know my output parameter. I have only one output parameter.
15:40So result of zero. You could see right there.
15:45I'm using result of zero and I've got my value.
15:48And since it is a feature set, I know it has features.
15:51So I've got the features, and every features...you know that, right?
15:56Classic features have attributes in them.
15:58So I'm accessing the attributes, and I'm creating a chart variable based on the attributes defined.
16:05And then, I'm creating a chart using a jqPlot.
16:09It does even do it in any API.
16:11If you're in Silverlight then you'll be using Silverlight API to create charts and other things.
16:15So you know how to create charts, so that's nothing to do with GP.
16:19So very simple, four steps we did.
16:22To go back, we initialized the task and then we did set up the parameters and then we sent it to the SOA to run it...
16:28...and we got back the results.
16:29We're running it, right? That's it.
16:32So let's go back to our PPT.
16:38Take some questions.
16:40Not now.
16:42So I want to talk to you a little bit about input feature sets and schema.
16:46And this is another thing that comes up during sessions very often.
16:52So do you know what a schema is?
16:56Okay. So every feature set has a schema.
17:01What is it? What do we call...I mean schema is kind of the nutty thing that we use in our team so...
17:06What a schema is it's nothing but a geometry type, information about the geometry type, the spatial reference...
17:12...and the attributes that will be in the feature. Okay?
17:16So these are the three things we call together as a schema.
17:19So if you notice, every feature set will have a schema.
17:24So why is this schema and feature set significant is because, what happens is if your JSON is well defined...
17:35...when you send a well-defined feature set JSON which has all the schema information, then you'll be able to give you good results.
17:43So what happens in the feature set?
17:45I just want to talk to you a little bit more about feature set, input feature sets that you send.
17:50What happens to the input JSON that you send?
17:53It gets a little bit complicated at the SOA.
17:56So what happens is the points, lines, and polygons that are in a web application, it gets converted to JSON.
18:03When you submit the operation when the parameter becomes a JSON, right?
18:06So this JSON, what we do at the SOA is we pass through the JSON and we try to create a new feature class out of it.
18:14I think if you're aware of ArcMap, ArcGIS Desktop, Python, to create a feature class I need three information.
18:21Spatial reference I need to know.
18:23I need to know the geometry type, and I definitely need to know the fields in it.
18:27So this is what happens in it.
18:28If you don't have...at 10.0, what we did was we had something called default value defined for every feature set parameter.
18:37So we use this default value to create the feature sets, feature class at the SOA.
18:45But at 10.1, what we have done is we know that you had lot of issues when using feature sets with default schema...
18:55...so what we tried to do at 10.1 is the schema doesn't have to be defined by the task.
19:01We're not going to be so restrictive anymore.
19:03We are going to accept schema that is being defined by the client.
19:07So if you tell us this is going to be the fields, this is going to be the spatial reference, this is going to be the geometry type...
19:13...we accept that, and we create feature classes at the server and we use that.
19:19Got it? Yes? No? Okay. I get some nods. Okay.
19:26And so what happens is, so when you send JSON, when the web application send JSON, we need to have a good structure.
19:33So these are the properties that we definitely need to create a good JSON.
19:38So the fields property is very important. I'm sorry.
19:43And then the spatial reference and then the features and the geometry type.
19:46These properties are very crucial for us.
19:49So if you...what you have to do is in your code, when you are writing your code and creating feature set...
19:55...make sure these properties are explicitly set on the feature set.
20:00So this is another trick at 10.1.
20:01So if you do that, we will honor it, the GP service will honor it, and when you return, the features will be returned as you sent it.
20:10So sometimes what happens is if you give a polygon with a beautiful nice attributes and you try and do a buffer...
20:16...when it comes back, you get one either buffer or polygon.
20:19You will not get the attributes along with it.
20:22So this has been...with some scenarios, it's really annoying, and so to overcome that, make sure that your field value is defined.
20:30If you did that, when it comes back, you will have the field value in your outputs as well.
20:37So the second thing that we did in 10.1 is we allowed you to define empty input schema.
20:44And some of the geoprocessing services are generic to any geometry type, to any fields.
20:51The classic example is buffer.
20:53You can do a buffer on a point, polygon, polyline.
20:56So you want to create a service and tell the user, You are welcome to send me any geometry type.
21:02You are welcome to send me any field type.
21:05So how can you create a service like that?
21:08You have to create a service with a default value, without a default value.
21:13So this is...you can do that when you publish it.
21:17So when you do that, the service is very obvious.
21:19It says that, the client defines a schema, and we use that schema to get a feature class.
21:27Okay. Good. And the same way when we return output feature sets, we return fields value.
21:36So this is also convenient at 10.1.
21:38So we've done that.
21:39Some of our users have been asking for it.
21:41So did that.
21:44Okay. Next, let's talk about result map service.
21:47Have you heard about result map service?
21:49Have you used result map service? Okay. Okay.
21:55So what is a result map service?
21:57A result map service comes into picture when we talk about asynchronous execution.
22:02I already told you, asynchronous execution is kind of a very luxurious way of running a geoprocessing service.
22:09We save your inputs. We save your outputs. We do everything at the server.
22:14So what happens is we stretch it a little bit more.
22:18It's a doggie bag effect.
22:19So we stretch it a little bit more, and we say, We already have the data and everything at the server.
22:25So why don't we create a map service out of it and we give it back to you?
22:29So what happens is the feature sets and the raster output that comes out of a geoprocessing service...
22:35...becomes a layer in a map service, and we dynamically create this map service at the end of a geoprocessing task...
22:42...and we send it back to you.
22:44So this is the concept behind it.
22:46If it is a classic geoprocessing task without an [unintelligible] the web application sends JSON and what you get back is a JSON output.
22:55When you create a geoprocessing service with a result map service, what you get is send a JSON input.
23:02What you get back is a JSON output as well as a result map service.
23:09An [unintelligibl] is supported only for asynchronous geoprocessing service.
23:12You cannot create [unintelligible] for synchronous geoprocessing service.
23:16So why would somebody want a map service like that?
23:20So number one reason is when you have really large dataset.
23:24Say, for example, your feature set has records more than 10,000 or 20,000 records.
23:29It outputs records like that, so you don't want to download everything into a JSON into your web application...
23:35...at the client and try to draw them and do everything.
23:39So that...it gets tedious at that point.
23:40So it comes in very handy, result map services.
23:44The second one is once you define the symbology at the server, that symbology is used again and again to create map service layers.
23:53So once you create symbology, you don't have to define it again at the client.
23:57This comes in very handy when you're using your services in web...when...different web APIs...
24:04...JavaScript, Flex, or Silverlight API.
24:07You can move onto any API you want, but what happens is you get the same symbology everywhere, right?
24:16Because it comes from the map service, so you can inherit the symbology and you can draw it, so it gets easier.
24:22And the last...next one is raster outputs.
24:25Raster dataset is always kind of a trouble, right?
24:28You can see that how you can download it as a file and you can see it, but you can't add it to the map.
24:34And raster datasets without adding to your web app...web map doesn't make that much difference...
24:41...because you don' know where the raster fits in.
24:44So the result map service, what it does is it creates a nice raster layer and hands it over to you.
24:49So now you could add the result map service layer to see where the raster data is.
24:57And the last one, we also support some of the advanced data types like TIN and CAD, which cannot be drawn by the client.
25:06So these are some of the advantages of creating results map service.
25:12And so what did we do at 10.1?
25:14This was another item that the result map service was kind a little tedious to get it onto.
25:20So we totally improved the result map service.
25:24And so now it's very, very easy.
25:26We give you a URL so every time you run a GP task and then the end, the result map service, we give you the URL.
25:35It's a very easy template for the URL that you can use, and you can use that map service and add it to the web map.
25:41And then you can...we allow you to download features based on query.
25:44So what happens is it acts like a classic map service.
25:48So what happens in a map service?
25:50You can do queries against it.
25:52You can do extent-based queries.
25:54You can do field-based queries.
25:56So you can do all sorts of queries, right?
25:58Same thing you can do with the result map service, too.
26:02And then we have added a dynamic legend.
26:04So every time your GP task runs, the legend is updated...sorry...the legend is updated to...
26:16...the legend is updated for each and every task result.
26:21And then we have enabled time.
26:22So similar to dynamic map service [unintelligible] is supported on dynamic map services, same operation, same functionality.
26:30We offer it through the result map services, too.
26:32So it's more powerful.
26:36So let's go take a quick look at a result map service.
26:59Okay.
27:01So what I'm going to do is I have a model at my server.
27:06So what this model does is it has a lot of data behind it.
27:11The same thing like before.
27:13It has about 15,000 points, and each and every point represents a specific 911 emergency call that occurred at that particular place.
27:23So what I'm going to do is I want to run hot spot against this.
27:27But I don't want to run the hot spot for the entire five months.
27:30It's from January 1998 to May 1998.
27:35But I don't want the hot spot for the entire five months.
27:38So I'll set up a model.
27:39So what I could do is I could send a query string.
27:42I could say run it between January to January 1st to February 2nd or February 3rd to March 8th.
27:50I want to find the hot spot for this particular time.
27:55I want to find the hot spot that was...I want to find the number of calls that was originated and I want to find the hot spot for it.
28:04So what I'm going to do is...let me set up a query for you.
28:08So there's a date range, and the default date range is still January, so let's extend it.
28:14So I'm going to select the features that are between January 1st to, say, February last.
28:22And the day of the week, I'm not very particular about all the days of the week.
28:26I want to know what happens during the weekend.
28:28Is there more 911 emergency calls during the weekend in this particular time?
28:33So I'm going to do the Saturday and the Sunday, maybe Friday as well.
28:37And let's do an analyze 911 calls.
28:39So what this model does is it queries that particular dataset, gets that data alone, and draws a hot spot on it...
28:47...and creates two layers for you.
28:49So one is the first one cycle.
28:53I can show you the map layers.
28:58So it shows you the hot spot raster for that particular queried features.
29:02And the second one is it shows you the raster hot spot and the features.
29:08And you could see that I have a time slider right here, so I could see...ah, it's a little bit slow...
29:18...because it's doing map service query.
29:21It's not on the feature layer. It's on the map service layer.
29:24So it's a little bit slow.
29:26So this is what I can do.
29:27So there is a result map service that's...when after the GP task runs it, it returns a result map service.
29:33I've added the result map service to my web application.
29:37So that's what I've done.
29:38So it's not just adding result map service as a dynamic map service, I can also add it as a feature layer.
29:44So this is my feature layer.
29:47So I'm going to add them as a feature layer.
29:48So now, the features are downloaded to the client, so it's drawn at the client.
29:53So this should be faster, so...
29:57We can do time on that one as well, right?
29:59Oh, okay. There you go.
30:08And the other thing that I wanted to show to you is this is just to show you that this is...
30:12...on the client, you could see that I could access the attribute and everything, so it's a classic feature layer.
30:20So you could see the legends.
30:21So each and everyone has legends, too.
30:24So let me enable the dynamic map service so you could see the legends.
30:30So on this legend is something that's created by my result map service.
30:35So I don't have to hard code it. I don't have to...I didn't have to create the legend.
30:39That was created by my result map service and I will access it.
30:42And this one is...this one changes for every result.
30:46Every time you run a result, the legends gets updated.
30:49See, for example, if I ran for Monday and Tuesday as well, you could see that my legend gets updated.
30:55And these are some of the good stuff that we have done at 10.1, especially for result map services.
31:01So I want you to go...I'm going to quickly show you the legend and then we'll go see the code.
31:06So you could see that I have updated it.
31:08The Friday, Saturday, Sunday, Monday, and Tuesday...the legends have updated itself.
31:15So how do we do this?
31:16How do we run an asynchronous task and create a result...and access the result map service that was created?
31:24Let's go take a look at the code.
31:27It's very simple.
31:28So access the GP service URL.
31:30GP service URL is nothing but the task URL.
31:35And then the other one that I've done is map service URL.
31:38So how did I get the map service URL from?
31:42Very simple.
31:44It's in my land use analysis.
31:51First, 911 calls hot spot.
31:55I go look at it right there.
31:57You could see, I have a map server link right there.
32:00So if I go click on it, there you go.
32:04That's the URL I'm using.
32:06That's my map service URL.
32:08So what happens is this kind of a template map service that we show it to you when you publish your processing services...
32:15...but based on this map template, we create new instances of map services for every task that is run.
32:24So if you get a successful task, then we create a map service for it.
32:29And so each and every one of them is a new map service.
32:35So let's go take a look at that.
32:37So same way as before, step 1, initialize the geoprocessing task.
32:42Step 2 is set up parameters.
32:44The parameter that I need to send is my query string.
32:47So I've done some UI processing to get my query string.
32:52And then the next thing that we do is submit job.
32:54We didn't do execute task this time.
32:56We did submit job because the operation is different for asynchronous execution.
33:01And you notice that I have done three different event handlers here, not just task complete and error.
33:07There's three different handlers.
33:09One is task complete, on job complete, on error, and the new one is on status update.
33:16So what is this, and why is it different from execute task?
33:21What happens in submit job is, when you submit a task to geoprocessing service, asynchronous task...
33:28...what happens is it creates a job ID for you.
33:32So the moment you submit it, it creates a job ID for you.
33:34And this job ID is kind of a reference for you.
33:38And so what you can do is you have to probe the GP service, GP task to find out the status of the your task...
33:46...because it's a long-running task, right.
33:48Asynchronous tasks are typically long-running tasks.
33:50So what you're going to do is you're going to find the status of the task now and then to make sure that it's been completed or not...
33:56...or whether it's running or what happened to it.
33:58So these are called status updates.
34:01So these are sent from the client to figure out whether this job is still running or where it is. Okay.
34:07So we are also going to...there is an event.
34:09So what happens in a web API is it creates a status call for every once again.
34:16It sends it for every...sorry...it sends it for every minute...sorry, I forgot.
34:22So it sends a periodic request, so you can...when it gets back the status, you can keep track of the status as well.
34:28So that's the event handler that is raised when it gets back a status from the service.
34:33The other one's a classic one. When the job is complete, it returns you an event.
34:37And at the same time, when there is an error, it raises an event.
34:40So I'm going to handle them both.
34:42And so on task status, I'm not doing much.
34:44I just want to know the status of my job.
34:47So I just return the job info.
34:49So in the job info, I can find the job status.
34:52On task complete. So this is the simplest code that I've done.
34:55So on task complete, look at that.
34:59What all I've done is I've created a dynamic map service, and I've used the URL.
35:05What URL did I use?
35:07I used the map service URL and the job ID that was created for this particular task.
35:13So that's it. So that will give you the map service.
35:17It's as simple as that.
35:18So use a map service plus the job ID of that particular task will give you the result map service, and you can add it directly.
35:26[Inaudible audience question]
35:29Its life span depends upon 600 to...6 tasks altogether, 360 minutes, but the system administrator can modify it...
35:40...because if he didn't want to have too many services running, obviously.
35:45So how do you add a feature layer?
35:48It's as simple as that.
35:49You've got the map service layer already so all that you have to do is /0, right?
35:55That's your first output as my input feature set, output feature set.
35:58So /0 gives me my feature layer as simple as that, and then add it to my map.
36:04There you go.
36:05So now you have a nice cool app that has a GP service and has a result that you can add without doing any symbology...
36:12...or anything.
36:13With few lines of code, you can add it. Done.
36:19So there you go.
36:20So the last one is file inputs.
36:33So the...another kind of geoprocessing service that you might come across is file inputs.
36:39File inputs like are becoming very popular these days.
36:42You use CSV and you use GPX files; you start using photo...there are so many files.
36:49And we also support a lot of out-of-the-box tools, too.
36:52There are different tools that we support in ArcGIS ArcMap that could be published to ArcGIS Server...
37:00...like the new GPX To Features tool.
37:02So you're given a GPX and then the features will be...it'll give you back the features of the GPX.
37:08So these all can be set up as a service as well.
37:10So there's so much of file processing and, of course, the rich Python API loves you to do even more processing with file inputs.
37:18So this file inputs has become very common.
37:20But in geoprocessing service at 10.0, we always expected the file to be behind the web server.
37:27Only if you give us a URL input, we could process the file in the GP task.
37:33So this was kind of inconvenient.
37:35So what we did at 10.1 is we have introduced a new capability on the GP service called uploads.
37:43So what does uploads...you can enable or disable it based...if you're using a file input, then you can enable it...
37:50...or if you didn't want it, you can disable it.
37:53You have to do this during publishing or after publishing.
37:55Go to the properties of the geoprocessing service and enable it.
37:58So it's just like any other map service capability.
38:03So what happens when...how do you handle this?
38:07You can upload. The capability allows you to upload your local file on your desktop to ArcGIS Server.
38:15And then it returns an item ID.
38:17So what you can do with this item ID is you can use this item ID as an input to GP task which use GP data file.
38:25You can use it for GP raster layers...I'm sorry...GP raster layers, and you can also use it for GP feature sets.
38:32This is another cool thing that we have done at 10.1.
38:40So what does this item ID represents is it's nothing but a simple grid...
38:46...and this grid represents a file located on my ArcGIS Server machine.
38:54So my GP service can access directly my file.
39:01Okay. So I'm going to show you the upload capability that we have done and how it is done.
39:11Okay. So I'm going to sit right now.
39:15So what happens is in web APIs, the uploads capability is not being implemented at the prerelease, 3.0 prerelease.
39:26So I'm going to show it to you in the REST interface.
39:32So I've created a simple tool called Create Geotagged Photos.
39:37What this tool does is you give it a ZIP file, a big ZIP file, so it can handle only 2 GB files, so not a really big one.
39:46So if you give it a file, it will unzip the file.
39:50Look at all the photos in it, and if it is being geocoded, then if has a lat/long value...
39:56...then what it'll do is it'll create a corresponding features for each and every photo in the ZIP file.
40:04And not just that. It'll also create attachments.
40:07These photos will live as an attachment for that particular feature class.
40:12So let's see how to get this working with the new uploads capability.
40:18As you could see, my geoprocessing service has been published with an uploads capability.
40:22It shows up as uploads.
40:23So I'm going to go here.
40:25I'm going to say, Upload item.
40:28So when I upload item, it gives me an interface to upload a file...I'm going to go ahead and do it in SQL and DS 2012.
40:38I have a ZIP file right here.
40:40This ZIP file has about four or five photos.
40:42I didn't want to take too much of your time, so it has about three or four photos altogether.
40:46I think three photos.
40:48So let's quickly upload it to the server.
40:51So I'm going to say for description, Photo file. Upload item. Okay.
41:02Make sure that I clicked on it. Okay. There you go.
41:05So it gave me a nice item ID, the item name, date, everything, right?
41:10So where does this item live?
41:12I can show you that.
41:27This is my ArcGIS Server directory. Right?
41:30So SQL and ArcGIS [unintelligible]. Right?
41:34So there is a directory called ArcGIS System at 10.1.
41:38And then in that, there is a directory called ArcGIS Uploads.
41:43Hope I didn't do anything. Okay. Let's see what happens.
41:48So in my uploads I have a folder called Services, and for each and every service that has uploads functionality...
41:54...there is a folder.
41:56[Audience comment] Control Z.
41:57Control Z? Did I do something? Okay. Let me see what happens.
42:03So if you take a look at it, this is the ZIP file that I uploaded.
42:07You could see that Redlands.zip. That's the one that I uploaded.
42:10So this is where it lives.
42:11The file lives in my ArcGIS Server now, so every service is aware of it.
42:15If you give an item ID, it knows where to go and look for it.
42:19Simple, right?
42:22So let's see how to use it.
42:24So here is my item ID.
42:26So I'm going to copy, paste my item ID. Control C.
42:29I'm going to go back to my service.
42:33So you could see my service is taking a GP data file as input.
42:38So I'm going to go all the way down.
42:40I'm going to say, Submit job.
42:42I'm going to give this as an input for my item ID and my string.
42:57And let's do submit job and wait for it to complete.
43:03Submitted, executing, fine, fine, fine.
43:09Okay. There you go.
43:10So it completed, and I also published it with the result map service, because it's in REST.
43:15I wanted to show you that it could create points, so it really created points.
43:19So let's go look at the result map service.
43:24So did you...take a look at the URL for the map.
43:31Do you see that? It has its job ID.
43:34So this is a new map. The result map shows it was created for this particular service.
43:45Okay. That didn't come up.
43:46[Inaudible audience comment]
43:48Yeah. I moved my jobs directory. That happens.
43:56Oh. So that what happens.
43:59So you want to see a nice map service with dots on it.
44:04SQL and ArcGIS Server directories.
44:12So that's my panic mode.
44:14ArcGIS Server. Okay. Directories. How [unintelligible] ArcGIS jobs? I don't know which one I moved out. ArcGIS system.
44:28Ah, sorry. I screwed up my server.
44:30Uploads.
44:31[Inaudible audience comment]
44:38There you go.
44:44Okay. Let's see whether it works this time. Okay.
44:52Ah, let me run it.
44:56Sorry. Got five-eighteen, so we still have some time to go.
45:04Item ID.
45:10Hopefully I have my...ah.
45:17ArcGIS...upload services, geo-photos, F2.
45:31Okay. Let's run it one more time.
45:41One more time. [Unintelligible] map service.
45:44There you go. So here's my layer for the points.
45:50And I'm going to open it up in ArcGIS JavaScript so we could see that.
45:57So those are the three points, geotagged points for the points that I sent.
46:01So it went through the photo. It looked for the lat/long value in the photo, and it created a feature.
46:08That look good? Okay.
46:26So just to do a quick recap on what we did today.
46:29So first thing we did was try some synchronous service with an execute task operation...
46:35...and then we went ahead did some asynchronous execution, and asynchronous execution uses submit job...
46:41...and when we did submit job, what we did was we also used a result map service along with that to make it simpler...
46:48...so we could add the result map service directly instead of running through the result, setting up symbology...
46:53...drawing everything.
46:55What we did was simply we used the result map service and we did that.
46:58And the other common geoprocessing functionality is file uploads.
47:02So we made it simpler at 10.1, file uploads.
47:05You could use the uploads capability, upload a file to ArcGIS Server, and use that as an input into your geoprocessing task.
47:13GP data file is very obvious. You are using a file in processing.
47:17GP feature set and GP raster data also at 10.0 and 10.1, we support them as URLs.
47:24So what exist in the case of GP feature set, the item ID.
47:28The file that you have will have a huge set of features in it, a JSON of features.
47:33So if you give us a URL or if you pass this particular file to ArcGIS Server and if it's in the uploads folder...
47:42...you can give us the item ID of this particular TXT file, and what we will do is we will create feature set out of that.
47:50So you don't have to send a JSON from the web application.
47:53Instead, you could give it the item ID, and we'll pass it for that.
47:56So that's the scenario for GP feature set where you can use item ID and the same with rasters as well. Okay.
48:04Any questions?
Using Geoprocessing Services with ArcGIS Web Mapping APIs
Monica Joseph and Scott Murray discuss the basic patterns of using geoprocessing services in the web APIs.
- Recorded: Mar 28th, 2012
- Runtime: 48:05
- Views: 1314
- Published: Apr 24th, 2012
- Night Mode (Off)Automatically dim the web site while the video is playing. A few seconds after you start watching the video and stop moving your mouse, your screen will dim. You can auto save this option if you login.
- HTML5 Video (Off) Play videos using HTML5 Video instead of flash. A modern web browser is required to view videos using HTML5.
Right-click on these links to download and save this video.
- 480x270:WebM (101.2 MB)MP4 (108.6 MB)
- 960x540:WebM (268.0 MB)MP4 (295.9 MB)
If you don't have an Esri Global Login ID, please register here.