Thursday, February 26, 2015

How to Download and Install PostgreSQL to Windows

PostgreSQL is an Open source object-relational database management system (ORDBMS) which highly use to store and manage spatial data. This will work nicely with different operating systems such as BSD, Linux, Mac, Solaris and Windows

You can download PostgreSQl using following link,
http://www.postgresql.org/

Follow below steps to download, Install and  configure PostgreSQL  database,

Step 1,

Use above link to download PostgreSQL



Step 2,

Select your operating system to download required version 

Step 3,

Run PostgreSQL-9.3.2-1- windows.exe


Step 4,

Setup page of the PostgreSQL - Press "Next'


Step 5,


Assign Installation Directory 


Step 6,

Add a password to database which you required to connect database when running the PostgreSQL


Step 7,

Assign Port 5432, then Press "next"
  

Step 8

If you need to install Stack Builder also you can tick otherwise leave it,





Step 9,

Then run PostgreSQL - "pgAdmin III"


Step 10,

Connect PostgreSQL - then provide given password


Step 11,

Now you can work with your PostgreSQL database - Enjoy!








Tuesday, January 13, 2015

Modeling Erosion Using ILWIS

ILWIS is an open source GIS software freely available to download  http://www.ilwis.org/ .
Download ILWIS 3.3 Academic for this practical.


Modeling erosion from pyroclastic flow deposits on Mount Pinatubo


1.       The given data set is to study the phyroclstic erosion of the given area, and  by examine the given data set understand them. The main phyroclastic deposit eroded by the rain water in different rainy seasons. 
The Digital Terrain Models given for after the main rainy sessions of 1991, 1992, 1993 as DTM91, DTM92 and DTM93
Dtmpre – Digital terrain model before eruption
Dtmerp – Digital terrain model after eruption
Catchpre – Catchment before eruption

Catchere – catchment after the eruption     


 Calculate the catchment area changes after the volcanic eruption in square kilometers and fill the following table

Catchment type
Area before eruption
Area after eruption
Changes of area
Abacan



Pasig



Sacobia



Sapangbato



Taug





We have to calculate the Area before eruption and the Area after eruption and the calculate the different between them,

Open ILWIS - Right click on Catchpre - Statistics - Histogram



Step 2,

Histogram shows the details of the  Area before eruption, we required area in square Kilometers, therefore we have to add new colomn and calculate the area by using simple command in ILWIS.

We have to add new column to the attribute table,




Then we have to open the command line in ILWIS,




Then assign values to your new column by using following command (In this practical "Area_km2" is my new column name )

Area_km2 = Area/1 e 6


Just hit Enter,




Then do the same procedure for the "Catchere " data set also and calculate the difference with the Area before eruption.

After the main volcanic eruption the area filled with the phyroclastic material therefore Calculate the total volume increase after the main eruption 


Step 1,

Here we have to calculate the total volume increased,  for this step we have to use Dtmpre – Digital terrain model before eruption and Dtmerp – Digital terrain model after eruption and create new layer with the difference. for that use following command in ILWIS. (Here "Pfthick" is the name of my new layer)

Pfthick=iff(DTMERP - DTMPRE > 0, DTMERP - DTMPRE,0)


Hit Enter - Show - and press ok, 


Then Right click on the new layer and statistics -  Histogram 


we have to calculate the volume therefore we have to multiple Value by the Area, for that we have to add a new column and using command line we can assign the values to the new column,


Volume = Area*Value






After the first rain (1991) season the original situation has changed in to new situation due to the erosion


Step 1,

Total erosion map of the area 

We have to calculate the total erosion of the area, for that use following command,

TotalEro = iff(DTMERP - DTM91 >0, DTMERP - DTM91,0)




Step 2,

Erosion map of the phyroclastic deposit

 Here we have to calculate the total  phyroclastic deposit

TotPhyro=iff((TotalEro>0)AND(DTM91>DTMPRE),DTMERP-DTM91,0)





Step 3,

Erosion map of the other deposits in 1991

Here we have to calculate the other deposits of the catchment areas,

