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

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

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

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-

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 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

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

Command Line conversion – shp to gml-

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

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-

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

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

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

  • Click on Convert file button.

  • 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.

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.

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 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

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

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

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

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

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

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

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 

Exit mobile version