TitlePages

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

Tuesday 25 November 2014

Working with Group layers through Python

TOOL USED:  arcpy.mapping

Python script will be deployed in the ARC Toolbox to create the Conversion Tool
WORKING OF THE TOOL:
This tool will iterate through each layer in the group layer and perform operation on each layer for every iterations

PROCEDURE:


  • Create a New Script tool in your toolbox of your ArcCatalog 
  • Set any empty python code file as source file in which you are going to write your script
  • Set Output layer as input parameter and group layers as the data Type
  • Copy the following code into your python code file



import arcpy
from arcpy import env
arcpy.env.overwriteOutput=1
outputgrouplayer=arcpy.GetParameter(0)

#Assign the output group layer to a variable, to be used later
lyrs =outputgrouplayer

print lyrs
#Create a Mapping Layer out of the Group Layer
groupLayer = arcpy.mapping.Layer(lyrs)

#Get a list of all the mappping layers, the first return will be the Group Layer itself
newLyrs = arcpy.mapping.ListLayers(groupLayer)

#Iterate through all of the Layers (mapping layers)
for lyr in newLyrs:
    #Because the first return is the group layer itself, we check for this, and move on
    if not lyr.isGroupLayer:
        print "Layer name is: {0}. Count is: {1}.".format(lyr.name, str(arcpy.GetCount_management(lyr)))

  • This will print the layer name and count of feature for every layer in the Group layer inputted
  • Run the script tool and target your group layer as the input in the parameter box. Click on Ok
  • Now it is Party time. Happy Coding

Google Maps Photosphere



Take a look Inside the Photosphere of Italian Mountains 


 Click here---------http://bit.ly/1vJPpfe


Create your Own Google Photosphere

 The method of creating a attractive google photosphere is easy now. Now a days google is setting up camera mode to Android powered devices make user to create their own photosphere and publish and share online

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

Saturday 22 November 2014

Where is that ATM?


To read the source Content

Where is that ATM?


Mike Sanderson suggests how Big Data can help us make better decisions - provided we can crack the thorny issue of ontology

About thirty years ago we had this marketing strapline for a multi-dimensional cube analyser. It went along the lines of being able to carry out work efficiently (doing the job right) and effectively (doing the right job). Twenty years ago Hammer & Champy1 set the IT consultancy world alight with the concept of business process re-engineering (BPR). This was about doing the job right and re-organising processes accordingly. 

The IT industry now has the tools to identify what the right job is, to go alongside our ability to engineer business processes. It’s known as Big Data in the industry. My proposition is simple, we now have tools to analyse structured and unstructured data to make better decisions, like where to find an ATM at the local supermarket.

Like BPR, its origins came from the consultancy world. In the Big Data phenomenon, McKinsey2 grabbed a large share of the zeitgeist at day one. Like most in our industry I suppose, I groaned inwardly as the cynic in me read the column inches on Big Data. After all, as Henderson said in September’s issue3, we have always had big data in spatial. The trouble is that McKinsey’s view of big data is built around personal location data – that coming from tablets and mobiles. What must we do so that the location industry plays a part?


About co-ordinates


Using location data is dangerous. Examine the two images at the top of the next page concerning the possible range of North Korean missiles. That on the left might equate to a big data answer without geodesy playing a part. That on the right ... well make up your own mind.


About scale


In thinking about this subject I came across the Data Science@Berkeley Blog on What is Big Data? The first contributor (John Akred, CTO of Silicon Valley Data Science) included these words in his contribution:

“Advances in sensing technologies, the digitization of commerce and communications, and the advent and growth in social media are a few of the trends which have created the opportunity to use large scale, fine grained data…”.

So I have no need to be worried about scale. It seems they get it after all, or perhaps not? As with the geodesy example, the unwary will not necessarily get the right answer. We can smile knowingly about these issues or we can help the big data users out. But before we get to how we might do this, there is one area with which the spatial industry and the big data industry both struggle.


About semantics


We can’t get to the right answer if we can’t frame a question that big data and the spatial industry jointly understand. This is not about a point-in-polygon search it’s about the ontology word that frightens everyone off. What do I mean when I say St. Pancras station? It could be the façade, the concourse, the tracks, the platforms, the hotel or all of these. But unless we know we will arrive at either the wrong answer or the wrong location. Big data will need to solve this issue if it is going to succeed.


What next?


I can think of three options where the spatial industry can play a part. There are probably others, but I do not have space for them here. Some of these ideas were also discussed last month by Millard (Frankenstein’s Data, GeoConnexion, Sep 2014) I am just trying to formalise them here. They are:

  • Intermediate

  • Add co-ordinates to enterprise data

  • Provide a platform to assure data quality.

