## Haversine Formula – Calculate geographic distance on earth

Haversine Formula – Calculate geographic distance on earth. If you have two different latitude – longitude values of two different point on earth, then with the help of Haversine Formula, you can easily compute the great-circle distance (The shortest distance between two points on the surface of a Sphere). The term Haversine was coined by Prof. James Inman in 1835. Haversine is very popular and frequently used formula when developing a GIS (Geographic Information System) application or analyzing path and fields.

## Haversine formula:

Central angle Haversine can be computed, between two points with r as radius of earth, d as the distance between two points, $\phi_1, \phi_2$ is latitude of two points and $\lambda_1, \lambda_2$ is longitude of two points respectively, as:

$\operatorname{haversin}\left(\frac{d}{r}\right) = \operatorname{haversin}(\phi_2 - \phi_1) + \cos(\phi_1) \cos(\phi_2)\operatorname{haversin}(\lambda_2-\lambda_1)$

### Law of Haversine:

To derive law of Haversine one needs to start the calculation with spherical law of cosine i.e cos a = cos b * cos c + sin b * sin c * cos A

One can derive Haversine formula to calculate distance between two as:

a = sin²(ΔlatDifference/2) + cos(lat1).cos(lt2).sin²(ΔlonDifference/2)
c = 2.atan2(√a, √(1−a))
d = R.c

where,

ΔlatDifference = lat1 – lat2 (difference of latitude)

ΔlonDifference = lon1 – lon2 (difference of longitude)

R is radius of earth i.e 6371 KM or 3961 miles

and d is the distance computed between two points.

### Here is the example result delivered by Haversine Formula:

Lets take one of latitude-longitude for calculation distance,
NEBRASKA, USA (Latitude : 41.507483, longitude : -99.436554) and
KANSAS, USA (Latitude : 38.504048, Longitude : -98.315949)

Do compute the distance with the above written formula. Your answer would be 347.3 Km(kilo-meter). The snapshot demonstrate the same result with map below.

If you are getting problem in understanding Haversine formula or getting error in the result do comment below. Also if you have more relevant information about the same, do share with us by writing below.

## Measure Straight line distance in Google Map

Measure Straight line distance in Google Map between two points. Straight line distance can be calculated with Haversine distance formula or Great circle distance formula. Google Map, a web mapping service application and technology, which provides and enrich a common user experience for free, like, Route planner for traveling by foot, car or public transportation with estimated travel time, Congestion description on current time or with prediction time, measure distance from one place to other either straight or route wise, see near by location and many more. You  can easily calculate straight line distance measurement, by just following simple steps.

## Measure Straight line distance in Google Map:

Note: Google provides two different version of map as, Classic Google Map (now with new Google Map Lite mode version) and a newly customized Google map. For both version, different steps are to followed to calculate distance. Below are the methods for both.

### New Google Map: Measure Straight line distance:

2.) Right click, from your starting point on Map, and select Measure Distance options.
3.) Click on destination point to which you want to measure distance. Done.

4.) Under the search box, see the calculated distance, as shown below in the figure.

How to switch between Google classic map and Google new map. Now switch to Lite Mode Google Map version.

### Classic Google Map: Measure Straight line distance:

2.) Click on Map lab link, appearing just left bottom panel.
3.) Enable “Distance Measurement tool”, and save changes.

4.) Click on ruler icon which appear at the lower left hand corner of map.
5.) Click on your start point and the end point, this will give your straight line measurement, shown in the left panel as shown.

Google map provides many feature, you can explore many other features as:

Hope this article helped you, to measure straight line distance, between two points. Do comment, below with your experience to calculate distance on Google Map.

Create save digitize and download kml or kmz from Google Earth. Google earth can be named a virtual globe or map of earth, which provide high resolution view of any area in recent years or any period of time from last decades. Always its not possible to go for field survey and prepare the layers like roads, places, river, water-body , settlements etc for any GIS application as it need resources and manual work which increases cost and project duration. Why do not one use a efficient way for the creation of layers like digitize kmz from the Google earth and convert it to shape-file or use directly. You can also see for how to save, create and export kml file from Google map. To digitize and save kmz from Google earth following steps need to be followed.

1) Start with running the application of Google earth on desktop or laptop, wait till the globe appears in the Google earth application window.

2) Add a folder to the My places contained by Places window of Google earth as shown in fig below.

3) Give name which you want to give to kmz in the tab opened clicking on the My place>add>folder button.

4) To plot a kmz of line type click on the Add Path button on the toolbar placed on the top of the window.