OtherDepo=iff((TotalEro>0)AND(DTM91<DTMPRE),DTMPRE-DTM91,0)



Step 4,

Sedimentation map of 1991

Sedimentation=iff(DTM91>DTMERP,DTM91-DTMERP,0)







Tuesday, September 30, 2014

How to write Python Scripts for ArcGIS

We can write python Scripts to the ArcGIS in-order to skip large number of complex steps in ArcGIS. Once we created script users just have to run the script and assign the inputs for the script. In ArcGIS we can create model builder and then created model builder can be export as a python script. Then we have to Edit the script in-order to modify and run as user requirement.  



Step 1,

In this exercise first we create model builder in ArcGIS and the export it as a python script.  Check my following blog for more details about model builder,

http://effective-gis.blogspot.com/2014/07/modelbuilder-in-arcgis.html


Create Personal GeoDataBase - Right Click - New ToolBox - Right Click - New Model



Drag Select Tool, Which required for selecting Main Roads from the Transport layer in this exercise. Add data as required. 



Add buffer tool, which will create buffer for the selected road type from the select tool.


Then add clip tool



Step 2,

Then we have to export model builder in to python script

Model - Export - To Python Script


Save script as a Python Script


Step 3,

Once you save your script you can open it with either python IDLE (command line) or Note pad, It is better to open with python IDLE.


you can open python IDLE manually by

All programs - ArcGIS - Python 2.7 - IDLE

This is the python script generated by the model builder



Step 4,

You can run the Script by Run - Run Module or by pressing F5


Once we run this script again it will generate error message (only if you have run the model builder earlier and having outputs ) saying particular output is already exists. Then we have to edit our script otherwise all the time before run this tool we have to delete the outputs. 



Step 5,

As you know import arcpy keyword is to import ArcGIS functions and also we need "sys" keyword,

for this script we need to assign out data in Geo-Database, for that we have to use "import = sys.argy[1]"



Then change the local variable path as follows,
"input+"\\WorkingData\\Transport (Here as input we assign out Geo-Database) 


Step 6,

when we run our script it gave us error message saying that data already exsists. Here we are going to remove those outputs in the Geo-Database (only if available)

if arcpy.Exists(trans_li_selected): arcpy.Delete_management(trans_li_selected,"")

here we have used Delete_management funtion in the python script. apply this for the required outputs. 



Step 7,

We can Add messages to be shown while script is running, for that we have to use following code,

arcpy.AddMessage ("Deleting exsisting files on Progress")

Withing brackets you type your message to be shown, You can Add any number of messages as you required to be shown when running your script..


Step 8,

Now you have complete your script, We have to add this script to ArcGIS, for that right click on your created ToolBox - Add - Script

This window will appear, Then you can give a name to youe script, Label for the script and Description, you do not required any stylesheet for this, the press 'Next'


The we have to add label for user interface, this appear when running this tool, therefore we have to add meaning full name, here we need input as a GeoDatabase, therefore I have assign "Input DataBase" you can add what ever you required,


Since we need input as a GeoDatabase we have to assign Data Type as "Workspace", Then press "Finish"


Then we have to add our script, brows to the script and press Open.




Step 9,

Once you complete adding script, your added script appear in your ToolBox. 



Step 10,

Now we have to run our script, for that just double click on the script, Then select your Goedatabase where your data available for this practical (data used to create bodybuilder), Press "Add", After you add Geodatabase run the script.

Step 11,

Once you run the script you can see the messages which you have added to the script is show in the each process, 


While you run this script you will get this error message "Building Polygon Does not exists", mean we do not have required data for clipping process, When you get this kind of errors inpython it will show you the error line even, so we can solve the problem easily, 


Once we go through our coding we can see that we are deleting the required shape file also from the beginning which only required for the clipping, so we have to remove that line from the script. then add that deleted shapefile to your database again manually. Therefore make sure not to delete data which required for the other process in the latter part of the process. once you edit your script make sure to save it. 


Step 12, 

Again run your script. Now its working properly, once it complete it generate completed message. you can check your output in the Geo-database.