Intermediate: This involves taking the complexity of scale and geodesy out of spatial data for the non-spatial user. The user interface will have to solve the ontology issue described above and as Millard describes the customer will want to know what the costs and benefits are of using open data only, a mixture of open and licensed data or licensed data only. 

Add co-ordinates to enterprise data: The biggest issue is that most enterprise data does not have geo co-ordinates attached. So all those work orders in asset intensive industries raised through Enterprise Management work management applications; the financial markets buy and sell orders are two examples where geo co-ordinates are not entered typically. In these examples we may be trying to optimise work planning or detect fraud in the latter example. The 1990s solution to these challenges involved heavy lifting of data and trying to integrate GIS and work management applications. That hasn’t worked effectively.

Our industry has been good at geocoding and reverse geocoding but tended to internalise the results of these operations within the GIS. It’s time to do it the other way around and if a map is the required output, then interface.

Provide a platform to assure data quality: I would contend that it is not enough to let the market decide what represents a good quality data set. As I have described above, and others have also, spectacular failures can occur when spatial data are misused. 1Spatial has provided a cloud-based platform for nearly five years for users to test data for geometric and topological consistency as part of a triple A data approach. 

The genie is out of the bottle in terms of personal location data being available to big data decision-makers (and it has been to governmental decision-makers for even longer), so I can do no better than quote Dr. Brian T. Gray, Assistant Deputy Minister, Earth Sciences Sector, Natural Resources Canada:

“Canadian government departments are working together to launch the Federal Geospatial Platform to enable online discovery, access, integration and visualization of multiple layers of accurate, authoritative and accessible geospatial information. That way users can search once and find everything.” 


Conclusion


So will the combination of BPR and Big Data make organisations more effective and more efficient? The answer to that is yes if the GIS industry helps the enterprise handle location more easily. And we will both benefit from working together to crack the ontology problem.

Friday 21 November 2014

Working with Group layers through Python


Working with Group layers through Python


 This tool will be helpful in accessing the Trace Managaement Results
TOOL USED:  arcpy.mapping
Python script will be deployed in the ARC Toolbox to create the Conversion Tool
WORKING OF THE TOOL:
This tool will iterate through each layer in the group layer and perform operation on each layer for every iterations
PROCEDURE:
·         Create a New Script tool in your toolbox of your ArcCatalog
·         Set any empty python code file as source file in which you are going to write your script
·         Set Output layer as input parameter and group layers as the data Type
·         Copy the following code into your python code file


import arcpy
from arcpy import env
arcpy.env.overwriteOutput=1
outputgrouplayer=arcpy.GetParameter(0)

#Assign the output group layer to a variable, to be used later
lyrs =outputgrouplayer

print lyrs
#Create a Mapping Layer out of the Group Layer
groupLayer = arcpy.mapping.Layer(lyrs)

#Get a list of all the mappping layers, the first return will be the Group Layer itself
newLyrs = arcpy.mapping.ListLayers(groupLayer)

#Iterate through all of the Layers (mapping layers)
for lyr in newLyrs:
    #Because the first return is the group layer itself, we check for this, and move on
    if not lyr.isGroupLayer:
        print "Layer name is: {0}. Count is: {1}.".format(lyr.name, str(arcpy.GetCount_management(lyr)))
  • This will print the layer name and count of feature for every layer in the Group layer inputted
  •  Run the script tool and target your group layer as the input in the parameter box. Click on Ok
  • Now it is Party time. Happy Coding

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

Wednesday 19 November 2014

ESRI Addin Button to Zoom to Selected Layer in TOC

Software Required:
  1. Microsoft Visual Studio 2010 +
  2. ArcMap 10.2 or more
  3. 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 on the onclick() method of the button.cs file.
  • Add the References(Right click references in Solution Explorer and select Add References) based on your classes usage
C#

protected override void OnClick()
        {
IMxDocument mdoc = ArcMap.Application.Document as IMxDocument;

//the following two lines of code are the same
IActiveView activeView = mdoc.ActiveView;
//IActiveView activeView = mdoc.FocusMap as IActiveView;
//get the selected layer in the Table of Contents
ILayer lr = mdoc.SelectedLayer;
//check if there is a selected layer or not
if (lr != null)
{
activeView.Extent = lr.AreaOfInterest;
//invoking Refresh method
//results in redrawing the whole view
activeView.Refresh();
}
}
  • 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 now open.Go to Customize>Customize mode>Command.Right now you will see your Addin name in the category list click on it, respective button will get displayed on the rightcommands 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

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