5) Start digitizing with the left click of the mouse and scrolling the window up, down, left and right by pressing the scroll wheel and zoom in and zoom out by rotating the scroll wheel inward and outward. To undo plotted points adjoining line press right click.

6) Save every line feature in the same folder named for kmz. Name of the feature can be edited by right click on the feature in the place window and going to properties of the feature.

7) Now after digitizing all feature save the kmz to the desired destination by right clicking on the folder in the My places.

8) Lastly the question may arise how to digitize kmz with polygon and point feature. For polygon feature click on Add Polygon on the tool bar and for point feature click on Add Place marks on the toolbar.

Note: Google provides Google Earth and this kind of service for free. But i suppose, if you are going to extract and create KML file with your program in bulk, then Google may notify you for the same.

You may also look on some other tutorial:

Thus Kmz is digitized and saved from Google earth. One may convert the kmz to shp in any GIS software like ArcGIS, QGIS, Global Mapper. Do comment below if you are getting any issue in performing above steps. Also do let us know in what way and in which application you are using KML file for performing GIS operation, by putting the information in the below provided space.

## Upload Excel latitude longitude in QGIS as Spatial Layer

Upload Excel latitude longitude in QGIS as Spatial Layer and save as Shapefile.  When you have collection of point data i.e latitude and longitude, stored in Excel file in different column, then you can easily view and Save it as Vector layer file in QGIS(Quantum GIS). Well after uploading Excel latitude longitude values as spatial layer,  you are only one step back, to convert the Excel data in Shapefile or KML or any vector file.

Before starting the exercise, you need to have a data excel file, which should be convert to Comma Delimited .csv file(Depends upon your choice, Comma delimited is common). To convert Excel file in .csv file, open the file and select save as type “CSV (Comma delimited) (*.csv)”. Name the file and save it.

• Note: If you are using old version of QGIS then, do download and install plugin “Add delimited text layer”.  To install a plugin,
• Go to Plugins -> Manage and install Plugins, search for “Add delimited text layer“, and install it.

## Steps to Upload Excel latitude longitude in QGIS as Spatial Layer

1.) Open up QGIS and click on layer, from menu tab and select Add delimited text layer.

2.) Browse the already created .csv excel file, which has latitude and longitude coordinates.

3.) By default, if your column is named as latitude and longitude, then, X will be mapped to longitude and Y will be mapped to latitude. Select OK after mapping X and Y.

4.) Select the desired coordinate reference system and press OK, the file get uploaded as Spatial layer in QGIS.

Well if you want to convert this uploaded Spatial layer in Shapefile or KML or any other vector file, select on layer, and click on save as. In the open window, select the desired format in which you want to save the file. Done. I suppose this tutorial would be helpful to you. If you are facing any problem, then do comment below.

Note: Google provides Google map and this kind of service for free. But i suppose, if you are going to extract and create KML file with your program in bulk, then Google may notify you for the same.

1.) Open Google map and sign in with all in one Google account.

2.) Click the setting button which appears at the bottom right corner of map as shown below (New Google map), and select My places. Or if you are using old map theme, then choose my places from top right corner.

• Update: If you are not getting my places option from here, then you click on left side Menu icon (three lines) and select your places and tap on Maps.

Once you clicked your places select the Maps.

3.) Now click on Create Map (in the last with blue font) which will open new link in new tab and select Create Map again.

4.) Perform and create a map, with the help of tool bars as shown below, Which has following options i.e

• Undo
• Redo
• Select item
• Draw a line
• Measure distance and Area.

5.)Name your map, by clicking on untitled map. You can now Add layers too, i.e for Adding Markers, which will be treated as point feature, make different layer while for Adding direction or line
you can have different layer.

• Note: You cannot have more than 3 layers for the same map project for Free. You need to go for Google map pro.

Here is the look, i had created 3 layers, i.e 1st one is Point layer, 2nd is Direction layer and 3rd is Line layer, as shown above.

6.) Once you are done with creating map, click the folder icon, shown just below your title of map project and Select Export as KML. Now you can export the entire map or either of the layer by selecting the options. Done.

You can now share your map you created map and can also embed it in your website. What are your plannings with the newly created KML file? Do you want to convert kml file to shapefile. Do comment below, how you use KML file so that me as well as our visitors will come to know about new technology and uses. Your valuable suggestion and questions are always welcomed by commenting below in the section provided.

## Here are the steps to upload or import KML file on Google map

2.) Move to My Places, a button on left upper side of Google map, and then select the Create with classic My Maps as shown below.

3.) Select import option, and then browse the KML file you want to upload on Google map.

4.) Done, edit the title and description. You can make the map public or private. Save the map.

