Convert Geojson to MIF MapInfo file

In this article we will be discussing about convert GeoJSON to MIF Mapinfo using GDAL utility (Ogr2ogr). This conversion is useful with MapInfo mapping and geographic analysis softwares.

Convert Geojson to MIF MapInfo file

We must understand GeoJSON and MIF format in detail before conversion.

Convert Online GeoJSON to MIF Mapinfo

Specification of GeoJSON data- Convert Geojson to MIF

Geojson data is open standard format, contains simple geographical feature with non-spatial data. In type, it has feature collection. That contains name, CRS (coordinate reference system) and features. These features can be line, point, polygon, Multi-Line string and multi-polygon. Properties contains all attribute information.

Convert Geojson to MapInfo file

Specification of MIF data- Convert Geojson to MIF

Convert Geojson to MapInfo file

MIF (Map Info File) File format used by MapInfo mapping and geographic analysis software. This stores a map visualization in a format that can be recognized by third party applications. Also used as an exchange format between GIS applications. This sometimes accompanied by a .MID (MapInfo data) file that contains additional spatial data. MID files are GIS data files created by MapInfo, a spatial data analysis and visualization software, saves spatial data for a corresponding .mif (MapInfo Interchange Format) file. Also used for storing larger data sets not expressed in the MIF file.

MIF file show some general property when open with QGIS software, as like :

i.) Storage type of this layer
–> MapInfo File
ii.) Description of this provider
–> OGR data provider (compiled against GDAL/OGR library version 2.2.2, running against GDAL/OGR library version 2.2.2)
iii.) Source for this layer
–> /var/www/html/PHP_pgrouting/public/shpfolder222/newwhello.mif
iv.) Geometry type of the features in this layer
–> Line
v.) The number of features in this layer
–> 19148
vi.) Capabilities of this layer
–> Fast Access to Features at ID, Presimplify Geometries, Presimplify Geometries with Validity Check
vii.) In layer spatial reference system units
–> xMin,yMin 68.4982,7.92528 : xMax,yMax 97.3348,35.5013
viii.) Layer Spatial Reference System
–> +proj=longlat +datum=WGS84 +no_defs

Convert Geojson to MIF MapInfo file

  • Go to MapOG Tool
  • Tap on Switch To and click on Converter.
  • Now upload your data from system or drag & drop from system.
  • Once input is uploaded select the output format and if you want to change coordinate reference system then click on the third option. And in the last click on Convert File.
  • You converted file is published on the map directly.
  • Check video for steps of conversion for Geojson to MIF.

Convert GeoJSON to MIF using GDAL utility-

Gdal library should be available in system when converting data format from one to another. This utility can be installed in system by following the given commands.

Convert Geojson to MIF MapInfo file
Convert Geojson to MIF

The options available with ogr2ogr utility cab seen by typing ogr2ogr in command prompt.

Convert Geojson to MIF MapInfo file

The drivers or format supported by utility can be seen by typing the following command.

–> ogr2ogr –formats

Convert Geojson to MIF MapInfo file

Convert the Geojson data in MIF with given command.

–> ogr2ogr -f  ‘MapInfo File’ -a_srs EPSG:4326 MIF_output.mif geojson_input.geojson

The option -a_srs is used to assign coordinate system to generated output file.

Output in QGIS software- Convert Geojson to MIF

The generated output file can be open with QGIS open source software.

Convert Geojson to MapInfo file

You can also use conversions using gdal utility as netcdf to geotiff, Hdf to geotiff, shapefile to topojson and many more.

Please comment in the given comment box for any help and suggestions. We are always ready for your help.

You might be interested in Different ways to convert Shapefile to GeoJSON

Convert GeoJSON to KML

In this article we would be discussing about conversion of GeoJSON data to KML (Keyhole Markup Language). This conversion is required when you are using software such Google earth to see the data. KML works great with Google earth. There is simple step to Convert GeoJSON to KML using ogr2ogr utility from GDAL library. Before that we must go through specification of GeoJSON and KML.

Here is the way to Convert the GeoJSON to KML online

Specification of GeoJSON – Convert GeoJSON to KML

Geojson data is open standard format, contains simple geographical feature with non-spatial data. In type element it has feature collection. That contains name, CRS (coordinate reference system) and features. These features can be line, point, polygon, Multi-Line string and multi-polygon.

Convert GeoJSON to KML
Convert GeoJSON to KML

Specification of KML- Convert GeoJSON to KML

The KML (Keyhole Markup language) this data format contains information in tags. SimpleField contains attribute information with name and type. Style tag contains the style of file as color of lines, points and polygons. Geometry is stored as coordinates in file.

