TitlePages

Showing posts with label Models. Show all posts
Showing posts with label Models. Show all posts

Friday, 12 December 2014

How to check for condition in Geoprocessing Service or Model Builder

How to check for if/else conditions in Geoprocessing Service


TOOL USED:  
Arc python and Script tool
Python script will be deployed in the ARC Toolbox to create the Conversion Tool 

WORKING OF THE TOOL:
Script tool is created in the ArcMap and the required input & Output Parameter are set. The script tool source is set to the custom python code present in an Python file(.py)
Out motive is to use check for the count of a features in an feature class and performing an conditional Execution

PROCEDURE:
  • Open ArcMap 10.0+ 
  • Create your own Geometric Network or Open your Existing Geometric Network
  • Add your Geometric network to the Table of contents in the ArcMap as Shown Below


·         Create a new Model in your myToolBox .Right Click on MyToolBox > New > Model.Following window will appear on the Screen 







  •    Add your desired feature class to the Model. (Right Click on any empty space and select ADD DATA  and select your feature class in the object browser)
  • ·         Add Get Count and Calculate value Model from the System Toolbox Connect the model as shown below 






  • ·         Now open calculate value Model and in the Expression Textbox call the function Calculate(%RowCount%)
  • ·         Here %RowCount% will act as an Inline Variable and Compiler automatically replace the %RowCount% with the value of the rowcount field
  • ·         At the Code block defined the function Calculate as

def calculate(row):
if row>0:
return true
else:
return false
  • ·         Make the return Data type as Boolean
  • ·         The output Boolean can be set as a precondition for any model. So that the Model  get executes only when the output of calculate value is true






Thursday, 11 December 2014

Performance issues on ArcGIS Geoprocessing Service

How to improve Geo-processing Execution Speed

Geoprocessing services hosted in the ArcGIS server needs to be pretty fast and accurate. User will always want the service to be the fastest. Since ArcGIS Server will be able to service multiple users at one instant of time, inefficient services can overload your server and increase the processing time. The more efficient and intelligent your services, the more users can be serviced with the same computing resources at a smaller amount of time.

Below are some of the tips and techniques that helps in increasing the performance of your Geo-processing Services.

Use local paths to data and resources

The more faster the data requires to be processed is accessible by the server the more faster your service will be.It is good to copy your data to the server rather than placing it on the shared location and asking the server to access it.(Copying the server will be effective only if the Geo processing input data is very small in size and also when the input data is not dynamic)
Reading data from the local area network will be slow compared to accessing the data from the local disk.. 


Reading and Writing the Intermediate data IN_Memory


The service execution speed will get increased by multiple times when the intermediate data is allowed to stored in the machine memory(RAM).Input and output operation is the slowest of all the computing operations.In Geoprocessing storing the intermediate data in a file geodatabase or personnel Geodatabase will take maximum of the execution time.
Please be sure the data which your are storing in the memory as an intermediate data need not be necessary after the execution is complete.Because once the execution is complete the data in the memory will get cleared.Don't write large amount of data to the in_memory as it may affect the performance of the processing service.
To write to your computer's memory, use the pathname in_memory, as follows:
          in_memory\your featureclassname




Use layers from a source map document

If a service uses a source map document instead of feature classes and datasets, it will tremendously increase the performance of the service.Your models and scripts can use map layers from the source map document so that it will impose less load on the processor and significantly decrease the execution time. A layer references a dataset on disk or feature class on a geodatabase, and some layers cache properties about the dataset. Therefore by using dataset layer instead of the direct dsataset or feature class,there is a performance advantage because ArcMap opens the dataset once, caches basic properties of the dataset, and keeps the dataset open. When the Service executes, the dataset need not to be  reopened because the source map document already it is opened and it will gives us a performance boost.


Write data to shapefiles

Storing the data to shapefiles is a bit faster than writing to other formats but writing data to memory, described above, is the fastest of all. Even then there is further more limitations on the shapefiles such field names should be  as 10 character , no null values, and limited support for date/time, to name a few. This become more helpful if the you are running your model locally on your Desktop

Wednesday, 26 November 2014

Custom Geoprocessing Tool


Arcobjects Geoprocessing Procedure:



1. Create a geoprocessor object and set its properties.
2. Set the appropriate values for the tool’s parameters.
3. Execute a tool using the geoprocessor object’s Execute() method.

In order to create a geoprocessor object, the IGeoProcessor2 interface can be used. This interface
is defined in the geoprocessing library of ArcObjects and is implemented by the GeoProcessor
CoClass.

IGeoProcessor2 gp = new GeoProcessorClass();
//add the result of geoprocessing as a new layer to Map
gp.AddOutputsToMap = true;
//if output of geoprocessing exists before the execution of tool
//it will be overwritten
gp.OverwriteOutput = true;

Assume that you want to create Thiessen polygons for the cities FeatureClass to create proximal
zones for all cities. The proximal zones represent full areas where any location inside the zone is
closer to its associated city than any other city. Based on the Create Thiessen Polygons reference
page, you have to provide at least an input point FeatureLayer and the path to the output
FeatureClass.
In order to create and set each parameter, the IVariantArray interface of the System library must
be used.

IVariantArray parameters = new VarArrayClass();

Each parameter has to be added to the IVariantArray interface in the exact order that is specified
on the tool’s reference page.

//in_features
parameters.Add(@"D:\DataFolder\fileGDB.gdb\cities");
//out_feature_class
parameters.Add(@"D:\DataFolder\fileGDB.gdb\citiesThiessen");
//fields_to_copy(Optional)
parameters.Add("ALL");

