Upload or Import KML file on Google map

Upload or import KML file on Google map. KML or Keyhole Markup Language is file which models and stores geographic features for display in Google Earth or Google maps. You can upload and view the KML file you already created on Google Map, to verify Whether the overlapped feature of KML uploaded has proper valid geometry or not in respect to the Google Map Feature. Before uploading the KML on Google Map, you need to have a Google account. The file uploaded will be saved to “My Places“, you don’t need to upload it twice when require. If you are not having an already built KML file, you can look at How to create KML file on Google map or How to create KML file on Google earth.

You can also try MAPOG Map Analysis Product to upload or import the KML file Online and View on map for free. Along with that you can further process the GIS Data with different operation and finally create a brief Analysis report.

Upload or Import KML file on Google map

Upload or import KML file on Google map
Upload or import KML file on Google map

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

1.) Open Google map, and sign in for all in one Google account.
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.

Upload or import KML file on Google map
Upload or import KML file on Google map

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

Upload KML file on Google map
Upload KML file on Google map

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

Upload KML file on Google map
Upload KML file on Google 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

In QGIS first start with loading the vector file in QGIS environment by click on add vector layer.

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

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.

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

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.

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

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.

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

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.

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

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

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

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.

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

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.

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

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:

Connect QGIS to oracle spatial
Connect QGIS to oracle spatial

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.

Connect QGIS to oracle spatial
Connect QGIS to oracle spatial

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

Connect QGIS to oracle spatial
Connect QGIS to 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:

Connect QGIS to oracle spatial
Connect QGIS to oracle spatial

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

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

f.) Username : Enter username

g.) Password : Enter corresponding password of username

Connect QGIS to oracle spatial
Connect QGIS to oracle spatial

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

Connect QGIS to oracle spatial
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.

Connect QGIS to oracle spatial
Connect QGIS to oracle spatial

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

Connect QGIS to oracle spatial

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

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.

Download and Install quantum GIS – QGIS with oracle connectivity:

1.) Download osgeo4w installer, from the link provided http://trac.osgeo.org/osgeo4w/.

 

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

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

Download and Install quantum GIS - QGIS with oracle connectivity
Download and Install quantum GIS – QGIS with oracle connectivity

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.

Download and Install quantum GIS - QGIS with oracle connectivity
Download and Install quantum GIS – QGIS with oracle connectivity

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:

Download and Install quantum GIS - QGIS with oracle connectivity
Download and Install quantum GIS – QGIS with oracle connectivity

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

Download and Install quantum GIS - QGIS with oracle connectivity
Download and Install quantum GIS – QGIS with oracle connectivity

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

Download and Install quantum GIS - QGIS with oracle connectivity
Download and Install quantum GIS – QGIS with oracle connectivity

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.

Download and Install quantum GIS - QGIS with oracle connectivity
Download and Install quantum GIS – QGIS with oracle connectivity

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.

Download and Install quantum GIS - QGIS with oracle connectivity

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 QGIS (Quantum GIS), 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.
Merge more than two Shapefile in QGIS
Merge more than two Shapefile in QGIS

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:

Merge more than two Shapefile in QGIS
Merge more than two Shapefile in QGIS

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.

1.) Road Shapefile of india

Merge more than two Shapefile in QGIS
India Road – Merge more than two Shapefile in QGIS

2.) Rail Route Shapefile

India Rail - Merge more than two Shapefile in QGIS
India Rail – Merge more than two Shapefile in QGIS

3.) Final Output : Merged Shapefile :

Merge more than two Shapefile in QGIS
Merge more than two Shapefile in QGIS

Hope this helps you to merge two or more shapefile with the help of QGIS tool. You can also find QGIS operation to convert Shapefile to GeoJSONconvert kml to Shapefile and Shapefile to KML. If you find any problem on implementing the above steps do comment below. Your suggestions are always welcome as comment.

Pan-sharpening images using ArcGIS

