Tuesday, September 15, 2015

Clip a raster with shapefile using C# and Gdal

Be The First To Comment



Over the week, I stumbled on problem clipping raster with feature using C# and Gdal and come up with following solution, which clips the features and fills no data value for missing raster  values inside the extent. If you are creating a new project- set up GDAL & C# environment as described here

Saturday, September 12, 2015

FIXED: Shape file import error in Postgis AddGeometry column doesn't exist

2 Comments
Last week I have installed PostgreSql/PostGis and PgAdmin. Once I have tired to import shape file from PgAdmin using "PostGIS Shape file and DBF Loader 2.1" as below.


But it throws an error complaining "File import error in PostGis AddGeometry column doesn't exist" as shown in figure below 

Then, I found out that the spatial extension is not enabled in my database. The following image shows the steps to enabled the spatial extension in the database. 

Open new extension and name it postgis.

 



Then import the shape file again... Voila it works

Friday, September 11, 2015

Fetching environmental data from Meso West API version 2

Be The First To Comment
In few months the MesoWest group will depreciated their MesoWest data API version 1 and fully moving over version 2. The Meso West data API 2 have been in the production for most of this year. The API v2 has significantly faster and more useful than version 1 and well as increased response time and availability including accumulated precipitation, simple station statistics, and climatological data requests.

Here is the code snippet to extract data variables using jQuery in JSON format. 
 $.getJSON('http://api.mesowest.net/v2/stations/nearesttime?callback=?',  
      {  
           state:'ca',  
           county:'Los Angeles,San Diego,',  
           latestobs:1,  
           status:'active',  
           token:'API_TOKEN_PROVIDED_BY_MESOWEST_GROUP',  
           within:15, //Observations with in past 15 min  
           vars:'air_temp,relative_humidity,wind_speed,wind_direction',  
           obtimezone:'local'  
      },  
      function (data)  
      {                       
        for(var i=0;i<data.STATION.length;i++)  
           {       
                //check if all stations contain all the observation we need  
                if((data.STATION[i].OBSERVATIONS.hasOwnProperty("air_temp_value_1"))&& (data.STATION[i].OBSERVATIONS.hasOwnProperty("wind_speed_value_1"))&&  
                     (data.STATION[i].OBSERVATIONS.hasOwnProperty("wind_direction_value_1"))&&(data.STATION[i].OBSERVATIONS.hasOwnProperty("relative_humidity_value_1")))  
                {  
                     var stn = data.STATION[i];  
                     var dat = stn.OBSERVATIONS;  
                     var stnInfo =stn.NAME.toUpperCase();  
                     var elev=parseInt(stn.ELEVATION);                                                         
                     //displaying air temperature from all stations   
                     console.log(Math.round(dat.air_temp_value_1.value));                          
                }  
           }  
  })  
 .done(function()  
 {  
 })  
 .fail(function()  
 {  
      alert("Could not access the MesoWest Data!");  
 });  

Vector to Raster Conversion using GDAL & C#

Be The First To Comment
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 
OR 
(Copied here for future reference - )

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 to a location on your hard disk e.g. C:\Program Files\GDAL (I ran into a number of AccessViolationExceptions when I used the binaries from FWTools 2.4.7).
  • Include both the path to C:\Program Files\GDAL\bin\gdal\csharp as well as C:\Program Files\GDAL\bin in your PATH system variable.
Setting of the PATH variable
Creating a Console Application (VS 2010)
  • Add four of.the dll-files that can can be found at C:\Program Files\GDAL\bin\gdal\csharp (or wherever your installation path of the current binaries is) to your project references: gdal_csharp.dllgdalconst_csharp.dllogr_csharp.dll and osr_csharp.
Adding necessary references (VS 2010)
  • Build the solution. If you are on a 64bit system and you are using the 64bit GDAL binaries you have to make sure you actually build for 64bit (you will get errors otherwise when you try to run the program).