Convert GeoJSON to KML

Convert GeoJSON to KML using GDAL Utility-

The conversion requires Gdal utility. This utility can be installed in the system by following the given commands.

Convert GeoJSON to KML

By typing ogr2ogr in command prompt you can get the following result. This result shows the presence of ogr2ogr utility in system.

To know the version of installed GDAL library you can type,

–> gdalinfo –version

Convert GeoJSON to KML

Before executing the conversion command, you should check the drivers. The drivers can be checked by typing

–> ogr2ogr –formats

in your command prompt. Now check for the GeoJSON and KML driver.

Convert GeoJSON to KML

After checking the drivers you can execute the following command.

–> ogr2ogr -f ‘KML’ -a_srs EPSG:4326 Output_fileName.kml Input_FileName.geojson

Output of Convert GeoJSON to KML-

The generated output file can be open in editor to see the content.

Convert GeoJSON to KML

In the similar way you can also convert shape file to MIF, shapefile to sql and shape file to excel file.

You can also comment in given comment box for any query, help or suggestions.

Convert GeoJSON to Shapefile

In this article we are converting GeoJSON to Shapefile shp format. You might be thinking why would anyone convert GeoJSON in shapefile. Answer is very simple Shapefile is very popular data format with open specification for data interoperability among GIS (Geographical information system) softwares. Before moving towards conversion steps we must look for GeoJSON and Shape file in detail. There Specification is given below.

Here is the Online Converter Tool from GeoJSON To Shapefile

Specification of GeoJSON-

Geojson data is open standard format, contains simple geographical feature with non-spatial data. In type element it has feature collection. That contains name, CRS (coordinate reference system) and features. These features can be line, point, polygon, Multi-Line string and multi-polygon.

Convert GeoJSON to Shapefile
Convert GeoJSON to Shapefile

Specification of Shapefile-

Shapefile is very popular data format specially among open source GIS softwares. It has some mandatory files, which contains various information such as index of geometry, attribute data and projection information.

  1. shx- contains geometry index,
  2. shp- contains geometry,
  3. dbf- contains attribute data,
  4. prj- contains projection data.

Convert GeoJSON to Shapefile using MapOG Tool

Convert GeoJSON to Shapefile

Convert GeoJSON to Shapefile Shp Using Gdal Utility-

Conversion from geojson to shapefile requires GDAL library in your system. For downloading it you can follow given commands.

Convert GeoJSON to Shapefile

To check the availability of library can be check by typing ogr2ogr in command prompt. You can also check the version of GDAL library by typing gdalinfo –version.

Convert GeoJSON to Shapefile

To convert data from geojson to shapefile we must have format available in library. To check the formats available you can execute the following command,

–> ogr2ogr –formats

you will get the following list that contains the drivers list. Check for the GeoJSON and Shapefile driver.

Convert GeoJSON to Shapefile

Now you can execute the conversion command given below,

–>ogr2ogr -f ‘ESRI Shapefile’ -a_srs EPSG:4326 Output_fileName.shp Input_FileName.geojson

Here Command shows some options of ogr2ogr utility as -f, which shows output file format, -a_srs shows SRS (spatial reference system) assigned to output file. The Generated output file can be seen on QGIS software.

Converted Output GeoJSON to Shapefile In QGIS software-

Convert GeoJSON to Shapefile

In similar way you can also convert Shp to geojson, shp to KML or many more.

Feel free to contact for any help or suggestions by commenting in given comment box.

KML to GML – Convert Keyhole to Geography

Sometimes we need to convert KML to GML where the software supports GML language. But before converting Keyhole markup language to Geography markup language, you should know the basic structure of KML and GML. So that if the file is corrupted then before converting it you can correct it manually and process the same in any GIS converter software to work properly. If you already know structure of this files, then you can directly navigate to the main topic i.e kml to gml conversion of this page.

Here is the Online Converter Tool from KML To GML 

Know KML and GML data structure before converting kml to gml

WHAT IS KML (Keyhole Markup Language)? – KML (Keyhole Markup Language), is an XML grammar and file format for modeling and storing geographic features such as points, lines,images, and polygons for display in the Google Earth client.KML is based on GML, although it doesn’t formally import GML schemas. KML language is used by a variety of GIS and mapping applications and the specifications are freely available to the public and available to the user community without charge or restriction. The Google Earth client supports a number of display features for rich presentation of GIS data. All of the features supported by the Google Earth client are described in KML. The Google Earth client supports a number of two-dimensional geometric shapes for display in the 3D viewer.