Pan-sharpening images using ArcGIS. Pansharpening is the process which makes use of panchromatic image and some bands of multispectral image to result in a high resolution image. Pansharpening stands for panchromatic sharpening. Here sharpening basic refers to increase the spatial resolution of multisprectral image or color image. This technique of increasing resolution has been used by various organisations that provide satellite imagery of high resolution like Google images etc.

A multi spectral image is captured with high spectral resolution as it is displayed in different colors while the panachromatic image is captured with high spatial resolution and provides a cluster of red, green and blue pixels resulting in a gray scale image.Now the question is how we get a pan-sharpened image? The possible answer by an ArcGIS user can be it’s just a tool to run. But is it that easy? No. Both the images has to be pre-processed before applying this tool which comes out to be a tough process if you have  a number of tiles for your area of interest.

Pan-sharpening images using ArcGIS

  • First of all start with the multispectral image let’s say a cartosat image with a resolution of 1 arc sec. Start with stacking of different bands(either all even or all odd number) in Erdas imagine. Perform Geo-referencing of each tile making one tile static.
  • Then mosaicing of tiles in ArcGIS using Mosaic tool of data management tool set. The panchromatic image will be a single band image say panchromatic band of lansat image with 15 m resolution so it does not need to be stacked. So just mosaic all the tiles of panchromatic image. Geo-reference both multispectral and panchromatic image accordingly so that they both are same spatial location without any spatial difference.
  • Now apply tool create pan-sharpened raster data-set of data management tool-set.

Thus a multispectral image with high spatial resolution is obtained. As panchromatic image possess high spatial information and multispectral image possess good color information. Fusion of the two brings out a colored image of high resolution which can be used as a product for any client who want an detailed view of his area of interest.

c++ program to read shapefile header

c++ program to read shapefile header. Shapefile can be read if you know the format of Shapefile files i.e of .shp, .shx, and .dbf file. ESRI provided technical description of the Shapefile files which describes very clearly about the format of storage of data in all three formats i.e .shp, .shx and .dbf. You can also interpret and take the advantage to make simple GIS tool which can read and edit Shapefile properly. Here is the link of the Shapefile technical descrption :
ESRI Technical Discription. This program reads only Shapefile .shp header, which includes file code, length, version, bounding box coordinates and the type of shape Shapefile you loaded. You can also find simple program that just reads about bounding box of that shapefile. The code is explained with the comments provided in all function that you found.

c++ program to read shapefile header:

#include<iostream>
#include<stdio.h>
#include<conio.h>

using namespace std;

class ByteConverter
{
    public:
        //Convert 32 bits which is stored in BigEndian format to integer. This is performed with the help of bit operation i.e left shifting and operating or.
    static int32_t bigEndianIntRead(char *fileBuf, int startIndex)
    {
        return (((fileBuf[startIndex + 0] & 0xff) << 24) | ((fileBuf[ + 1] & 0xff) << 16)| ((fileBuf[startIndex + 2] & 0xff) << 8) | ((fileBuf[startIndex + 3] & 0xff)));
    }
    //Convert 32 bits which is stored in BigEndian format to integer. This is performed with the help of bit operation i.e left shifting and operating or.
    static int32_t littleEndianIntRead(char *fileBuf, int startIndex)
    {
        return (((fileBuf[startIndex + 3] & 0xff) << 24) | ((fileBuf[startIndex + 2] & 0xff) << 16) | ((fileBuf[startIndex + 1] & 0xff) << 8) | ((fileBuf[startIndex + 0] & 0xff)));
    }
    //Convert 64 bits or 8 Byte which is stored in BigEndian format to integer. This is performed with the help of bit operation i.e left shifting and operating or.
    static double littleEndianDoubleRead(char *fileBuf,int startIndex)
    {
        double convert;
        char *add;
        int j;
        add = new char();
        j=-1;
        for(int i=startIndex; i<startIndex+8; i++)
        {
            j++;
            add[j] = fileBuf[i];
        }
        convert = *reinterpret_cast<double * const>(add);
        return convert;
    }
};

