Posts

Showing posts with the label ArcGIS

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

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 }

ESRI FeatureClass vs Feature Layer

Feature Layer:  A layer that references a set of feature data. Feature data represents geographic entities as points, lines, and polygons. Feature Class: In ArcGIS, a collection of geographic features with the same geometry type (such as point, line, or polygon), the same attributes, and the same spatial reference. Feature classes can be stored in geodatabases, shapefiles, coverages, or other data formats. Feature classes allow homogeneous features to be grouped into a single unit for data storage purposes. For example, highways, primary roads, and secondary roads can be grouped into a line feature class named "roads." In a geodatabase, feature classes can also store annotation and dimensions. Rasterized Feature Layer: A feature layer in ArcGlobe that exists as points, lines and polygons but is rendered as cell data. When layers are added to ArcGlobe, they may automatically be rendered in raster format to retain their cartographic symbology.

Enable ESRI ArcGIS extension licence from C#

Code snippet on enabling ESRI ArcGIS extension licence for spatial analysis using C# ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); ESRI.ArcGIS.RuntimeManager.BindLicense(ESRI.ArcGIS.ProductCode.Desktop); UID pUid = new UIDClass(); pUid.Value = "esriSpatialAnalystUI.SAExtension"; // Add Spatial Analyst extension to the license manager. object v = null; IExtensionManagerAdmin extensionManagerAdmin = new ExtensionManagerClass(); extensionManagerAdmin.AddExtension(pUid, ref v); // Enable the license. IExtensionManager extensionManager = (IExtensionManager)extensionManagerAdmin; IExtension extension = extensionManager.FindExtension(pUid); IExtensionConfig extensionConfig = (IExtensionConfig)extension; if (extensionConfig.State != esriExtensionState.esriESUnavailable) { extensionConfig.State = esriExtensionS...

Feature to Raster Conversion Using C# and ArcGIS

Import ArcGIS.ConversionTools and ArcGIS.Geoprocessor then pass the file paths as param into following function you will get the resulting raster out of shapefile. using ESRI.ArcGIS.ConversionTools; using ESRI.ArcGIS.Geoprocessor; public static void Rasterize(string inputFeature, string outRaster, string fieldName, int cellSize) { //Runtime manager to find the ESRI product installed in the system ESRI.ArcGIS.RuntimeManager.Bind(ESRI.ArcGIS.ProductCode.Desktop); Geoprocessor geoprocessor = new Geoprocessor(); geoprocessor.OverwriteOutput = true; FeatureToRaster featureToRaster = new FeatureToRaster(); featureToRaster.cell_size = cellSize; featureToRaster.in_features = inputFeature; featureToRaster.out_raster = outRaster; featureToRaster.field = fieldName; geoprocessor.Execute(featureToRaster, null); }

Vector to Raster Conversion using GDAL & C#

Image
I have been working on a .Net based project that requires feature to raster conversion without using ESRI ArcObjects. The GDAL seem's an obvious solution to us and wrote a small snippet for rasterize layer using Gdal and C#. Hope it will help someone someday... Step 1: Setup the environmental variables for GDAL  Setup the environment as described in   Getting Started with C# and GDAL OR  (Copied here for future reference - ) Getting started with C# and GDAL The Geospatial Data Abstraction Library (GDAL) is great if you want to process raster data, especially regarding format conversion. I want to use GDAL for a biodiversity modelling project, so I had a look at the C#-bindings of GDAL. The described steps work both with VS 2010 as well as VS 2012, what you need to do is: Download the latest version of the precompiled GDAL binaries from  here . Choose the ones that suit your system (32bit or 64bit). Extract the contents from the zip file ...

Building ArcMap’s Add-in using command line

Image
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 avail...

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

Image
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 excell...

Good Book for GIS Beginners : Book II

Image
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 fo...

Python Scripting for ArcGIS

Image
Python Scripting for ArcGIS is a new text from Esri Press by Paul A. Zandbergen (2013). It isn’t the first Python book for the geospatial community or even focused on ArcGIS, but it is the first that has the Esri logo on it. Much like other recent books on Geo/Python we have seen, it focuses on integrating an introduction to Python with the industry specific materials. As Frank mentioned when he highlighted the book in a previous podcast, this allows users to gain exposure to Python, but it doesn’t fall back on the (in my opinion) bad habit of most programming texts of spending half of the book on the language and concepts before even getting to the application in the specific area. There is a time and place for that approach in Python specific books. When you add another software library to a book, then use it from the get go.

Popular GIS Books

Image
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 algori...

GIS Programming for GIS Analyst using Python

Image
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 n o 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:

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

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

Extract Raster Values from Points

The R blog article encourages me to write this solution to extract Raster values from points in R. In geospatial analysis, extracting the raster value of a point is a common task. If you have few raster files or few points; you can extract the raster value by overlaying a point on the top of the raster using ArcGIS. What will you do, if you have hundreds of raster files and thousands of points? The easy solution is use loop in Python and ArcGIS. Is loop efficient to use? No. Can loop be avoided? Yes. Then how?  Follow the steps: Step 1: Create a Raster stack or Raster brick of your raster files using “raster” package in R . For example: rasStack = stack(raster1, raster2,raster3 …rasterN) Step 2:   Read point data, and convert them into spatial points data frame. Sample: pointfile.csv Point_ID LONGITUDE LATITUDE 1 48.765863             -...