TitlePages

Showing posts with label Geoprocessing. Show all posts
Showing posts with label Geoprocessing. Show all posts

Thursday, 22 January 2015

ArcFm Auto Updaters to Update the Shape Length of the Feature

Schneider electric

Update the Shape Length of the Poly line Feature

Special Auto Up-daters

A special Auto Up-daters differs from the attribute Auto Up-daters in that it is not associated with a field/event combination but rather a feature/event combination. A special Auto Up-daters can be associated to the On Feature Create, On Feature Update, or On Feature Delete events of a feature.

Special Auto Up-daters are not limited to simple field updates like attribute Auto Up-daters. Rather, they can be written to perform a wide array of tasks such as writing out text files, updating records in a remote database, sending emails - just about anything that you would need to programmatically do in response to a feature/object.

IMMSpecialAUStrategyEx Interface




  1. Do the following steps to start with AutoUpdaters.
  2. Start your Visual Studio 2010 or More 
  3. Create a New Project of Type base Command from ArcGIS tab .Choose the Programming Language of your comfort(VB or C#.Net)
  4. Give a Name to the Project and your can see base class library with your dll registered function with Unique Code GUID.
  1. To get the Functionality of the Special AutoUpdaters in your code implement the Specific Interface ie. IMMSpecialAUStrategyEx Interface


public class ShapeLengthAU : IMMSpecialAUStrategyEx
    {

        private string _name;
//Name is a required parameter for the Implemented Interface
        public string Name
        {
            get
            {
                if (string.IsNullOrEmpty(_name))
                {
                    _name =”Name of your Autoupdater
                }
                return _name;
            }
        }

        
        public void Execute(IObject obj, mmAutoUpdaterMode eAUMode, mmEditEvent editEvent)
        {
            IPCursor pCursor = null;
            try
            {
//Autoupdater will update only when the EditEvent is of Type like FeatureCreate,FeatureSplit,FeatureUpdate
                if (editEvent == mmEditEvent.mmEventFeatureCreate || editEvent == mmEditEvent.mmEventFeatureSplit || editEvent == mmEditEvent.mmEventFeatureUpdate)
                {
                    IFeature pFeature = obj as IFeature;
                    IPolyline pPolyLine = pFeature.Shape as IPolyline;
                    double ftLength = pPolyLine.Length;
//Place the length value in to the Pfeature respective field
                    pFeature.set_Value(pFeature.Fields.FindField(“ShapeFieldName”), ftLength);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                if (pCursor != null)
                {
//Use the Marshalling Method to release the Cursoer from the Memory
                    Marshal.ReleaseComObject(pCursor); 
                }
            }           
        }
//get_Enabled is a required Method for the Implemented Interface
        public bool get_Enabled(IObjectClass,pObjectClass, mmEditEvent eEvent)
        {
            return true;
        }

        
    }
}

Now Compile the Code and Execute.
Note:Set the Startup Project for Debugging as ArcCatalog.exe in the Project Properties.

Go to Arc-Catalog , Right Click on your ArcFM feature and Select ArcFm Properties Mangaer

Select the Object Tab.It will display the various event from the ArcFm for the Particular Object.
Assign your Auto Updaters to the various event you want to call.

Do the edit in the feature through ArcMap editor.This will trigger your Updaters.






Wednesday, 24 December 2014

Arcpy Improvements in 10.1

Arc Python in ArcGIS 10.1

  1. Site package that adds ArcGIS functionality to Python
  2. Access to rich suite of geoprocessing tools
  3. Functions, classes and modules
  4. Helper functions like ListFeatureClasses, Describe
  5. Classes that can be used to create complex objects like Spatial Reference, Field Map
  6. Modules that provide specialized functionality like Mapping,SpatialAnalyst, NetworkAnalyst, DataAccess

Complete Introduction to Python concepts for beginners is available here

Python
ArcGIS + Python = ArcPython

For more info and advance Concepts use the folowing references: 

resources.ArcGIS.com
arcpy.wordpress.com
GIS Stack Exchange, Stack Overflow
Python References,Python Scripting for ArcGIS
GIS Tutorial for Python Scripting by Allen (Esri Press)
Learning Python by Lutz - The Python Standard Library
python.org
http://www.esri.com/training

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

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

Wednesday, 19 November 2014

Create a Display Flow Arrows Addin


ArcMAP ESRI Add-in for Display flow arrows for Utility Geometric Network


Software Required:
Microsoft Visual Studio 2010 +
ArcMap 10.2 or more
ArcObjects SDK for .Net Installed

Procedure:

  • Open Visual Studio 2010
  • Create a New Project > Visual C#> ArcGIS>Desktop Addins >ArcMap Add In
  • ArcMap Addin Wizard will appear on the Screen.Give a desired name for your Addin and click Next
  • In the Addin Types Enable Button checkbox and provide description for it.This will appear as a button tooltip in your ArcMap application.Click finish to end the wizard.
  • Now go the Solution Explorer(View>Soln Explorer) and open the Addinname.cs file if it doesn't appear in your screen.
  • Replace the content of the file with the following data.
  • Add the References(Right click references in Solution Explorer and select Add References) based on your classes usage


//Add the references in to the current namespace
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using ESRI.ArcGIS.ArcMapUI;
using ESRI.ArcGIS.Carto;
using ESRI.ArcGIS.EditorExt;
using ESRI.ArcGIS.Framework;
using ESRI.ArcGIS.esriSystem;
using ESRI.ArcGIS.Editor;
using ESRI.ArcGIS.NetworkAnalystTools;
using ESRI.ArcGIS.Geometry;
using ESRI.ArcGIS.Geodatabase;



namespace Flow
{
    public class FlowArrow : ESRI.ArcGIS.Desktop.AddIns.Button
    {
//Declare the interface Variable
        public IUtilityNetworkAnalysisExtFlow utilarr;
        public IUtilityNetworkAnalysisExt utilflow;
        public INetworkAnalysisExt netExt;

        public FlowArrow()
        {
//Get the reference to the Utility Analyst Toolbar using the UID Reference
            UID pUID = new UIDClass();
            pUID.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
            netExt = ArcMap.Application.FindExtensionByCLSID(pUID) as INetworkAnalysisExt;

            UID uidutilflow = new UIDClass();
            uidutilflow.Value = "esriEditorExt.UtilityNetworkAnalysisExt";
            utilflow = ArcMap.Application.FindExtensionByCLSID(uidutilflow) as IUtilityNetworkAnalysisExt;

            
            
        }

        protected override void OnClick()
        {
            message m = new message();
    
            IGeometricNetwork gn = null;
            
            // get the current network

            IMxDocument mxd=ArcMap.Application.Document as IMxDocument;
            IMap map=mxd.FocusMap;
            IActiveView av = map as IActiveView;
            gn = netExt.CurrentNetwork;

            if (gn != null && utilflow!= null)
            {
                utilflow = netExt as IUtilityNetworkAnalysisExt;
                utilarr = utilflow as IUtilityNetworkAnalysisExtFlow;
                utilarr.ShowFlow = !(utilarr.ShowFlow);
                av.Refresh();
            }

       
            
            // refresh the display to update the flow direction arrows
            IActiveView mapView = ArcMap.Document.ActiveView;
            mapView.PartialRefresh(esriViewDrawPhase.esriViewGraphics, null, null);

        }
        protected override void OnUpdate()
        {
//Enable the Button once the operation is Successful
           //Enabled=True;
        }

        
   
    }

}

Code to get flow arrow using ArcObjects
Display flow arrow using Arcobjects

  • Save your Current project .Don't run your Code.
  • Go to Properties>Addinname Properties>Debug option.Set your ArcMap as the External program for debugging the code
  • Run the Code.
  • ArcMap Application will open.Now go to Customize>Customize mode>Command.Right now you will see your Addin name in the category list click on it.After that the button will get displayed on the commands window.
  • Drag the Button and put it in the Menu bar.
  • You get the ESRI Addin file bin>Debug folder of your project location
  • Now its party time :) Share your work with other through the Addin file