//Class HeaderShapefile have all funtion implemented to desribe every field of shapefile header file.
class HeaderShapefile
{
    public:
        //filecode describes the code of .shp file. As described in Shapefile Technical description of ESRI, filecode
        //value is always constant and should have 9994 value.
    static int32_t fileCode(char*fileBuf, int startIndex)
    {
        return ByteConverter::bigEndianIntRead(fileBuf,startIndex);
    }

        //File length contains Length of the file field
    static int32_t fileLength(char*fileBuf, int startIndex)
    {
       return ByteConverter::bigEndianIntRead(fileBuf,startIndex);
    }
        //Version function
    static int32_t version(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianIntRead(fileBuf,startIndex);
    }
        //Function shapeType describes the type of the shape. It returns an 32 bit integer
        //value. This integer is then matched with the cooresponding shape as described in ESRI shapefile pdf
    static int32_t shapeType(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianIntRead(fileBuf,startIndex);
    }

    //This remaning funtion of the class will calculate the bounding box coordinates of the shapefile.
    //Following values i.e x and y minimum and maximum values also with z and m minimum
    // and maximum values are obtained.


    static double dimensionXMin(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf,startIndex);
    }

    static double dimensionYmin(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }

    static double dimensionXmax(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }

    static double dimensionYmax(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }

    static double dimensionZmin(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }

    static double dimensionZmax(char*fileBuf, int startIndex)
    {
       return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }

    static double dimensionMmin(char*fileBuf, int startIndex)
    {
       return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }

    static double dimensionMmax(char*fileBuf, int startIndex)
    {
       return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }
};

class SizeOfFile
{
    public:
        //This function finds the size of file in Byte
    static long sizeOfFiles(FILE *file)
    {
            long l, e;
            l = ftell(file);
            fseek(file, 0, 2);
            e = ftell(file);
            fseek(file, l, 0);
            return e;
    }
};

int main()
{
    int32_t filecodes, fileLengths, shapeTypes, versions;
    double xmin, ymin, xmax, ymax, mmin, mmax, zmin, zmax;
    string shape;
    char *filePath = "map.shp";
	char*fileBuf;			// Pointer to our buffered data
	FILE *file = NULL;		// File pointer
	// Open the file in binary mode using the "rb" format string
	// This also checks if the file exists and/or can be opened for reading correctly
	if ((file = fopen(filePath, "rb")) == NULL)
		cout << "Could not open specified file" << endl;
	else
		cout << "File opened successfully" << endl;

	// Get the size of the file in bytes
	long fileSize = SizeOfFile::sizeOfFiles(file);

	// Allocate space in the buffer for the whole file
	fileBuf = new char[fileSize];

	// Read the file in to the buffer
	fread(fileBuf, fileSize, 1, file);

	// Now that we have the entire file buffered, we can take a look at some binary infomation

	cout<<"File size = " <<fileSize;
	cout<<"File size get = "<<fileBuf;

    filecodes = HeaderShapefile::fileCode(fileBuf,0);
    fileLengths = HeaderShapefile::fileLength(fileBuf,24);
    versions = HeaderShapefile::version(fileBuf,28);
    shapeTypes = HeaderShapefile::shapeType(fileBuf,32);
    xmin = HeaderShapefile::dimensionXMin(fileBuf,36);
    ymin = HeaderShapefile::dimensionYmin(fileBuf,44);
    xmax = HeaderShapefile::dimensionXmax(fileBuf,52);
    ymax = HeaderShapefile::dimensionYmax(fileBuf,60);
    zmin = HeaderShapefile::dimensionZmin(fileBuf,68);
    zmax = HeaderShapefile::dimensionZmax(fileBuf,76);
    mmin = HeaderShapefile::dimensionMmin(fileBuf,84);
    mmax = HeaderShapefile::dimensionMmax(fileBuf,92);

    /*****************HEADER SHAPEFILE DETAIL*********************/

    cout<<endl<<"/*****************HEADER SHAPEFILE DETAIL*********************/";

    cout<<endl<<"File code = "<<filecodes<<endl;
    cout<<"File Length = "<<fileLengths<<endl;
    cout<<"Version = "<<versions<<endl;

    //This shapefile shapetypes can be found in the technical discription.
    switch(shapeTypes)
    {
        case 0:
            shape = "Null Shape";
            break;
        case 1:
            shape = "Point";
            break;
        case 3:
            shape = "Poly Line";
            break;
        case 5:
            shape = "Polygon";
            break;
        case 8:
            shape = "MultiPoint";
            break;
        case 11:
            shape = "PointZ";
            break;
        case 13:
            shape = "PolyLineZ";
            break;
        case 15:
            shape = "PolygonZ";
            break;
        case 18:
            shape = "MultiPointZ";
            break;
        case 21:
            shape = "PointM";
            break;
        case 23:
            shape = "PolyLineM";
            break;
        case 25:
            shape = "PolygonM";
            break;
        case 28:
            shape = "MultiPointM";
            break;
        case 31:
            shape = "MultiPatch";
            break;
        default:
            shape = "Wrong match found";
            break;
    }
    cout<<"Shape Type = "<<shape<<endl;

    cout<<endl<<"************* Bounding Box **************"<<endl;
    cout<<"X minimum = "<<xmin<<endl;
    cout<<"Y minimum = "<<ymin<<endl;
    cout<<"X maximum = "<<xmax<<endl;
    cout<<"Y maximum = "<<ymax<<endl;
    cout<<"Z minimum = "<<zmin<<endl;
    cout<<"Z maximum = "<<zmax<<endl;
    cout<<"M minimum = "<<mmin<<endl;
    cout<<"M maximum = "<<mmax<<endl;

	cin.get();
	delete[]fileBuf;
        fclose(file);   // Almost forgot this
	return 0;
}