<Schema name="roads" id="roads">
 <SimpleField name="MED_DESCRI" type="string"></SimpleField>
 <SimpleField name="RTT_DESCRI" type="string"></SimpleField>
 <SimpleField name="F_CODE_DES" type="string"></SimpleField>
 <SimpleField name="ISO" type="string"></SimpleField>
 <SimpleField name="ISOCOUNTRY" type="string"></SimpleField>
 <SimpleField name="Length_km" type="float"></SimpleField>
 <SimpleField name="Latitude" type="string"></SimpleField>
 </Schema>
 <Folder><name>roads</name>
 <Placemark>
 <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
 <ExtendedData><SchemaData schemaUrl="#roads">
 <SimpleData name="MED_DESCRI">Without Median</SimpleData>
 <SimpleData name="RTT_DESCRI">Secondary Route</SimpleData>
 <SimpleData name="F_CODE_DES">Road</SimpleData>
 <SimpleData name="ISO">IND</SimpleData>
 <SimpleData name="ISOCOUNTRY">US</SimpleData>
 <SimpleData name="Length_km">0.3</SimpleData>
 </SchemaData></ExtendedData>
 <LineString><coordinates>77.8277403975188,35.5012774951028 77.8257523065223,35.4995003281062</coordinates></LineString>
 </Placemark>

WHAT IS GML (Geography Markup Language)? GML (Geography Markup Language) is only concerned with the representation of the geographic data content. While GML is an effective means for transporting geographic information from one place to another we expect that it will also become an important means of storing geographic information as well.

<gml:boundedBy>
 <gml:Box>
 <gml:coord><gml:X>-164404.6900820375</gml:X><gml:Y>893749.1179630321</gml:Y></gml:coord>
 <gml:coord><gml:X>2727970.187011702</gml:X><gml:Y>3932312.865004988</gml:Y></gml:coord>
 </gml:Box>
 </gml:boundedBy>
 <gml:featureMember>
 <ogr:raods fid="raods.0">
 <ogr:geometryProperty><gml:LineString srsName="EPSG:32643"><gml:coordinates>756486.657418272,3932312.4133327 756311.93383727,3932110.06520674</gml:coordinates></gml:LineString></ogr:geometryProperty>
 <ogr:MED_DESCRI>Without Median</ogr:MED_DESCRI>
 <ogr:RTT_DESCRI>Secondary Route</ogr:RTT_DESCRI>
 <ogr:F_CODE_DES>Road</ogr:F_CODE_DES>
 <ogr:ISO>IND</ogr:ISO>
 <ogr:ISOCOUNTRY>US</ogr:ISOCOUNTRY>
 <ogr:Length_km>0.3</ogr:Length_km>
 <ogr:Latitude xsi:nil="true"/>
 </ogr:USraods>
 </gml:featureMember>
 <gml:featureMember>

Convert KML to GML using Ogr2ogr utility-

For using this utility you need to install GDAL OGR2OGR in your system. To  install this you can follow the given commands.

KML to GML - Convert Keyhole to Geography
KML to GML – Convert Keyhole to Geography

If you have already install ogr2ogr utility you can check by typing ogr2ogr in terminal.

KML to GML - Convert Keyhole to Geography

Now run the given command to convert from KML to GML-

--- ogr2ogr -f 'GML' Output_GML.gml Input_KML.kml

Changing Coordinate System of Output File kml to gml-

Sometimes we need different coordinate system. So to get different coordinate system from input you can follow this given command.

--- ogr2ogr -f 'GML' -t_srs EPSG:32643 -s_srs EPSG:4326 Output_GML.gml Input_KML.kml

Convert KML (KeyHole Markup Language) to GML (Geography Markup Language) Using PHP Code-

If you want the conversion using programing or don’t want to use terminal then this can also be done using PHP. You can create a function that defined this command as string and can give this string in shell_exec() method to execute. Shell_exec() actually execute the command and returns output as string.

public function kmltogml($kmlfilepath,$output,$srsno,$srsold){
 $query="ogr2ogr -f GML -t_srs EPSG:$srsno -s_srs EPSG:$srsold $output.gml $kmlfilepath";
 shell_exec($query);
 }

Generated output of kml to gml –

KML to GML - Convert Keyhole to Geography
KML to GML – Convert Keyhole to Geography

If you have any problem regrading this tutorial, please let us know via comments  in provided comments box.

KML to SHP Shapefile – Convert

Convert kml to shp shapefile. Have you extracted and downloaded kml file from Google Earth or Google map and want to render it with your geo library which support shapefile? Do you have KML data given from third party and want to give a proper representation of data over map by converting the same in shapefile? If so, here is an article to convert kml to shp using command line tool ogr2ogr or using php code. While if you use QGIS tool, you can look over kml to shp convert using QGIS or else continue using this article.