As it is illustrated on the Create Thiessen Polygons reference page, the third parameter is optional.
You can simply not add any value to IVariantArray or, as shown in the preceding code, you can
provide an appropriate value for the optional parameter. You can skip the optional parameter
using an empty string as input to IVariantArray’s Add() method. For example, look at the
reference page of the Buffer tool; you can see that three of the seven available parameters are
mandatory. The following code demonstrates how to skip the fourth parameter and specify the
fifth parameter:

//1-in_features
parameters.Add(@"D:\test.gdb\cities");
//2-out_feature_class
parameters.Add(@"D:\test.gdb\citiesBuffer");
//3-buffer_distance_or_field
parameters.Add("50 kilometers");
//4-line_side(Optional)
parameters.Add("");
//5-line_end_type(Optional)
parameters.Add("ROUND");
//6 &7 there is no need to provide empty string
//for the rest of parameters since you don't want to set them
After setting all the required parameters, all you need to run a tool is to call the Execute() method
of the geoprocessor object. The Execute() method solicits the name of the tool and its parameters.

gp.Execute("CreateThiessenPolygons_analysis", parameters, null);
The following code shows the complete code for this example. In order to run the code, you need to
add references to the Geoprocessing and System libraries of ArcObjects:
IGeoProcessor2 gp = new GeoProcessorClass();
//add the result of geoprocessing as a new layer to Map
gp.AddOutputsToMap = true;
//if output of geoprocessing exists before the execution of tool
//it will be overwritten
gp.OverwriteOutput = true;
IVariantArray parameters = new VarArrayClass();
//in_features
parameters.Add(@"D:\DataFolder\fileGDB.gdb\cities");
//out_feature_class
parameters.Add(@"D:\DataFolder\fileGDB.gdb\citiesThiessen");
//fields_to_copy(Optional)
parameters.Add("ALL");
//or parameters.Add("");
gp.Execute("CreateThiessenPolygons_analysis", parameters, null);


The Geoprocessing library of ArcObjects is accessible through the ESRI.ArcGIS.Geoprocessing
namespace. This library contains a few hundred types which can be used to run and manage tools
and GIS workfl ows. You learned earlier in this section that IGeoProcessor2 is the main interface of
this library and the easiest way to run a geoprocessing tool is to call its Execute() method.
However, using IGeoProcessor2 is not the only approach to run a geoprocessing tool or model.
There are some managed assemblies created by Esri to performing geoprocessing in a managed
way. A managed way means there is a native .NET assembly (the Geoprocessor assembly) that is
a wrapper for some types in the Geoprocessing library of ArcObjects, and there are other .NET
assemblies for each system toolbox.
These native .NET assemblies provide an even easier way to run a system tool. In general, the
procedure for running a tool using the Geoprocessor-managed assembly is the same as running a tool

Sunday, 23 November 2014

Simple Geometric Network Tracing

Trace Geoprocessing Model for Custom Tracing on your Geometric Network

Tools Required: Arcmap 10.0 + 


Procedure

To start with building geoprocessing Model for Tracing functionality you must first need an Geometric Network

If you doesn't have your own geometric Network with you.Please download a sample network from the Internet.Please refer arcgis site for various geometric network samples

For creating a own geometric Network for representing your own network of real world data.Please follow the steps in this link Create Geometric Network


Once Geometric network is downloaded or Created please add it in to the ArcMap Table of Contents.

To perform a tracing on your network , the network should be ready with the flow directions which help the tracing tool to perform a trace

Setting up a flow direction for a Network can be done in Two ways: 1.Digitized flow direction  2.Flow direction through Source and Sink

Follow the basic python code to setup your network Flow Direction

 import arcpy 

Water_Net = "C:/testing/GeometricNetworks/Montgomery.gdb/Water/Water_Net" 

 Set Flow Direction arcpy.SetFlowDirection_management(Water_Net, "WITH_DIGITIZED_DIRECTION")

Once the flow direction is Set. Create a new toolbar with a new model in it named as Trace model Tool

Open the model by right clicking it and select EDIT


Build the model as shown in the Figure.

For creating feature set .Right click and click on CREATE VARIABLE> select FEATURE SET (This features will be generated interactively during the runtime to get the flag and barrier Locations)

Set the Snapping environment as desired.Select the major network element such as Mains in a Water Network as the snapping feature.So that the flag and Barrier will snapping if it is placed within the snapping Tolerance

The Snap model Tool will work only with model builder and not with Python

Set the Trace Results as the Model parameter if you want the Traced Results to placed on the TOC.So that it will appear on the Active S

creen.

The Model displayed above will select only the junction traced results and add the created feature layer to the map

To access the Traced Results.Please Go to GEOPROCESSING>RESULTS and Current Session will give access to the flags and Barriers Used by the Model Tool

Final Model when opened will look like this.

Traced Results

HAPPY TRACING.,,Please comments your suggestions

Thursday, 20 November 2014

Feature Count using Model Builder

Software Required:
  1. ArcMap 10.2 or more


Procedure:
  • Open ArcMap 10.2+ 
  • Goto Window > Show ArcCatalog
  • ArcCatalog Right Click on the Default GeoDatabase and Create New Feature Class.Give a name for the new feature class and Click Finish
  • Add a New Model to the Database New > Model Tool after creating a New ToolBox
  • Add Get Count and Calculate Value to the New Model
  • Set GetCount Ouput Value as  the Precondition for Calculate Value
  • Add the following procedure for the Calculate value Model






Expression

CountMe(%RowCount%)

Code Block
def CountMe(n):
  if n > 0: 
     return "true" 
  else: 
     return "false"



The Output of the Calculate Value Model is Boolean(True or False).Setting the output value of Calculate Value as the Precondition for the desired Model will make it model to run only when the output is True