Output of c++ program to read shapefile header:

c++ program to read shapefile header
c++ program to read shapefile header

Get minimum Bounding box of shapefile c++ program

Get minimum Bounding box of shapefile c++ program. This program not only reads shapefile, but makes you aware to read other files, i.e files which have .dbf, .exe, .png etc format without having software. Before that you should know about bits, byte order, and conversion of bytes to other data types and most importantly the format of the files that you want to read.

A shapefile stores non topological geometry. ESRI shapfile mainly contains 3 files, i.e .shp, .shx and .dbf files. To get bounding box details of shapefile, we need to concern about .shp file format. You can find all the technical discription of shapefile, provided by esri in their website.

Shapefile .shp has 3 parts, i.e file header, record header and record contents. File header stores the bounding box of shapefile. You can also see c++ program to read shapefile header. Here is the program:

Get minimum Bounding box of shapefile c++ program

#include<iostream>
#include<stdio.h>
#include<conio.h>

using namespace std;

class ByteConverter
{
    public:
        //Convert 32 bits which is stored in BigEndian format to integer. This is performed with the help of bit operation i.e left shifting and operating or.
    static int32_t bigEndianIntRead(char *fileBuf, int startIndex)
    {
        return (((fileBuf[startIndex + 0] & 0xff) << 24) | ((fileBuf[ + 1] & 0xff) << 16)| ((fileBuf[startIndex + 2] & 0xff) << 8) | ((fileBuf[startIndex + 3] & 0xff)));
    }
    //Convert 32 bits which is stored in BigEndian format to integer. This is performed with the help of bit operation i.e left shifting and operating or.
    static int32_t littleEndianIntRead(char *fileBuf, int startIndex)
    {
        return (((fileBuf[startIndex + 3] & 0xff) << 24) | ((fileBuf[startIndex + 2] & 0xff) << 16) | ((fileBuf[startIndex + 1] & 0xff) << 8) | ((fileBuf[startIndex + 0] & 0xff)));
    }
    //Convert 64 bits or 8 Byte which is stored in BigEndian format to integer. This is performed with the help of bit operation i.e left shifting and operating or.
    static double littleEndianDoubleRead(char *fileBuf,int startIndex)
    {
        double convert;
        char *add;
        int j;
        add = new char();
        j=-1;
        for(int i=startIndex; i<startIndex+8; i++)
        {
            j++;
            add[j] = fileBuf[i];
        }
        convert = *reinterpret_cast<double * const>(add);
        return convert;
    }
};