Setting of the platform target for 64bit (VS 2012)
  • Now you can run the program with some data. Include a reference to one of the raster files in the Command line arguments field of your Debug options (in the properties of your GDALInfo project; don't forget to put the path inside double quotes of it includes blanks).
  • Run the program (Ctrl-F5). It should show you something similar to the following:
Output of GDALInfo
That's it. Now you can use the other example C#-programs to open, copy, manipulate raster data in variety of file formats. For some of the other example files it is necessary to add some additional references (e.g. System.Drawing).
(End copy)

Step 2: Open visual studio and create C# console project

Import references 
  • gdal_csharp
  • gdalconst_csharp
  • ogr_csharp
  • osr_csharp
Import Namespaces

using OSGeo.GDAL;
using OSGeo.OGR;
using OSGeo.OSR;

Thursday, August 20, 2015

Capitalize each word after forward slash in Java Script : Code snippet

Be The First To Comment
 function getFormattedText() {  
   var formattedString= capitalizedTextAfterBackslash("Red spruce / balsam fir/tamarack");    
   alert(formattedString);  
 };  
 function capitalizedTextAfterBackslash(str){  
    var temp= str.split("\/");       
    for(var i=0; i<temp.length; i++) {  
     temp[i] = temp[i].trim();  
     temp[i] = temp[i].substr(0,1).toUpperCase() + temp[i].substr(1,temp[i].length-1);  
    }  
    return temp.join(' / ');   
 }  

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]

Friday, May 29, 2015

[SOLVED] Vagrant & Virtualbox - The guest machine entered an invalid state while waiting for it to boot....

2 Comments
Last couple of days I was running a Virtualbox issue "The guest machine entered an invalid state while waiting for it to boot. Valid states are 'starting, running'. The machine is in the 'poweroff' state. Please verify everything is configured properly and try again."

I had not clue how to fixed that and I have tried several versions and several installation. Then, then installation of Virtualbox 4.3.12 is working fine so far. If you are running into similar issue get  rid of all new Virtualbox versions and try with version 4.3.12, VirtualBox-4.3.12-93733-Win.exe, that might helps you solve the problem.

This version can be downloaded from:
                                              http://dlc-cdn.sun.com/virtualbox/4.3.12/

Similarly, if you are using vagrant I recommend to use Vagrant 1.7.2. Please note that not all versions of vagrant and virtual box are compatible with each other.

Updated environment for Vagrant and Virtual box in Windows 7 -
http://www.gisremotesensing.com/2016/09/solution-vagrant-stopped-working-open.html

Update
Working version as of 1/27/2017:
OS: Windows 7 Enterprise
Vagrant 1.9.1
Oracle VM Virtualbox - Version 5.1.14 r112924 (Qt5.6.2)

Friday, May 15, 2015

Tiler tools, an alternative scripts to Gdal2tiles.py for creating raster tiles from digital maps

Be The First To Comment
Other day I was working to generate the Google Map based raster tiles using Gdal2tiles for a large raster file, 30GB in size. Gdal2tiels complains about the following error, which I had no clue.

Then fiddling with others tilers available I played with the Tilers-tools, python Scripts for raster tile sets from digital maps with GDAL dependency. After spending few days hit and trial, finally I am able to generate raster tiles compatible with Google Maps. Here I am sharing the steps that I follow to produce tiles using the Tiler tool. Hope it will help some of the OSGeo users. I have divided tile generation steps into two groups, dependency installation and data preparation with a presumption that you are already familiar with GDAL.

A] DEPENDENCY INSTALLATION

STEP 1. Install Python geospatial packages

Install the dependencies as described-

For my project, I used 32 bit installers and Python 2.7. Strictly follow the python Geospatial package dependency installation orders and do not mix the 64 bit and 32 bit dependencies

STEP 2. Install the Tiler tools

Download and unzip the Tiler tool from: http://sourceforge.net/p/tilers-tools/wiki/WinInstall/