Here is the online Tool To Convert KML To SHP Shapefile

KML (Keyhole Markup Language) is very popular GIS format. It is available in text format containing tags such as Placemark, SimpleField, SimpleData and ExtendedData etc. It contains whole information in tag. But when you need to see the geometry you may require Shapefile. This conversion can be done using Ogr2ogr utility from GDAL (Geospatial Data Abstraction Library) and other GIS software such as QGIS, ArcGIS etc.

Convert kml to shp – Look Details For KML (Keyhole Markup Language) structure with Line feature-

<Schema name="India_roads" id="India_roads">
 <SimpleField name="MED_DESCRI" type="string"></SimpleField>
 <SimpleField name="RTT_DESCRI" type="string"></SimpleField>
 <SimpleField name="F_CODE_DES" type="string"></SimpleField>
 <SimpleField name="ISO" type="string"></SimpleField>
 <SimpleField name="ISOCOUNTRY" type="string"></SimpleField>
 <SimpleField name="Length_km" type="float"></SimpleField>
 <SimpleField name="Latitude" type="string"></SimpleField>
 </Schema>
 <Folder><name>India_roads</name>
 <Placemark>
 <Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
 <ExtendedData><SchemaData schemaUrl="#India_raods">
 <SimpleData name="MED_DESCRI">Without Median</SimpleData>
 <SimpleData name="RTT_DESCRI">Secondary Route</SimpleData>
 <SimpleData name="F_CODE_DES">Road</SimpleData>
 <SimpleData name="ISO">IND</SimpleData>
 <SimpleData name="ISOCOUNTRY">INDIA</SimpleData>
 <SimpleData name="Length_km">0.3</SimpleData>
 </SchemaData></ExtendedData>
 <LineString><coordinates>77.8277403975188,35.5012774951028 77.8257523065223,35.4995003281062</coordinates></LineString>
 </Placemark>
 <Placemark>

In the above given example, attribute fields are given with their data type. In style tag geometry style shown with color. Extended Data encloses attribute field name with values. In the last coordinates are given for particular line string. In similar way other lines, point and polygon are given in KML.

You may also look over converting Shapefile to kml using QGIS or shp to kml using ogr2ogr tool.

KML to SHP Shapefile – Convert

    • Go to MapOG Tool  and login with email id or if you are new user then register with a valid email id.
    • After login next step is to  Tap on Switch To and select Converter.
    • Next screen will be opened. Upload your data from system or drag & drop.
    • After uploading your data select the output data. For KML to Shapefile select SHP.
    • If you want your output in different coordinate reference system then click on change CRS.
    • Your converted file is directly published on the map. Download your converted file by clicking download icon.

For step by step approach check the video given below:

Convert from Keyhole Markup Language KML to SHP Shapefile using ogr2ogr utility-

For using this utility you need to install it in your system. To install this utility you can follow given commands,

KML to SHP Shapefile - Convert
KML to SHP Shapefile – Convert

If you already have install this utility or you want to check availability of this utility you can type ogr2ogr in terminal.

KML to SHP Shapefile - Convert

For conversion the given command need to be executed on terminal-

--- ogr2ogr -f 'ESRI Shapefile' Output_sahpefile.shp Input_KML.kml

Here -f defines the output file format and ‘ESRI shapefile’ is driver available.

PHP code for converting KML to SHP shapefile-

If you want the conversion using programing or don’t want to use terminal then this can also be done using PHP. You can create a function that defined this command as string and can give this string in shell_exec() method to execute. Shell_exec() actually execute the command and returns output as string.

public function KML_to_shp($KMLfilepath,$output){
 $query="ogr2ogr -f 'ESRI Shapefile'  $output.gml  $KMLfilepath";
 shell_exec($query);
 }

Generated output in QGIS software-

KML to SHP Shapefile - Convert
KML to SHP Shapefile – Convert

Change Coordinate System of shapefile generated from kml-

Changing coordinate system of output file can be done with this same ogr2ogr utility. It has various option for SRS (Spatial reference system), given below

-a_srs srs_def:

Assign an output SRS

-t_srs srs_def:

Reproject/transform to this SRS on output

-s_srs srs_def:

Override source SRS

These option can be used in command as-

— ogr2ogr -f ‘ESRI Shapefile’ -t_srs EPSG:32643 (new EPSG) -s_srs EPSG:4326 (old EPSG) shpchange.shp output1.kml