//Class HeaderShapefile have all funtion implemented to desribe every field of shapefile header file.
class HeaderShapefile
{
    public:

    //This funtion of the class will calculate the bounding box coordinates of the shapefile.
    //Following values i.e x and y minimum and maximum values also with z and m minimum
    // and maximum values are obtained.


    static double dimensionXMin(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf,startIndex);
    }

    static double dimensionYmin(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }

    static double dimensionXmax(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }

    static double dimensionYmax(char*fileBuf, int startIndex)
    {
        return ByteConverter::littleEndianDoubleRead(fileBuf, startIndex);
    }
};

class SizeOfFile
{
    public:
        //This function finds the size of file in Byte
    static long sizeOfFiles(FILE *file)
    {
            long l, e;
            l = ftell(file);
            fseek(file, 0, 2);
            e = ftell(file);
            fseek(file, l, 0);
            return e;
    }
};

int main()
{
    int32_t filecodes, fileLengths, shapeTypes, versions;
    double xmin, ymin, xmax, ymax, mmin, mmax, zmin, zmax;
    string shape;
    char *filePath = "map.shp";
	char*fileBuf;			// Pointer to our buffered data
	FILE *file = NULL;		// File pointer
	// Open the file in binary mode using the "rb" format string
	// This also checks if the file exists and/or can be opened for reading correctly
	if ((file = fopen(filePath, "rb")) == NULL)
		cout << "Could not open specified file" << endl;
	else
		cout << "File opened successfully" << endl;

	// Get the size of the file in bytes
	long fileSize = SizeOfFile::sizeOfFiles(file);

	// Allocate space in the buffer for the whole file
	fileBuf = new char[fileSize];

	// Read the file in to the buffer
	fread(fileBuf, fileSize, 1, file);

	// Now that we have the entire file buffered, we can take a look at some binary infomation

	cout<<"File size = " <<fileSize;

    xmin = HeaderShapefile::dimensionXMin(fileBuf,36);
    ymin = HeaderShapefile::dimensionYmin(fileBuf,44);
    xmax = HeaderShapefile::dimensionXmax(fileBuf,52);
    ymax = HeaderShapefile::dimensionYmax(fileBuf,60);

    /*****************MINIMUM BOUNDING BOX OF SHAPEFILE DETAIL*********************/

    cout<<endl<<"\n/*****************MINIMUM BOUNDING BOX SHAPEFILE DETAIL*********************/\n\n";

    cout<<"X minimum = "<<xmin<<endl;
    cout<<"Y minimum = "<<ymin<<endl;
    cout<<"X maximum = "<<xmax<<endl;
    cout<<"Y maximum = "<<ymax<<endl;

	cin.get();
	delete[]fileBuf;
        fclose(file);   // Almost forgot this
	return 0;
}

Output of Get minimum Bounding box of shapefile c++ program

Get minimum Bounding box of shapefile c++ program
Get minimum Bounding box of shapefile c++ program

What is GIS | Geographic Information System

What is GIS | Geographic Information System? GIS is an Abbreviation of Geographical Information System or Geo-spatial Information Systems or Geologic Information Systems (also Geo-spatial database management). As the name suggest ‘GIS’ is related to geographical information. But before explaining what is GIS?, we should know about what Geographic information means? Geographic information is knowledge of where something is. It defines the spatial reference of the element or matter present on earth surface.

As it is said “a picture is worth a thousand words”, Maps plays a lead role in defining geographical information. We control map to guide someone to know the actual  route, exact destination, its distance, its elevation, its surroundings etc. Geographical information is needed to Government, Industries, Business markets, Tourism and services sector,  Education, Agriculture, Health, Disaster Management,  Transportation and also to a common people. It makes us easy to locate an area of industries, day care center, restaurant, mall, head quarter or any other specific place.  It solves everyday issues. What is the shortest route to get to work? How can i get to hotel? Where is the location of my new office? So, Geographical information is part of our lives. But how can we get geographic information and What is GIS?

