Wednesday, December 9, 2015

Leaflet WMS layer custom projection on fly

Be The First To Comment
For most of the WMS mapping applications the Google Web Mercator (GWM) projection is sufficient. The GWM is default standard for web mapping and widley accepted by Bing, Google, OSM, OpenLayers(default), and Leaflets(default). However some mapping application required custom projection other than Google Mercator projection to display data. Then, how to project/re-project the data other than wms's default projection, GWM.

The following snippet shows the WMS layer custom projection in LEAFLET for  Albers equal area and UTM zone 13.

Step 1.

First of all include -
         leaflet.js
         proj4.js
         proj4leaflet.js  in following order.    

     <link rel="stylesheet" href="http://cdn.leafletjs.com/leaflet-0.7/leaflet.css" />  
     <script src="http://cdn.leafletjs.com/leaflet-0.7/leaflet-src.js"></script>  
     <script src="//cdnjs.cloudflare.com/ajax/libs/proj4js/2.0.0/proj4.js"></script>  
     <script src="http://mapserv.utah.gov/cdn/examples/proj4leaflet.js"></script>  

Step 2: Create new Proj4Leaflet CRS

Find your desired custom projection type in http://spatialreference.org/ and punch the the projection variable in the following code snippet.









    

Friday, November 6, 2015

Passing R variables dynamically to JavaScript for data visualization

Be The First To Comment
For a random project, I was interested to see if there a way to pass data between R and JavaScript. My purpose was to populate a Highcharts graph dynamically using preprocessed data from R. Of course, my first look was rCharts, an R package to create and publish interactive JavaScript visualizations, which also support the Highcharts for building interactive graphs and plots. The rCharts is a great package and widely popular among R users to create interactive charts without knowing the underlying JavaScript.

My requirement was not only the interactive chart but also dynamic that can create chart on near real time as shown in Highcharts demo. It seems to me that rCharts neither provide a straightforward way to add-point on series nor a way to customize the JavaScript to create such dynamic charts. As far as I know, it has limitations (or out of context of rCharts philosophy) for doing sophisticated jobs that requires JavaScript customization. At this moment it only supports the 24 functions from Highcharts API through R interface.

Wednesday, October 14, 2015

Read ESRI File Gdodatabase (FileGDB) using GDAL & C#

Be The First To Comment
If you are creating a new project- set up GDAL & C# environment as described here

Code snippet to read ESRI File Geo-database (FileGDB) using GDAL and C#. By default it uses GDAL's 'OpenFileGDB' (read only) driver with out any external dependencies. If you are interested in editing GDB feature class you should use 'FileGDB' (read-write) driver, which had dependency on ESRI's FGDB API SDK. The UCLA's internal testing showed that ESRI's FileGDB driver drags the performance than OpenFileGDB for read-only operation. So choose the driver according to your needs.

However, both GDAL drivers and ESRI's API do not support the raster dataset inside the GDB till date.

 public static void ReadEsriGdb(string gdbPath, string featureLayerName)  
     {  
       //Register the vector drivers  
       Ogr.RegisterAll();  
   
       //Reading the vector data  
       DataSource dataSource = Ogr.Open(gdbPath, 0);  
       Layer layer = dataSource.GetLayerByName(featureLayerName);  
          
     }  
   
     //call  
      ReadEsriGdb("gdbPath.gdb", "counties");  

Thursday, October 8, 2015

Clip a raster from feature shape file using C# and ArcObject's geoprocessor

Be The First To Comment
Code snippet in clipping a raster from feature shape file using C# and ArcObject's geoprocessor -

 public static void ClipRaster(string inRaster, string inClipFeature, string outTempRaster)  
     {  
       Clip clipTool = new Clip();  
   
       //set clip parameters  
       clipTool.in_raster = inRaster;  
       clipTool.out_raster = outTempRaster;  
   
       //clip extent  
       clipTool.in_template_dataset = inClipFeature;  
   
       Geoprocessor gp = new Geoprocessor();  
       gp.OverwriteOutput = true;  
       gp.AddOutputsToMap = false;  
         
       try  
       {  
         IGeoProcessorResult result = (IGeoProcessorResult)gp.ExecuteAsync(clipTool);  
         while(result.Status != esriJobStatus.esriJobSucceeded)  
         {  
           //Console.WriteLine(result.Status.ToString());  
           System.Threading.Thread.Sleep(100);  
         }  
       }  
       catch (Exception ex)  
       {  
         object level = 0;  
         Console.WriteLine(gp.GetMessages(ref level));  
         Console.WriteLine(" Failed to clip raster using ESRI clip tool " + ex.Message);  
       }  
   
     }  

Enable ESRI ArcGIS extension licence from C#

Be The First To Comment
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 = esriExtensionState.esriESEnabled;  
       }  
       else  
       {  
         Console.WriteLine("No Spatial Analyst License available");  
       }  
   
   

Thursday, September 24, 2015

Calculate zonal-statistics using ESRI ArcObjects and C#

Be The First To Comment
Import the following references in the project.

using ESRI.ArcGIS.Geoprocessor;
using ESRI.ArcGIS.SpatialAnalystTools;
using ESRI.ArcGIS.esriSystem;

This solution is only works for single band raster. For multi-band raster zonal statistics I will make a separate post soon.

 public static void ComputeZonalStatisticsFromEsri(string feature, string zoneField, string valueRaster, string outputTable)  
     {  
   
       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;   
   

Tuesday, September 22, 2015

Read raster block by block or row by row using GDAL and C#

Be The First To Comment
If you are creating a new project- set up GDAL & C# environment as described here

Code Snippet: Read raster block by block using GDAL and C#
 private static void ReadRasterBlocks(ref Dataset valueRaster)  
 {  
   Band bandValueRaster = valueRaster.GetRasterBand(1);  
     
   int rasterRows = valueRaster.RasterYSize;  
   int rasterCols = valueRaster.RasterXSize;  
     
   const int blockSize = 1024;  
   
   for(int row=0; row<rasterRows; row += blockSize)  
   {  
      int rowProcess;  
      if(row + blockSize < rasterRows)  
      {  
        rowProcess = blockSize;  
      }  
      else  
      {  
        rowProcess = rasterRows - row;  
      }  
   

Thursday, September 17, 2015

Tutorial: Getting started with ArcGIS Application Development using ArcObjects and Vb.NET

Be The First To Comment
This will be a series of videos on Programming with ArcObjects by Hussein Nasser where he features a fictional project called Bestaurants and gradually added functions to the project from scratch using ArcObjects and Vb.NET programming on top of ArcGIS. An excellent tutorial for beginners to learn how to use ArcObjects to build an ArcGIS application.

Wednesday, September 16, 2015

Read a raster file into an Array using C# and GDAL

Be The First To Comment
If you are creating a new project- set up GDAL & C# environment as described here

Code snippet: Read raster into an Array using GDAL and C#

 //Register all drivers  
 Gdal.AllRegister();  
   
 //Read dataset  
 Dataset rasterDataset = Gdal.Open("rasterName.tif", Access.GA_ReadOnly);  
 if (rasterDataset == null)  
 {  
      Console.WriteLine("Unable to read input raster..");  
      System.Environment.Exit(-1);  
 }  
   
 //raster bands  
 int bandCount = rasterDataset.RasterCount;  
 if (bandCount > 1)  
 {  
      Console.WriteLine("Input error, please provide single band raster image only..");  
      System.Environment.Exit(-1);  
 }  
   

Feature to Raster Conversion Using C# and ArcGIS

Be The First To Comment
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);  
     }  
 

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

About Me