STEP 3. Set Python and Gdal path in Tiler’s bat file

Open : tilers-tools.bat from unzipped Tiler tool
         set PYTHON=C:\Python27 ( As you assigned the path in Step 1)
         set GDAL=C:\Program Files (x86)\GDAL ( As you assigned the path in Step 1)

STEP 4. Environmental variable setting on your machine

Set GDAL_DATA & path in your environmental variable setting.

                   Variable          Value

       GDAL_DATA = C:\Program Files (x86)\GDAL\gdal-data

        path = C:\Program Files (x86)\GDAL

Tuesday, May 12, 2015

Easy 5 steps to get thumbnails out of Pdf using Python

Be The First To Comment
1) Install Ghost script before python dependencies installation from: http://www.a-pdf.com/convert-to-pdf/gs.exe

2) Make yourself familier with Wand, a ctypes-based simple ImageMagick binding for Python.

3) Install Wand - pip install wand

4) Use the following script..
 #Install Ghost script before python package's installation   
 #from: http://www.a-pdf.com/convert-to-pdf/gs.exe  

 from wand.image import Image  
 from wand.display import display  
 fileDirectory = "D:/files/"  
 inFileName="myInputfile.pdf"  
 outFileName="myOutputfile.png"  
 imageFromPdf = Image(filename=fileDirectory+inFileName)  
 pages = len(imageFromPdf.sequence)  
 print(pages)  
 image = Image(  
   width=imageFromPdf.width,  
   height=imageFromPdf.height * pages  
 )  
 for i in range(pages):  
   image.composite(  
     imageFromPdf.sequence[i],  
     top=imageFromPdf.height * i,  
     left=0  
   )  
 image.format="png"  
 image.save(filename=fileDirectory+outFileName)  
 display(image)  



5) Let me know if you have any trouble.

Wednesday, April 22, 2015

Plan for Future Landsat Program: NASA, USGS Begin Work on Landsat 9 to Continue Land Imaging Legacy

Be The First To Comment
NASA and the U.S. Geological Survey (USGS) have started work on Landsat 9, planned to launch in 2023, which will extend the Earth-observing program’s record of land images to half a century. The year 2023 seems like a long way off, however.  
The Landsat program has provided accurate measurements of Earth’s land cover since 1972. With data from Landsat satellites, ecologists have tracked deforestation in South America, water managers have monitored irrigation of farmland in the American West, and researchers have watched the growth of cities worldwide. With the help of the program’s open archive, firefighters have assessed the severity of wildfires and scientists have mapped the retreat of mountain glaciers.
The President’s fiscal year 2016 budget calls for initiation of a Landsat 9 spacecraft as an upgraded rebuild of Landsat 8, as well as development of a low-cost thermal infrared (TIR) free-flying satellite for launch in 2019 to reduce the risk of a data gap in this important measurement. The TIR free flyer will ensure data continuity by flying in formation with Landsat 8. The budget also calls for the exploration of technology and systems innovations to provide more cost effective and advanced capabilities in future land-imaging missions beyond Landsat 9, such as finding ways to miniaturize instruments to be launched on smaller, less expensive satellites.
“Moving out on Landsat 9 is a high priority for NASA and USGS as part of a sustainable land imaging program that will serve the nation into the future as the current Landsat program has done for decades,” said John Grunsfeld, associate administrator for science at NASA Headquarters, Washington. “Continuing the critical observations made by the Landsat satellites is important now and their value will only grow in the future, given the long term environmental changes we are seeing on planet Earth.”
Because an important part of the land imaging program is to provide consistent long-term observations, this mission will largely replicate its predecessor Landsat 8. The mission will carry two instruments, one that captures views of the planet in visible, near infrared and shortwave-infrared light, and another that measures the thermal infrared radiation, or heat, of Earth’s surfaces. These instruments have sensors with moderate resolution and the ability to detect more variation in intensity than the first seven satellites in the Landsat program. Source
 

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

About Me