Generated shapefile from kml after changing coordinate system in QGIS software-

Convert- KML to Shapefile - Keyhole Markup Language

Hence, we get our shapefile. Furthermore, try our tool MAPOG Tool if you want to conversion in single click.

You also can visit Shapefile to GeoJSON, Shapefile to TopoJSON, Shapfile to geopackage, KML to shapefile conversion using QGIS etc.

If you face any problem during implementing this tutorial, please let us know. Feel free to comment in given comment box.

Even more try your hands on our Conversion Tool

Shp to SQL – Convert Shapefile to postgersql file

Shapefile shp can be converted in pgsql file using shp2pgsql command line tool. Sometimes you have a shapefile and want to upload the same in postgresql database, you can directly use shp2pgsql command and upload shapefile to postgis. While there might be possibilites that you would not be having access to your production server to install shp2pgsql command line tool, so you can convert shapefile into a sql file and then upload the same to Database. Lets check how to convert shp to sql file.

Conversion using shp2pgsql – shp to sql

Try Our Tool MapOG Converter for SHP to SQL conversion

For executing this command you need to have shp2pgsql utility in your system. You can check the presence of utility by typing shp2pgsql in terminal. If this utility is present then you will see the following result.

Convert- Shapefile Shp to SQL postgersql file
Convert- Shapefile Shp to SQL postgersql file

Shp2pgsql has some option, some for them are used here. Option -I creates a spatial index on the geocolumn. Option -s specifies the SRS (Spatial Reference system) in EPSG (European Petroleum Survey Group) number.

–> shp2pgsql -I -s 4326 shpfilepath.shp output_table_name > output.sql

After executing this command, you can run the sql file in postgres to insert data in table.

Code – Convert- Shapefile Shp to SQL postgersql filE

If you know to read binary files by knowing its format, you can easily read and convert shapefile to sql, as shapefile has an open standard file format. For instance, you can look over tutorial I had created in how to read shapefile bounding box using c++ or reading shapefile header.

In codeigniter framework of php, we can use shell_exec() by providing command as input. In command we need to export PGPASSWORD, where password is supplied.
While writing command in PHP, we need to take SRS (Spatial Reference system) of shape file, input shapefile and output file name from the user. The passwrThen query is written in string format and supplied to shell_exec() method. This method returns output as string and generates file in folder.

PGPASSWORD behaves the same as the password connection parameter. Use of this environment variable is not recommended for security reasons, as some operating systems allow non-root users to see process environment variables via ps; instead consider using the ~/.pgpass file. For more detail you can visit https://www.postgresql.org/docs/9.1/static/libpq-envars.html link.

public function shptosql($shpfilepath,$output){
$srs=4326;
$query=”export PGPASSWORD=’download1′; shp2pgsql -I -s $srs $shpfilepath $output > $output.sql”;
shell_exec($query);
}

You can check for SQL file in the same folder where shapefile is kept. The generated result will look like-

Convert- Shapefile Shp to SQL postgersql file
Convert- Shapefile Shp to SQL postgersql file

Change coordinate system – shp to sql

While converting shapefile into sql, you can not change the coordinate system. But you can execute this process in two steps as-

  1. Change the coordinate system of shapefile

–> ogr2ogr -f ‘ESRI shapefile’ -s_srs EPSG:4326 (old EPSG number) -t_srs EPSG:32643 (new EPSG number) new_shapefile.shp India_raods.shp

2. Then convert shapefile into sql

–> shp2pgsql -I -s 32643 new_shapefile.shp output_table_name > output.sql

ogr2ogr utility has some options as-

-a_srs srs_def:

Assign an output SRS

-t_srs srs_def:

Reproject/transform to this SRS on output

-s_srs srs_def:

Override source SRS

You may also Check Shapefile to GeoJSON, Shapefile to KML, Shapefile toconverting TopoJSON, etc conversion.

Hope you enjoyed the conversion and executed it successfully. Let us know you face any difficulty during execution of this tutorial via commenting in provided box.

Shp to MIF – Convert Shapefile to MapInfo Interchange Format

Many people uses MapServer as their Server, so they might need to store shape file as MIF (Map Info File) file on server. The OGR Simple Features Library allows MapServer users to display several types of vector data files in their native formats. For example, MapInfo Mid/Mif and TAB data can be seen on MapServer when using OGR support with it. So lets see how to convert Shapefile shp to mif or map info file.

Here is the online tool To convert Shapefile to MapInfo MIF 

Lets look what is MIF ( MapInfo Interchange Format) Before converting shp to Mif

