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.

Shp to KML KMZ – Convert Shapefile to Keyhole Markup Language

Shapefile Shp to KML KMZ Convert. Many times you may want to render your shapefile directly in Google Map and check the view. Or you may want to convert the shapefile shp to KML so that it becomes easy to program with Google Map API. You can also check the file with Google Earth by loading KML converted from Shapefile.

KML is keyhole markup language file format, used to display geographic data on earth browser such as google earth and ArcGIS Explorer etc. This is XML tag-based structure. It is a highly portable single file that can contain all of a layer or map’s elements, such as feature geometry, imagery, symbology, descriptions, attributes, imagery, and other related content. Similarly .kmz  is spatial format, which is a compressed or zipped file of KML extension. In GIS vector and raster data formats are saved differently where as KML composed of including elements as line point polygon and imagery. While shapefile is a Vector file, comprised of three files i.e .shp, .shx and .dbf extension.

Checkout Online tool To convert Shapefile to KML or KMZ

KML File Format To Know Before Converting from Shapefile or SHP

Before taking a look on Converting Shapefile to KML or KMZ file, lets first look over how KML file look like. This is essential as if kml file is corrupted then conversion is not possible. And if you know file format, you can correct the same as we can edit the kml in text editor. If you already know the file format of KML, you may skip this step and look directly for Convert Shapefile shp to KML using ogr2ogr tool. Every geographic element such as point line or polygon is specified by different tags.

SHP to KML Conversion IGIS Map Tool

shp to kml

  • You can directly upload from your database or from Google drive or else from dropbox.

shp to kml

  • We are using google drive.  Once file upload is complete, select the output format. We tap on KML for output.

shp to kml

  • Click on Convert file button.

shp to kml

  • Here is your Converted Shp to Kml file. Tap on published button.

Download World Shapefile for project

Point Data KML file format – shp to kml

It contains geographic location, title and description as latitude and longitude.

<Placemark>
 <name>Simple placemark</name>
 <description>Attached to the ground. Intelligently places itself
 at the height of the underlying terrain.</description>
 <Point>
 <coordinates>-122.0822035425683,37.42228990140251,0</coordinates>
 </Point>
 </Placemark>

Line Data KML file format – shp to kml

Using style tag you can specify the color and width for lines.

<Style id="yellowLineGreenPoly">
 <LineStyle>
 <color>7f00ffff</color>
 <width>4</width>
 </LineStyle>
 <PolyStyle>
 <color>7f00ff00</color>
 </PolyStyle>
 </Style>
 <Placemark>
 <name>Absolute Extruded</name>
 <description>Transparent green wall with yellow outlines</description>
 <styleUrl>#yellowLineGreenPoly</styleUrl>
 <LineString>
 <extrude>1</extrude>
 <tessellate>1</tessellate>
 <altitudeMode>absolute</altitudeMode>
 <coordinates> -112.2550785337791,36.07954952145647,2357
 -112.2549277039738,36.08117083492122,2357
 -112.2552505069063,36.08260761307279,2357
 -112.2564540158376,36.08395660588506,2357
 -112.2580238976449,36.08511401044813,2357
 -112.2595218489022,36.08584355239394,2357
 -112.2608216347552,36.08612634548589,2357
 -112.262073428656,36.08626019085147,2357
 -112.2633204928495,36.08621519860091,2357
 -112.2644963846444,36.08627897945274,2357
 -112.2656969554589,36.08649599090644,2357
 </coordinates>
 </LineString>
 </Placemark>

The <tessellate> tag breaks the line up into smaller chunks, and the <extrude> tag extends the line down to the ground.

Polygon Data KML file format – shp to kml

<Placemark>
 <name>The Pentagon</name>
 <Polygon>
 <extrude>1</extrude>
 <altitudeMode>relativeToGround</altitudeMode>
 <outerBoundaryIs>
 <LinearRing>
 <coordinates>
 -77.05788457660967,38.87253259892824,100
 -77.05465973756702,38.87291016281703,100
 -77.05315536854791,38.87053267794386,100
 -77.05552622493516,38.868757801256,100
 -77.05844056290393,38.86996206506943,100
 -77.05788457660967,38.87253259892824,100
 </coordinates>
 </LinearRing>
 </outerBoundaryIs>
 <innerBoundaryIs>
 <LinearRing>
 <coordinates>
 -77.05668055019126,38.87154239798456,100
 -77.05542625960818,38.87167890344077,100
 -77.05485125901024,38.87076535397792,100
 -77.05577677433152,38.87008686581446,100
 -77.05691162017543,38.87054446963351,100
 -77.05668055019126,38.87154239798456,100
 </coordinates>
 </LinearRing>
 </innerBoundaryIs>
 </Polygon>
 </Placemark>