• Note: You can upload KML file of Maximum size of 3MB on Google Map, as per Google instructions. While i found some lose of data while uploading KML file of greater than 2MB. Alternative to Google map is Google earth for the same.

The map saved, can be again viewed and downloaded by going to “My Places -> click on the title of map -> then the KML” option appearing just below the title of your map. You can also find the tutorial to convert KML to Shapefile and Shapefile to KML, with the help of QGIS an open source GIS tool. Want to know more technically on the KML and shapefile, i will provide you soon, related tools and coding for the same with explanation.

## Geo-Referencing raster image in QGIS w.r.t. vector file

Geo-Referencing raster image in QGIS with respect to vector file. Geo referencing is the process used to provide geographical information to the raster images like cadastral maps, physical maps and satellite imagery with the help of projection or coordinate system. As an ordinary raster image formed by the number of pixel which has no particular size,  Geo-referencing gives a particular coordinate to a pixel with respect to the ground point, it represents. Thus every individual pixel get its coordinate and size.

Look for other QGIS tutorial.

There are many GIS tools which perform Geo-referencing like ArcGIS, PCI Geomatica, Erdas Imagine, QGIS etc. Here Geo-referencing is shown in QGIS:

## Geo-Referencing raster image in QGIS with respect to vector file

Once the vector layer is loaded it can be given symbology by right click on the layer in the layers window. For geo-referencing the click on the georefrencer tab present at bottom of the QGIS environment window as shown below.

This will open a new window named Georeferencer . In this window open the raster image to be referenced by click on the tab open raster layer present on the top left corner.

When raster is open in the georefrencer window to add control points according to which raster will be georefrenced click on the add point button on the tool bar. Control points are the coordinate points of the ground or the projected coordinates.

These control points may be enter manually or from the map canvas as here reference is vector layer which is present on the map canvas. click on from map canvas on Enter map coordinates window.

This will open the map canvas or main QGIS window , select the point of reference on the vector layer.

Selection of point on vector layer will fill in the XY coordinates on the Enter map coordinates window. In this way first control point is marked.

Following same procedure select more and more points with minimum residual error which is generated by the tool and shown in the GCP table window.

Residual error is the difference between the actual coordinate of the control points and the geographic coordinate created by control points. The residuals represent the level of accuracy of the georefrenced images.

Check more :

Georeference on Map image with Geo Coordinates Control

Change projection of a georeference

These georefrenced images can be placed in the layers of any Geographic information system and can be used to locate points on the ground. Feel free to comment below, if you are having any problem to Geo-Referencing raster image  or if you want to discuss for the same topic.

## Connect QGIS to oracle spatial – Quantum GIS

How to connect QGIS to oracle spatial. QGIS can now connects to oracle to view spatial data and process it, great news for an open source software believers. As a newbie to QGIS user, i can just give a way, that i connected to it.

## How to connect QGIS to oracle spatial :

1.) Firstly you should have downloaded QGIS with GDAL/OGR required oracle library for bridging oracle connectivity and must have installed oracle  on your machine. If oracle library is not installed, see the following post : Install QGIS for oracle connection via OSGeo4w.

2.) After starting the QGIS application,  select Add Vector Layer as shown below:

3.) A new window will pop up on clicking the above, now select Database Radio button as appeared in Source. Now in Database Type drop down box, select Oracle Spatial. If you have properly installed QGIS with the requirement stated above Oracle spatial would be present.

4.) In the same Add Vector Layer window, select new button under connection label. This will open up a simple form with following Connection information to be filled, i.e, Type, Name, Host, Database, Port, Username and Password.

Here is the way to fill up the information :

a.) Type : In type select oracle spatial from drop down  box.

Type : Oracle Spatial

b.) Name : Type in any desired name you wish to give to connection

c.) Host : For finding your host name, make a query in your oracle sql plus application as written below:

SELECT UTL_INADDR.GET_HOST_ADDRESS FROM DUAL;

This will return the 32 bit address as shown below in figure:

d.) Database : Write database name, i.e the name you have given while installing oracle software.

e.) Port : Enter port number i.e 1521

Now select Test Connection button. This will pop up another window which gives you an information of your successful connection, as shown below.

Note the string url connection to connect QGIS to oracle spatial and click OK.

5.)  Again in the vector data layer window, select the connection that you made named as Demo and click on Open button.

6.) Now select the coordinate system for your database, which will be prompted after proceeding from step 5.

7.) If all steps are successfully done, you can see your spatial table, with your vector data spatial view as shown below:

Feel free to comment below, if you are having any problem to connect Oracle Spatial to QGIS Quantum GIS (Geographic information System) or if you want to discuss for the same topic. You can also see QGIS tutorial further. And yes, don’t forget to subscribe and follow on twitter for getting updates related to GIS post.

Download and Install quantum GIS – QGIS with oracle connectivity. Quantum GIS is an open source cross platform software for developing GIS (Geographic information System) solutions. QGIS connects to large set of spatial database and supports many data file formats, which enable us to visualize data, analyze data, edit data and generate a final map. QGIS is a best alternative to ESRI ARCGIS Desktop and is available for free under GNU General Public License. You can download and install Quantum GIS from either of the two way, i.e by standalone installer software or you can install it with OSGeo4w installer. OSGeo stands for open source geospatial foundation which include many open source projects, geospatial libraries, desktop application and web mapping.

While QGIS can be installed by one click with QGIS standalone installer, but it is better to install QGIS with OSGeo4w software as it helps you to install  many libraries and packages with QGIS. As this post topic is  concentrating for QGIS with oracle connectivity, so, for that reason we need to install GDAL/ORG library with QGIS , and it would be easy for you to install with support of OSGeo4w installer.

You might be interested in looking at QGIS tutorial.

If you have already done with this, you can see post to connect qgis with oracle :  QGIS connect with oracle.

a.)Run the installer and select “advanced Install” and select “Next”.

b.)Choose Install from internet when choose download source appears, as shown below.

c.)Select root directory, then next and select package directory and select next. Choose your internet connection. Default installation directory will be, C:\OSGeo4W. If you want to change the directory you can choose and select the same, as shown below.

2.) Select package to install will be prompted on the same window, Wait, don’t select next. You need to select the desire packages from the following open source utilities, enlisted below:

a.) Command line utilities: Dont need to select any utitlies from this for our above aim.

b.) Desktop utilities: Here, select the following libraries:

i.)  grass : Geographic Resource Analysis Support System

ii.) qgis : Quantum GIS (desktop)

iii.) qgis-dev : Quantum GIS rightly build of the master

c.)Libs (Library): By selecting above desktop utitlies, some libraries which are connected with above desktop utilites will get selected by default. Let it be selected and dont make any change in that. For getting oracle connection, some of libraries you need to select by clicking and making cross across that. This libraries are as follows:

i.) gdal : The GDAL/OGR library and command line tools

ii.) gdal-ffegdb : OGR fileGDB driver

iii.) gdal-oracle : OGR OCI and GDAL GeoRaster Plugins for Oracle

iv.) gdal-oracle 10g: Oracle 10g Plugin for GDAL(OGR)

v.) gdal 16-oracle : OGR OCI and GDAL Geo Raster Plugins for Oracle

d.)Web and Web application.

2.) After selecting all libraries, click on next. This step will connect you to internet and install all the library and utilities that you have selected. This may take some time to download  and install.

3.) All done. Now Open Quantum GIS and select add vector layer. Now select database in vector layer window and see if oracle spatial is on the list or not.

If every thing is perfect, You can now move this post for connecting qgis with oracle:  How to connect to Qunatum GIS with oracle.

Check  : Create Web Maps using QGIS2WEB

If you are having any problem to Download and Install quantum GIS – QGIS with oracle connectivity, comment on below. As i am also a newbie to QGIS, we will discuss and make out some proper solution.

## Merge more than two Shapefile in QGIS

Merge more than two Shapefile in QGIS. Do you want to merge two or more than two Shapefile? Do all the Shapefile are of same shape type i.e the Shapefile which can be merged with each other should have an identical shape, i.e either  “Point”, “Line” or “Polygon”? Do Shapefile all 3 files i.e .shx, .shp and .dbf are available? Then let us move to  an Open source Geographic information System Software. If not installed in your system, one of the way to install QGIS, with OSGeo4W provides or either you can install QGIS with standalone software. Let us move to Merge more than two Shapefile:

You may also find how to merge two or more than two features in shapefile.  Also you may read more tutorials in QGIS.

## Merge more than two Shapefile in QGIS

1.) Take and copy all Shapefiles to a common folder which you want to merge.

2.) Open up QGIS desktop and select the following from the menu :

• Vector -> Data Management tools -> merge shapefile to one, which will open up new window “Merge Shapefiles”, as shown below.

3.) Now select the browse input directory to the folder you created which include all Shapefile that you need to copy. Also browse the Output directory for getting the new merged Shapefile, and name the output file, as shown below:

4.) Press Ok. It will process your all shapefile and merge it to one. Finished.

• Note: New .dbf file will contain sum of column of two shapfefile minus common column.

Here you can see the output of two merged Shapefile of Road and Rail Route of India.