MIF (Map Info File) File format used by MapInfo mapping and geographic analysis software. This stores a map visualization in a format that can be recognized by third party applications. Also used as an exchange format between GIS applications. This sometimes accompanied by a .MID (MapInfo data) file that contains additional spatial data. MID files are GIS data files created by MapInfo, a spatial data analysis and visualization software, saves spatial data for a corresponding .MIF (MapInfo Interchange Format) file. Also used for storing larger data sets not expressed in the MIF file.  What is Shapefile – collection of geometry with other supported files as shx, dbf, prj ect.

MIF file show some general property when open with QGIS software, as like :

i.) Storage type of this layer
–> MapInfo File
ii.) Description of this provider
–> OGR data provider (compiled against GDAL/OGR library version 2.2.2, running against GDAL/OGR library version 2.2.2)
iii.) Source for this layer
–> /var/www/html/PHP_pgrouting/public/shpfolder222/newwhello.mif
iv.) Geometry type of the features in this layer
–> Line
v.) The number of features in this layer
–> 19148
vi.) Capabilities of this layer
–> Fast Access to Features at ID, Presimplify Geometries, Presimplify Geometries with Validity Check
vii.) In layer spatial reference system units
–> xMin,yMin 68.4982,7.92528 : xMax,yMax 97.3348,35.5013
viii.) Layer Spatial Reference System
–> +proj=longlat +datum=WGS84 +no_defs

Convert Shapefile SHP TO MIF format using ogr2ogr utility-

ogr2ogr supports some file format MIF is one of them. You can write a simple command to convert your shapefile. Before this you must check for ogr2ogr utility. That can be done by typing ogr2pgr in your terminal.

Convert- Shapefile Shp to MIF - Map Info File
Convert- Shapefile Shp to MIF – Map Info File

If this utitlity is not available, you should run the given commands-

Convert- Shapefile Shp to MIF - Map Info File

After this please check ogr2ogr utility http://www.gdal.org/ogr2ogr.html is available now.

Now you can move for conversion. For conversion please use the given command

–> ogr2ogr -f “MapInfo File” output_file.mif Input_SHP.shp

Note-

You must have shp along with .shx and .dbf file for proper conversion.
If you only have shp file you will got an error something like.

Convert- Shapefile Shp to MIF - Map Info File
Convert- Shapefile Shp to MIF – Map Info File

And if you don’t have .dbf file, then you following error will appear

Convert- Shapefile Shp to MIF - Map Info File

Code to Convert Shp to MIF

If you are aware of reading binary file by knowing the file format, you can easily read and parse shapefile and convert the same to any other format. You can check out one such tutorial which I had created to read header of shapefile using c++ or bounding box of shapefile using c++.