There are many option tags in KML.

Convert Shapefile SHP to KML KMZ

In this article we will have a look on how shapefile can be converted in KML. For conversion ogr2ogr command has used which should be written on terminal (command promt). You need to install ogr2ogr tool, which is open source tool and can be installed in Windows, Ubuntu, Mac or any other linux system.

Note that for converting shapefile to KML you must have shp along with shx file and dbf file. As shx file contains the positional index of the feature geometry whereas shp format contains geometry itself and dbf contains the data associated with the feature.

Command Format for using ogr2ogr tool to convert to kml :

---- ogr2ogr -f KML outputfilename.kml inputfilename.shp

Here is an example command line, to show how i had use ogr2ogr tool to convert the shp to kml file.

convert-shapefile to kml/kmz

Similarly you can convert shapefile to KML using QGIS tool.

Convert SHP to KML or KMZ using coding-

To convert in KMZ format you can just change the extension of output file from .kml to .kmz format. The option -f (output file format) remain same for both.

In PHP you can use this command using shell_exec() method. Here a function is created in which shapefile and Output file name is taken from user.

public function shptokml($shpfilepath,$output){
 $query= "ogr2ogr -f KML $output.kml $shpfilepath ";
 shell_exec($query);
 }

Similarly for KMZ, you can have a function as given below-

public function shptokmz($shpfilepath,$output) {
 $query="ogr2ogr -f KML output.kmz $shpfilepath";
 shell_exec($query);
 }

The converted output will contain all attribute details with their geographic location in latitude longitude form.

convert-shapefile to kml/kmz

Note-

KML only supports EPSG: 4326 i.e. +proj=longlat +datum=WGS84 . So you can not change the coordinate system of KML. But you can change the coordinate system of shapefile before converting it in KML.

Similarly you may also look for converting shapefile to GeoJSON, Shapefile to Topojson, Shapefile to Geopackage, Shapefile to Postgresql, shapefile to CSV etc. Also you can look for reverse convert the same i.e from KML to shapefile using QGIS or ogr2ogr tool.

Hope you enjoyed this article and successfully converted shapefile into KML. If you find any difficulty during execution of this article please let us know by commenting below in the box provided.

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

Convert KML to Shapefile in QGIS

Convert KML to Shapefile in QGIS. KML or Keyhole markup language file which store and models geographic features for displaying in Google earth or Google maps, which is not common in use for Map makers and GIS programmers. ESRI made a standard Vector file i.e Shapefile which is most commonly adopted in the field of GIS (Geographic Information System), and this made me to convert KML to shapefile, created for learning purpose from Google map. QGIS (Qunatum GIS) is an open source GIS tool, which provide you a function to convert the KML file to Shapefile, and Vice versa i.e Shapefile to kml file.

You might be looking for converting KML to shapefile when you get the data from third party or from website which download free GIS map data but in different formats which can also be converted to.

If you still don’t prefer using QGIS or GDAL utility to convert the file from kml to shp, then you should also look for KML to Shapefile Conversion using Online Tool.

Convert KML to Shapefile in QGIS
Convert KML to Shapefile in QGIS

You might be interested in seeing QGIS tutorials.

Instead of QGIS you can also try Online Converter tool here MAPOG Online converter tool

Convert KML to Shapefile in QGIS:

1.) Open up the installed QGIS.
2.) Select Layer in the menu bar and press Add Vector Layer or select the shortcut icon. Browse the KML file, in the Source DataSet type, in the pop up window opened.(While browsing, select either all files or Key Hole Markup language in file type). And press Open.

Convert KML to Shapefile in QGIS
Convert KML to Shapefile in QGIS

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

3.) In the Layer file appearing in the left upper side, right click on it, and select save as:

or

you can either select layer from the menu and click on save as.

Convert KML to Shapefile in QGIS`
Convert KML to Shapefile in QGIS

4.) In the Save vector layer as window, Select the format from the drop down box as ESRI Shapefile(OGR) and browse the folder in which you want to save the shapefile. Name it and Press OK.

Convert KML to Shapefile in QGIS
Convert KML to Shapefile in QGIS

Try our tool for conversion: MAPOG Online converter tool

Your Shapefile i.e .shp, .shx and .dbf file will be created in the directed folder. Upload your KML file in your map browser tool, or try our tool, to verify whether the tool preserves all attributes and elements or not. You may also see how to merge two shapefile in QGIS. Or if you are looking to convert that shapefile to kml to Topojson then you can look for GeoJSON to Topojson and Shapefile to GeoJSON and shapefile to TopoJSON. Do comment below if you are getting any problem in converting the file.

QGIS 3.2.1 for Beginners