Monday, October 23, 2017

Upgrade or Install Python PIP in ArcGIS Desktop 10.4.1

Be The First To Comment
ArcGIS  Desktop 10.4.1’s default pip, C:\Program Files (x86)\Python27\ArcGIS10.4\Scripts  failed to install the packages throwing following error –

Fatal error in launcher: Unable to create process using '"C:\Python27\ArcGIS10.4
\python.exe" "C:\Python27\ArcGISx6410.4\Scripts\pip.exe" 
The following steps to make the pip to work

Step 1. Open command terminal as Administrator and see if pip works
      Make sure 
            C:\Program Files (x86)\Python27\ArcGIS10.4\Lib;
            C:\Program Files (x86)\Python27\ArcGIS10.4\Scripts;

            C:\Program Files (x86)\Python27\ArcGIS10.4
      are in path            
  
           pip install <package_name> , no luck [ You can Jump directly to #4]
        
Step 2. Check the pip version
            pip --version
            (pip9.0.1 as of today)

Step 3. Try to upgrade pip

            pip install --upgrade pip

            The command run successfully, but did not upgrade pip. Every time terminal complains –
You are using pip version 7.0.1, however version 9.0.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Step 4. Installing pip from beginning although it ships automatically in Python 2.7 ( Arcgis 10.)
To install pip, securely download get-pip.py.
Then run the following:

python get-pip.py
or
python get-pip.py --trusted-host pypi.python.org ( if SSL certification error occurs)

Step 5. Check pip version

pip --version

pip 9.0.1 from C:\Python27\ArcGIS10.4\lib\site-packages (python 2.7)
( You should have latest version of pip)

Step 6. Now use pip to install packages

pip install <package_name> --trusted-host pypi.python.org

           

Friday, April 14, 2017

Code Snippet: Select feature polygon(s) on Mouse Click ArcObjects C#

Be The First To Comment
Code snippet of custom feature(s) selection tool on mouse click and highlight it using ArcObjects and C#.

 class SelectFeatureTool : ESRI.ArcGIS.Desktop.AddIns.Tool  
   {  
     protected override void OnMouseDown(MouseEventArgs arg)  
     {  
       IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument;  
       IActiveView activeView = mxDocument.ActiveView;  
       IMap map = mxDocument.FocusMap;  
       ILayer layer = map.get_Layer(0); //Get 1st Layer  
       IFeatureLayer featureLayer = (IFeatureLayer) layer;  
   
       IPoint identifyPoint = activeView.ScreenDisplay.DisplayTransformation.ToMapPoint(arg.X, arg.Y);  
       ESRI.ArcGIS.Carto.IIdentify identifyLayer = (IIdentify)layer;  
       IArray array = identifyLayer.Identify(identifyPoint);  
         
       int oid = -1;  
       if (array != null)  
       {  
         object obj = array.get_Element(0);  
         IFeatureIdentifyObj fobj = obj as IFeatureIdentifyObj;  
         IRowIdentifyObject irow = fobj as IRowIdentifyObject;  
         IFeature feature = irow.Row as IFeature;  
         oid = feature.OID;  
       }  
       HighlightClickedFeature(featureLayer, oid, activeView);  
     }  
   

Wednesday, March 22, 2017

Catch Exception - Attempted to read or write protected memory in ESRI ArcObjects .Net 4.0 Framework

1 Comment
First - Don't write the code to throw "Attempted to read or write protected memory" ..it is bad.

Second - If you are working on legacy codes and COM objects that throws "Attempted to read or write protected memory" while writing ArcMap add-ins, catch exceptions to prevent application crash, in my case ArcMap.


Step #1 - Add following snippet to config file - app.config for Arc-addin

<configuration>
   <runtime>
      <legacyCorruptedStateExceptionsPolicy enabled="true" />
   </runtime>
</configuration>
Step #2

Add -

[HandleProcessCorruptedStateExceptions] 
[SecurityCritical]
on the top of function you are tying catch the exception

[HandleProcessCorruptedStateExceptions]
[SecurityCritical]
public IFeatureLayer GetOrCreateFeatureLayer(string path, esriGeometryType type, ISpatialReference sr)
{
//body
}

Thursday, July 2, 2015

Building ArcMap’s Add-in using command line

Be The First To Comment
Couple of days I have been spending on creating a build automation for ArcMap’s Add-in using Jenkins . In order to accomplish that I need to able to build my visual studio add-in solution using MSBuild.exe.

When I try to build the solution using via command line –
msbuild.exe MyArcMapAddin.sln /t:Clean,Build



The console throws the following error- 
 
(PrePackageArcGISAddIn target) -> 
  C:\Program Files (x86)\MSBuild\ESRI\ESRI.ArcGIS.AddIns.targets(37,5): error MSB4062: The "ValidateAddInXMLTask" task could not be loaded from the assembly ESRI.ArcGIS.AddIns.SDK, Version=10.0.0.0, Culture=neutral, PublicKeyToken=8fc3cc631e44ad86. Could not load file or assembly 'Microsoft.VisualStudio.Shell.9.0, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified. Confirm that the <UsingTask> declaration is correct, that the assembly and all its dependencies are available, and that the task contains a public class that implements Microsoft.Build.Framework.ITask. [SOLVED]

Monday, February 2, 2015

Getting into ESRI ArcGIS Add-in Development in .Net and ArcObjects

1 Comment
Recently, I landed into a project for ArcGIS/ArcMap Desktop add-in development using ArcObjects in C#. I am a newbie in both ArcObjects and add-in development. Googling through I got tons of snippets on the ArcMap add-in development, but I was not familiar with tailoring them to make a working application.

Then, I started to look after Youtube and Amazon to see if any good basic books or tutorials that gives me basic concepts on tailoring the  ArcObjects/.Net snippets. On youtube, I came across a video tutorials series on “.Net programming with ArcOjects”, an excellent tutorial on ArcObjects and .Net development with sample Gis data and codes to download  by Hussein Nasser. I watched all 15 episodes on add-in development using VB.Net.

From the Amazon, I bought a book entitled, “Beginning ArcGIS for Desktop Development using .NET ” by Pouria Amirian, with a blind believe on the reviewers, but it turned out the 
The book is wonderful! The author does an excellent job of explaining basic .NET concepts and tying them into ArcObjects.This book was long overdue and it seems like the author really took his time to ensure the content was organized in a logical way and concepts are thoroughly explained.

I would recommend this book and Youtube video to anyone who is interested in learning ArcObjects in .NET. The both author includes .NET code samples as well as the solutions in C#/VB. Lots of useful stuff in there and I think when you finished you will have a good starting point to ArcGIS Desktop development.

Friday, January 23, 2015

Parenting Win-form and WPF form in ArcMap

Be The First To Comment
Parenting of Win-form windows and WPF windows within a ArcMap application using C#.Net code snippets-

Step 1: Create a ArcMapWrapper.cs, wrapper class

        using System;
        using System.Windows.Forms;
        using ESRI.ArcGIS.Framework;

        namespace ArcMapClassLibrary2
        {
               class ArcMapWrapper:IWin32Window
               {
                    private IApplication _arcMapApplication;

                    public ArcMapWrapper( IApplication mApplication)
                    {
                       _arcMapApplication = mApplication;
                    }

                    public IntPtr Handle
                    {
                       get { return new IntPtr(_arcMapApplication.hWnd); }
           
                     }
                 }
           }

Step 2: Access from Win-form

              WinForm fm = new WinForm();                        
              ArcMapWrapper wrapper= new ArcMapWrapper(map_application);  
              fm.ShowInTaskbar = false;        
              fm.Show(wrapper);

              //Try, it behaves like a modal dialog
              //fm.ShowDialog()

Tuesday, January 13, 2015

Create standalone feature class and feature class inside feature dataset on Geodatabase using ArcObjects

Be The First To Comment
 public void StartUp()   
    {   
     try   
     {   
       //create gdb   
      const string path = "D:/SampleDatasets/NewShp";   
      const string fileGDBName = "sample.gdb";   
      const string fileGDBAddress = path + "/" + fileGDBName;   
      const string featureDatasetname="polygonFeatureClasses";   
      const string featureClassname = "MytestPolygons";   
      if (System.IO.Directory.Exists(fileGDBAddress))   
      {   
       Console.WriteLine("already exist");   
       // return;   
      }   
      Type factoryType = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");   
      IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType);   
      IWorkspaceName workspaceName = workspaceFactory.Create(path, fileGDBName, null,ArcMap.Application.hWnd);   
      MessageBox.Show("gbd created!");   
      
      //Create feature dataset   
      IFeatureWorkspace fws = workspaceFactory.OpenFromFile(fileGDBAddress, ArcMap.Application.hWnd) as IFeatureWorkspace;   
      
     //check the existance of FeatureDataset   
      IWorkspace2 ws = fws as IWorkspace2;   
      if(ws.get_NameExists(esriDatasetType.esriDTFeatureDataset,featureDatasetname)==true)   
      {   
       MessageBox.Show("Feature dataset is already exists");   
      }  

      #region feature Class inside feature Dataset : Region_1 (Choose either Region_1 or Region_2)  
     
      //Create a spatial refrence/extract spatial refrence from map   
      //Infuture will access through the arcmap   
      ISpatialReferenceFactory spatialReferenceFactory = new SpatialReferenceEnvironmentClass();   
      int coordinateSystemID = (int) esriSRGeoCSType.esriSRGeoCS_WGS1984;   
      ISpatialReference spatialReference =spatialReferenceFactory.CreateGeographicCoordinateSystem(coordinateSystemID);   
      

Friday, March 22, 2013

Good Book for GIS Beginners : Book II

Be The First To Comment


Understanding GIS: An ArcGIS Project Workbook, is a very user-friendly written book for those interested to begin using ESRI ArcGIS Desktop 10 or ArcGIS Desktop 10.1 using real data from the City of Los Angeles' Department of Public Works, Bureau of Engineering's Mapping Division, and Department of Recreation and Parks and to manipulate it using the power of GIS.

 Don't expect to become a GIS expert at the end because this is simply a good introduction to ArcGIS. The book guides the reader step-by-step, mouse-click-by mouse-click, decision-by-decision through a GIS project to determine for yourself which locations along the river are best suited for public recreational use in Los Angeles. At the end, you will have learned many of the fundamentals of GIS generally and ArcGIS specifically which aims at finding a suitable land parcel(s)for a new park area in Los Angeles .You use real data which comes in the companion DVD. When you reach the final stage in chapter 6 and follow all the careful steps to manually select the best areas and you learned why you do so, you discover in the following chapter (chapter 7) that you can do the same in a much quicker way by using a visual graphing tool, a marvel in my opinion of ArcGIS Desktop.

Sunday, January 13, 2013

Popular GIS Books

Be The First To Comment
Books Pro Cons
It provides solid guide to how geospatial analysis work, particularly with respect to GIS. The book emphasizes conceptual workflows and with basic math which is helpful for creating own code and also getting an understanding of what's happening under the hood in contemporary GIS. It is better to have an update because lots of changes in GIS software over last five years.
This book is for typical GIS user aspiring to design good maps. It is illustrating GIS map software and throughout with map samples in color which is especially useful for those who has little prior training or experience in map making. This is acceptable book for beginners but very little information of advanced users. It hardly touches on advanced cartographic representations.
This book explains the computational geometry and algorithms concisely and very readable. It emphasis on describing algorithms and data structures theoretically. It presents pseudo code with lots of figures that is very easy to understand and follow.

It's also worth reading for all computer scientists and mathematicians who are working on geometry.

This is good text/reference book for graduate course.
Focused on geometric computation and algorithm, very complicated for beginners, who does not have prior computer programming knowledge.

The various algorithms and concepts often used in this book are triangulation, indexing, calculating intersection, shortest paths etc.
The book illustrates the most common cartographic deceptions, and provides some excellent color guides. If you want to learn how to make influential maps for a cause, this is the book!. The reader can learn what to look for and how to avoid the inadvertent or unintentional 'lies'. Worth the effort! Basically, the book as an introduction to the science of cartography and targeted for prospective cartographer or decision making authority.
The book details the use of freely available open source mapping software and tools such as MapServer, GDAL, OpenEV, and PostGIS to create web gis and web maps.

Mostly focused on UMN Mapserver for web mapping and building web gis.
Not much technical discussion on how GPS databases work, how to decode GIS information.
The book is fairly shallow. It will give you a couple of basic examples of how to use some pieces of software, but for anything more complicated, you have to look elsewhere.

Wednesday, January 9, 2013

GIS Programming for GIS Analyst using Python

Be The First To Comment


Penn state has a nice collection of ArcGIS & Python programming step by step guide for their GEOG 485 students, which is also available for non-students via Penn state website.  This course’s is main aim is to make student able to use the Python scripting language to automate GIS tasks in ArcMap, assemble ArcView geoprocessing tools into models to solve GIS problems, and run the tools from scripts to automate GIS tasks. 

Although no previous programming experience is assumed, the course's target is to make a student as a GIS programmer/analyst in ArcGIS and Python environment. 

The course is basically divided into four parts:

Friday, December 21, 2012

Dissolve ERROR 999999: Error executing function. The Geometry has no Z values.

Be The First To Comment

Solution to Dissolve ERROR 999999: Error executing function. The Geometry has no Z values.
ArcToolbox>Repair Geometry and delete features with empty geometries
ArcToolbox > Conversion Tools>To Shapefile>Environments>General Settings>Output has Z values = Disabled, Output has M values = Disabled>OK>Input features/Output features>OK
ArcToolbox>Dissolve> happy :))

Source

Tuesday, March 13, 2012

Solved: AutomationException 0x80004005 - Unspecified error

1 Comment

I was writing ArcGIS extension for Geoprocessing using JAVA and ArcObjects 10. My need was to process about 1000 PRISM raster datasets globally to compute various environments.

My application did work up to 45- 50 raster files without any problems in loop, then if fails with “AutomationException 0x80004005 - Unspecified error”. If I restarted the application again works for next 45-50 raster files and then crashes with the same error.

I still couldn’t figure out what was the exact cause for application failure-my guess is it may be due to memory management/garbage collection problem among ArcGIS COM objects and JAVA objects.
Fortunately, I solved this issue by reinitializing ArcGIS engine (hope re-initialization breaks the locks and flushes the garbage) after 20 raster files processing. Now, the application works well without any breaks but little bit slower while initializing the ArcGIS engine after 20 raster files processing.

Wednesday, May 25, 2011

Raster Misalignment with Base Data in ArcMap10

Be The First To Comment
In the early Friday morning of mid May, I got an email from one of my team member about raster misalignment problem in ArcGIS10. I also tried to overlay couples of previously working Tiff and Grid raster files in ArcMap9.3 and ArcMap10. The ArcMap9.3 overlay raster files perfectly aligned as we all desired, but ArcMap10 did not.
Unaligned

Aligned

From the ESRI website, I got to know that the issue of misalignment of Tiff in ArcMap10 is a bug in ArcGIS 10. The ESRI team announced two solutions to solve Tiff shift into wrong geographic locations:

Tuesday, May 3, 2011

Map re-projection in ArcMap or ArcGIS

Be The First To Comment
Here, I am trying to show how to project/re-project US shape file into AEA conic USGS projection using ArcMap.

Follow the following steps:

1. Right click on Layer -> click on Coordinate System

2. Unfold Predefined -> Unfold GCS -> Unfold North America

3. Select North American Datum 1983

4. Click Apply and Click OK

5. Add Feature Data (Points/Lines/Polygons)

6. A warning may appears but ignore it.

7. Find Data Management Tools -> Select Project (feature) Tool

8. Input Dataset or Feature Class (Enter the name of layer needed to be projected.)

9. Input Coordinate System -> Click on Hand icon -> Click Select -> Unfold GCS -> Unfold North America -> Select North American Datum 1983

10. Click Add

11. Click Apply and Click OK

12. Output Dataset or Feature Class (Enter the location of output file and location name: *.shp)

13. Output Coordinate Systemè Click on Hand icon -> Click Select -> Unfold PCS -> Unfold Continental -> Select North American -> Select USA Contiguous Albers Equal Area Conic USGS.prj

14. Click Apply and Click OK

15. New Projected map layer will be created. But  might not be able to see that projected layer in same data frame. Then what?

16. Trick: Add new data frame.. HOW?

17. Click Insert from Arc Map tool bar -> Click Data Frame

18. Drag projected map layer into it.

19. Cheers !!!  Your Map is projected.

20. If still problems persist; check on Environmental Variable Setting.

Saturday, April 30, 2011

Mapping the Disease Trends

Be The First To Comment
West Nile Virus (WNV) is the most widespread arbovirus (viruses that are transmitted by arthropods) in theworld. . During the period of 1996 -1999, the WNV became prevalent insouthern Romania, the Volga delta in southern Russia, and the northeastern United States. The spread of WNV covered the United States from coast to coast in four years, and by then it had 7 infected about one million Americans, killing about eight hundred.

Here I mapped the spatial trends of WNV virus in the United States of America.

Check website - http://globalmonitoring.sdstate.edu/eastweb/maps/wnv1999_2011/

Friday, March 18, 2011

How to get Color Brewer Ramp in ArcMap 10?

2 Comments

There are two ways to achieve this:

Method A steps:

1. Download Color Brewer Color Ramp Style Set from http://arcscripts.esri.com/details.asp?dbid=14403

2. Unzip it.

3. Open the Layer properties and click on ‘Symbology’ tab in ‘ArcMap 10’.

4. Double click on one of the color symbol beneath ‘Symbol’ that gives you a ‘Symbol Selector’ window.

5. Click “Style References..”

6. Click “Add Style to List..” and add ‘ColorBrewer.style’ that is obtained from setp 2.

7. If you made it correctly it should be listed in the ‘Style References’.

8. Select ‘ColorBrewer.style’ and make it default.

9. Close the layer properties once and open it again, you will see newly generated color ramp.


Method B steps:

1. You have to pick each color ramp value manually from http://colorbrewer2.org/ .

2. Open the Layer properties and click on ‘Symbology’ tab in ‘ArcMap 10’.

3. Double click on one of the color symbol beneath ‘Symbol’ that gives you a ‘Symbol Selector’ window.

4. Click on ‘Edit Symbol’.

5. Click on Color box inside ‘Simple Fill’ area.

6. Click on “More Colors” which gives you Color Selector.

7. Choose RGB from Drop down box located in the top right.

8. Then, update values that come from Colorbrewer.

Voila Cheers!!!!!

I would like to recommend ‘Method A, because it is faster than Method B. (Does the same work but time consuming)

The author of color brewer, Cynthiya Brewer also published a book Designing better Maps in ArcGIS.



 

© 2011 GIS and Remote Sensing Tools, Tips and more .. ToS | Privacy Policy | Sitemap

About Me