This same work can be done in PHP using shelll_exec() method, which execute the command and gives output as string. The following function describes the $query variable, which takes command as string and given to shell_exec(0 method.

public function shptomif($shpfilepath,$output) {
$query=”ogr2ogr -f ‘MapInfo file’ $output.mif $shpfilepath.shp”;
shell_exec($query);
}

Output of mif file from shp file-

The Output will contain .mif and .mid files. You can open MIF file in QGIS software.

If you are using Windows operating software than you can open .mif (Map Info File) with microsoft word. The following result will appear

Version 300
Charset “Neutral”
Delimiter “,”
CoordSys Earth Projection 1, 104
Columns 7
MED_DESCRI Char(254)
RTT_DESCRI Char(254)
F_CODE_DES Char(10)
ISO Char(7)
ISOCOUNTRY Char(54)
Length_km Decimal(11,2)
Latitude Decimal(11,2)
Data line(…..)

Change Coordinate System of MIF from shp format

Converting shapefile into MapInfo File with desired coordinate system can be done by using ogr2ogr utility. It has some options related to SRS (Spatial reference system), given below-

-t_srs srs_def:

Reproject/transform to this SRS on output

-s_srs srs_def:

Override source SRS

So the query can be written as-

–> ogr2ogr -f ‘MapInfo File’ -s_srs EPSG:4326 (old EPSG) -t_srs EPSG:32643 (new EPSG) output_mifFile.mif Input_file.shp 

Hope this tutorial helped you to convert your shapefile to MIF (Map Info File) format. There are also various conversion available as- Shape to CSV, GeoJson to topoJson, Shapefile to Topojson , shapefile to kml, shp to ods, shp to gml etc.

Please let us know, if any find any difficulty in performing this conversion via commenting in provided box.

SHP to XLSX – Convert Shapefile to Excel

Sometimes we just need to see attribute details not geometry. So instead of carrying heavy shape files we can convert them in XLSX format. XLSX file contains on attribute detail or can say non spatial data. XLSX files are light in weight. Along with shp to xlsx convert you may also check for shp to ods, shp to csv conversion which also more focuses on attribute details.

Convert SHP to XLSX using MapOG Tool for hassle free conversion

KNOW ABOUT XLSX AND SHAPEFILE format -BEFORE CONVERTING SHP TO XLSX

An XLSX file is an Excel spreadsheet created by Microsoft Excel or another spreadsheet program. It stores data in worksheets, which contain cells arranged in a grid of rows and columns, and may also contain charts, mathematical functions, styles, and formatting. XLSX files create simple or complex mathematical models.

What is shapefile? Each object within a SHP file contains an individual geographic feature and its attributes.

Conversion from shapefile to XLSX using ogr2ogr utility-

–> ogr2ogr -f XLSX output_xlsx_filename.xlsx India_raods.shp

In command -f is file format and XLSX is driver. Then you can specify the output file name with .xlsx extension and input shapefile. This command can be executed on terminal or using PHP code. Here you must look for the ogr2ogr utility in your system. If not available you can install it using given line of code.

SHP to XLSX

Then you can check the presence of utility by typing ogr2ogr in terminal. The output will look like-

SHP to XLSX
SHP to XLSX

Note that while converting shapefile to XLSX, you must check for .shx file. If shx file is not available you may get following error.

SHP to XLSX

Shapefile has some supporting file like .dbf, .shx, .prj etc. So you must take all file whenever you perform conversion.

PHP CODE – SHP to XLSX

If you are aware of Shapefile Open description format, then you can easily access shapefile data through coding. As i have created one such shapefile minimum bounding box parser in c++. Below in the php code to execute ogr2ogr tool.

Here you can perform the conversion using shell_exec() method, which actually executes the command and returns string as output.

public function shptoxlsx($shpfilepath,$output) {
$query=”ogr2ogr -f XLSX $output.xlsx $shpfilepath.shp”;
shell_exec($query);
}

After execution of command you can check the specified folder to see generated xlsx file. The content of file will be something like-

SHP to XLSX

You may also look forward to convert shapefile to GeoJSON, Shapefile to Kml, Shapefile to topojson and etc conversions.

Hope you enjoyed the article and successfully converted shape file into XLSX file. If you have any problem regarding conversion please feel free to write in comment box.

Shp to ODS – Convert Shapefile to Open Document Spreadsheet

Shape file to ODS (Open Document Spreadsheet) conversion is required when you only need non spatial information i.e. only attribute information. This conversion need ogr2ogr utility. Or you may also you any other tool to convert shp to ods easily.

Convert SHP to ODS using MapOG Tool for hassle free conversion

What is ODS (Open Document Spreadsheet) and Shapefile-Shp to ODS CONVERT

An ODS (Open Document Spreadsheet) file is a spreadsheet. It stores data in cells that are organized into rows and columns. ODS files are formatted using the OASIS Open Document XML-based standard. Whereas shape files are collection of geometry with non spatial data as attributes.

To install ogr2ogr utility you can follow the given lines of command.

Convert Shapefile Shp to ODS- OpenDocument Spreadsheet

Then check for presence of ogr2ogr utility by typing ogr2ogr in your terminal.

Conert - SHP To ODS

Conversion- Shapefile shp to ODS (Open Document  Spreadsheet) using Ogr2ogr utility-

Now the conversion command can be executed,

–> ogr2ogr -f ODS output_ods_fileName.ods  India_raods.shp

Here, in the command -f is the option for file format.

Note that while converting shx file should be present in same folder where shp file is kept. Otherwise you will get error like-

Shapefile Shp to ODS- OpenDocument Spreadsheet

All the supported file (.shx, .prj and .dbf etc.) should be kept together while performing any conversion.

Code- Convert shp to ods

You can use any programming language to convert between shapefile to ods, if you know the format of shapefile and ods file. I have created one such minimum example of code to find the minimum bounding box of shapefile with c++ programming lanauage. Below is the php code.

public function shptoods($shpfilepath,$output) {
$query=”ogr2ogr -f ODS $output.ods $shpfilepath.shp”;
shell_exec($query);
}

The generated output can be seen in the same folder, where shapefile is kept. Output will look as-

Shapefile Shp to ODS- OpenDocument Spreadsheet
Shapefile Shp to ODS- OpenDocument Spreadsheet

You may also be interested in knowing how to convert shapefile to kml, shp to gml, shapefile to csv, shapefile to geojson, shapefile to topojson etc.

Hope this post is helpful for you to convert shp to ods document. If you find any difficulty in implementing the conversion of shapefile to open document spreadsheet, let you know by commenting below in the box provided.

SHP to GML – Convert Shapefile to Geography Markup Language

Shape file shp to GML conversion is required when you carry data from one place to another. Shapefiles are heavy as compared with GML (Geography Markup Language). On the other hand we can say that GML makes you able to do many of the same things that you would do with heavyweight desktop GIS files.

For a more in-depth guide on this topic, be sure to check out our accompanying video tutorial, where we walk you through each step visually and provide practical demonstrations.

Convert SHP to KML using MapOG Tool Converter

GML (Geography Markup Language) is about describing kinds of geographic objects. This is XML based language that contain two part- the schema that describes the document and the instance document that contains the actual data. GML schema allows users and developers to describe generic geographic data sets that contain points, lines and polygons. Using this schema user can differentiate between geometry primitives.

GMl format composed of geometry property and attribute detail in feature member tag. Here geometry defines which primitive is available in data. Whether it is point, line or polygon. These can be multilinestring or multipolygon. The given line of GMl defines the lineString, contains attributes as MED_DESCRI, RTT_DESCRI, F_CODE_DES, ISO and ISO_country in ogr tag. The srsName(Spatial reference system name) is given is file for each geometry as EPSG number.

LineString as Example of GML file Describing feature – Know Before performing shp to gml convert

<gml:featureMember>
 <ogr:India_raods fid="India_raods.0">
 <ogr:geometryProperty><gml:LineString srsName="EPSG:4326"><gml:coordinates>77.8277403974823,35.5012774951288 77.8257523064861,35.4995003281321</gml:coordinates></gml:LineString></ogr:geometryProperty>
 <ogr:MED_DESCRI>Without Median</ogr:MED_DESCRI>
 <ogr:RTT_DESCRI>Secondary Route</ogr:RTT_DESCRI>
 <ogr:F_CODE_DES>Road</ogr:F_CODE_DES>
 <ogr:ISO>IND</ogr:ISO>
 <ogr:ISOCOUNTRY>INDIA</ogr:ISOCOUNTRY>
 <ogr:Length_km>0.30</ogr:Length_km>
 </ogr:India_raods>
 </gml:featureMember>

This also contains the bounding box of whole data with four corner latitude longitude.

<gml:boundedBy>
 <gml:Box>
 <gml:coord><gml:X>68.49822243392609</gml:X><gml:Y>7.92528433268866</gml:Y></gml:coord>
 <gml:coord><gml:X>97.33479210700925</gml:X><gml:Y>35.50128146412876</gml:Y></gml:coord>
 </gml:Box>
 </gml:boundedBy>

Convert shapefile Shp to GML (Geography Markup Language) using Ogr2Ogr –

For converting shapefile in GML format you need to have ogr2ogr utility in your system. If this is not available you can follow the given procedure.

Convert Shapefile shp to GML - Geography Markup Language
Convert Shapefile shp to GML – Geography Markup Language

After installing, you can check the availability of ogr2ogr in terminal by typing ogr2ogr, then you will be able to see the following result.

Convert- Shape file to GML

Command Line conversion – shp to gml-

Now, to convert Shapefile to GML you need to execute the following command-

Convert- Shape file to GML

In this command -f is the output file format i.e. GML then specify the output file name with .gml extension and after that input shapefile name with .shp extension.
Note- while executing this command you must check for .shx file, which contains the positional index for geometry objects.

Code- Convert shp to GML

If you want the conversion using programing or don’t want to use terminal then this can also be done using PHP. You can create a function that defined this command as string and can give this string in shell_exec() method to execute. Shell_exec() actually execute the command and returns output as string.

public function shptogml($shpfilepath,$output){
$query=”ogr2ogr -f GML $output.gml $shpfilepath”;
print_r($query);
shell_exec($query);
}

The GML output file will be something like this-

Convert Shapefile shp to GML - Geography Markup Language

Change coordinate system of GML file from shp-

Many of times, we need the output file in other coordinate system. For this we can use options of ogr2ogr utility. It has

-t_srs srs_def:

Reproject/transform to this SRS on output

-s_srs srs_def:

Override source SRS

So using these option, we can get the data in required coordinate system. So for this you can write the query as-

–> ogr2ogr -f GML -t_srs EPSG:32643 (new EPSG) -s_srs EPSG:4326 (old EPSG) newGmlFile.gml InputFile.shp

You also can visit Shapefile to GeoJSON, Shapefile to KML, Shapefile to TopoJSON, Shapfile to geopackage etc.

If you face any problem during implementing this tutorial, please let us know. Feel free to comment in given comment box.