Geographic Information System
Geographic Information System

What is GIS | Geographic Information System?

GIS is a tool to acquire geographic data and produce Geographic information. Generally Information about those features are stored in tabular formGIS can be defined as a “computer information system that can input, store, manipulate, analyze, and display geographically referenced (spatial) data to support decision making processes”.
GIS enables us to connect dynamic relations between spatial data (geo referenced) & relational data (attribute of features in tabular forms). It enable us to make models of reality, of the ground and to answer question such as what is where? Main component of Geographic information system are: Hardware, Software, Data and People.

You may also be interested in knowing GIS Uses and Application in different industries.

Geographic Information System
Geographic Information System
Some organizations defined GIS – Geographical Information System as :

A geographic information system (GIS) is a computer-based tool for mapping and analyzing things that exist and events that happen on earth. GIS technology integrates common database operations such as query and statistical analysis with the unique visualization and geographic analysis benefits offered by maps.” ~ ESRI

“GIS is an integrated system of computer hardware, software, and trained personnel linking topographic, demographic, utility, facility, image and other resource data that is geographically referenced.” ~ NASA 

Google Map can be considered as an Example of GIS tool. You can have a look over 35+ Google Tips and tricks.

The demand for GIS tools is continuously growing. One of such tool is QGIS(Quantum GIS), and is a cross platform, free open source desktop application. From a citizen to an organization, every body needs Geographic information. You can find here advantage of GIS and Why GIS. I hope that reading this post will make you to learn more about Geographic information System. I would appreciate your comment, if you like to share more ideas related to the same topic.

Convert Shapefile to kml by QGIS

Convert Shapefile to kml by QGIS. Shapefile is ESRI based Vector file, While KML or Keyhole Markup Language is file which models and stores geographic features for display in Google Earth or Google maps. Many times you may require to convert the required shapefile to KML file, so that you can deploy the same over Google Earth for some reason. QGIS (Quantum GIS) is an open source GIS (Geographic Information System) tool, which let you upload the Shapefile and convert the same to KML file. Similarly ogr2ogr is also an open source tool, which let you to convert between GIS data formats. Look over shp to kml convert using ogr2ogr tool which can be marked as an alternative to this article. You can also see to convert Kml to Shapefile and also Shapefile to GeoJSON in QGIS.

You can also try Online conversion instead of QGIS MAPOG Online converter tool

You can also go through other tutorial in QGIS.

Free SHP to KML conversion using GIS Converter Tool in one click.

Here are the steps to convert shapefile to kml:

Convert Shapefile to kml in QGIS

Convert Shapefile to kml by QGIS
Convert Shapefile to kml by QGIS

Convert Shapefile to kml in QGIS:

1.) Open up the installed QGIS.
2.) In the menu bar, select Layer and press Add Vector Layer. Now select the source type in the pop up window opened as File and browse the source Shapefile(Note:Your shapefile .shp, .dbf and .shx file should be in same folder). Press open.

Convert Shapefile to kml by QGIS
Convert Shapefile to kml by QGIS

Select the coordinate reference type system if coordinate reference window appears and press ok.

3.) Right click on the name of Shapefile layer Appearing in the Left upper side and select save as:
or
You can select layer from the menu, and click on save as. (Image below provide demonstrate both the options with the indicator displayed)

Convert Shapefile to kml by QGIS
Convert Shapefile to kml by QGIS

4.) In the Save vector layer as window, Select the format from the drop down box as Keyhole Markup Language(KML) and browse the folder in which you want to save the KML file . Name it and Press OK.

Convert Shapefile to kml by QGIS
Convert Shapefile to kml by QGIS

Your KML file will be Exported in the directed folder. You can Verify the generated KML file for its validity by uploading the generated KML file to QGIS or uploading KML file in Google map. You may soon find the tool and the coding for the same on this site.

You may check in converting Geojson to Topojson and Shapefile to TopoJSON file. Hope this may help you in converting Shapefile to KML file easily. If you still find problem in converting the file, do let me know by commenting below.

Introduction of QGIS 3.2.1