OnlineMapMaker logo

GML Viewer: Open and View .gml Files on a Map Online

Open a .gml file on an interactive map. Every feature type becomes its own layer, the viewer finds the coordinate system and the axis order by itself, you can tap any feature for its attributes, and you can export the data as GeoJSON. It works on phones, and your file stays in your browser. Open fullscreen version →

Rate this tool:
Advertisement
Advertisement
Loading…
Need assistance with your GIS project?Explore Our Services

What this GML viewer does

GML (Geography Markup Language) is the XML format that governments, mapping agencies and WFS web services use to share geographic data. If you downloaded a .gml file from a cadastre, an INSPIRE download service or a WFS GetFeature request, you probably saw that most apps cannot open it. A web browser shows only the XML text, and many online map tools skip the format.

This viewer opens the file directly. Drop a .gml or .xml file on the map (a .zip or .gz archive with a GML file inside also works) and it reads the features, finds the coordinate system, converts the coordinates to longitude and latitude, and draws every feature type as a separate layer with its own color. The sidebar shows the GML version, how many feature types and features the file has, which coordinate system it uses and whether the axis order had to be swapped. Tap a feature to read its attributes.

Most GML files that appear in the wrong place have an axis-order or coordinate-system problem, so I built a fix for both into the viewer: automatic axis detection, and a "Coordinate system" box where you can type an EPSG code or a PROJ string and swap X and Y with one tick. When the map looks right, download one feature type or the whole file as GeoJSON. Nothing is uploaded, and the layout works well on a phone.

Advertisement
Advertisement

GML vs GeoJSON, KML and Shapefile

All four formats store geometry and attributes. They differ in who designed them and how much they describe.

AspectGMLGeoJSONKMLShapefile
StandardOGC and ISO 19136IETF RFC 7946OGC KML 2.2Esri specification (open)
File typeXML text, often largeJSON textXML textSeveral binary files (.shp, .shx, .dbf)
Coordinate orderDepends on the CRS: latitude first for EPSG:4326 in urn: namesAlways longitude, latitudeAlways longitude, latitude, altitudeX, Y (easting, northing or longitude, latitude)
Coordinate systemAny, named in srsNameWGS 84 onlyWGS 84 onlyAny, stored in the .prj file
AttributesAny, described by an XML schema (.xsd)Free-form propertiesName, description and extended dataA table in the .dbf file, field names up to 10 characters
Typical useWFS services, INSPIRE, cadastre, data exchange between agenciesWeb maps and APIsGoogle Earth, display and sharingDesktop GIS and file exchange

My rule of thumb: GML is the format you receive from official sources, and GeoJSON is the format you want to work with on the web. Keep the GML as the original and export a GeoJSON copy for everything else.

What is inside a GML file

A GML file is plain XML. A typical download from a WFS service has a collection element, then one member element per feature, and each feature has attributes and one geometry. These are the parts you will meet most often:

srsName
An attribute on a geometry (or on a gml:Envelope) that names the coordinate system, for example urn:ogc:def:crs:EPSG::4326 or EPSG:25832. It tells you how to read the numbers.
featureMember, member
Wrapper elements around each feature. GML 2 and 3.1 use gml:featureMember, WFS 2.0 uses wfs:member. Inside is the feature itself, named after its feature type, such as ex:parcel.
gml:id
The unique id of a feature. The viewer shows it as the gml_id attribute and uses it as the GeoJSON id.
gml:pos, gml:posList
The coordinates, written as numbers separated by spaces. pos holds one point and posList holds a whole line or ring. GML 2 uses gml:coordinates with commas instead.
exterior, interior
The outer ring and the holes of a polygon in GML 3. GML 2 calls them outerBoundaryIs and innerBoundaryIs.
Curve, Surface
GML 3 geometries that can contain arcs and patches. The viewer draws arcs as smooth lines and surfaces as polygons.
Attributes
Every other element of a feature, for example ex:name or ex:population. They become the attributes you see in the popup.

Here is a complete small file with one polygon, written the way a WFS 2.0 server writes GML 3.2:

<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs/2.0"
    xmlns:gml="http://www.opengis.net/gml/3.2" xmlns:ex="http://example.com/ns">
  <wfs:member>
    <ex:park gml:id="park.1">
      <ex:name>Vondelpark</ex:name>
      <ex:geom>
        <gml:Polygon srsName="urn:ogc:def:crs:EPSG::4326" gml:id="park.1.geom">
          <gml:exterior><gml:LinearRing>
            <gml:posList>52.3579 4.8686 52.3579 4.8800 52.3620 4.8800
                         52.3620 4.8686 52.3579 4.8686</gml:posList>
          </gml:LinearRing></gml:exterior>
        </gml:Polygon>
      </ex:geom>
    </ex:park>
  </wfs:member>
</wfs:FeatureCollection>

The srsName is urn:ogc:def:crs:EPSG::4326, so the official axis order applies: latitude first. The first pair 52.3579 4.8686 is latitude 52.3579, longitude 4.8686, which is the Vondelpark in Amsterdam. Read as longitude first, the same numbers put the polygon in the Indian Ocean.

Technical details

This is exactly what the viewer reads and shows.

Accepted files
.gml and .xml files, and .zip or .gz files that contain one, up to 60 MB. Files in UTF-8 or in any encoding named in the XML header (for example ISO-8859-1) are read correctly.
GML versions
GML 2, GML 3.1 and GML 3.2, including WFS 1.x and 2.0 FeatureCollection responses, GML 3.2 simple feature downloads and OGR output.
Geometry types
Point, LineString, LinearRing, Polygon, MultiPoint, MultiLineString, MultiPolygon, MultiCurve, MultiSurface, MultiGeometry, Curve (line segments and arcs), Surface, CompositeCurve, CompositeSurface, OrientableCurve, OrientableSurface and Solid (drawn from its faces, in 2D).
Feature types
Every kind of feature becomes its own layer, with a checkbox, a color, its geometry type, its feature count, its field count and a GeoJSON download.
Attributes
Simple elements become attributes. Nested elements are flattened with dots, for example address.city. Numbers stay numbers, and codes with a leading zero stay text. The gml:id is added as gml_id.
Coordinate systems
WGS 84 and the equivalent ETRS89, NAD83, GDA94 and GDA2020, Web Mercator, every UTM zone, and national systems such as RD New (28992), British National Grid (27700), Lambert-93 (2154), ETRS89-LAEA (3035), CH1903+ (2056) and the Gauss-Krüger zones (31466 to 31469). Any other system works when you paste its PROJ string. Datum differences below about 2 m are ignored.
Axis order
Read from the srsName and checked against the numbers. If the result looks wrong, tick "Swap X and Y" and press Apply.
Limits
Features without a geometry are counted in a message and not drawn. Arcs are drawn as smooth lines. Heights are ignored, so 3D data is drawn in 2D.
Export
Each feature type as its own GeoJSON file, or all types in one file with a gml_feature_type attribute.
Basemap
Street map by default, with a satellite option. Set the fill opacity to 0 to see only the outlines.
Phones and tablets
On a small screen the layout changes to one column: controls above the map, the sidebar below it, with large buttons for your fingers.
Privacy
The file is read and converted in your browser. Nothing is sent to a server.

Why a GML file shows up in the wrong place

Two things go wrong again and again: the axis order and the coordinate system. Both are easy to fix once you know what to look for.

The latitude-first trap

The official definition of EPSG:4326 lists latitude before longitude. GML 3 and WFS 1.1 and 2.0 follow it when the srsName is written as a urn, so the coordinates arrive as latitude, longitude. GeoJSON and most web maps use the opposite order. If you plot such numbers as x, y, the data is mirrored across the diagonal and often lands in the wrong ocean.

urn:ogc:def:crs:EPSG::4326   52.3676 4.9041   (latitude, longitude)
EPSG:4326                    4.9041 52.3676   (often longitude, latitude)

The viewer reads the srsName and then checks the numbers: values that cannot be latitudes rule an order out. When both orders are possible, it follows the srsName. If the map still looks wrong, tick "Swap X and Y".

Projected coordinates

Many national files do not use degrees at all. They use meters in a projected system, for example RD New in the Netherlands, where Amsterdam is near 121000 487000. These numbers only make sense together with the right EPSG code, and the viewer uses the srsName to turn them into longitude and latitude.

EPSG:28992 (RD New)    121000  487000   ->   52.370 N   4.888 E
EPSG:25832 (UTM 32N)   500000 5700000   ->   51.451 N   9.000 E

If the file has no srsName, or a code the viewer does not know, you get a message and not a wrong map. Type the EPSG code you know the data uses, or paste a PROJ string, and press Apply.

How to find the right code

Look for srsName in the file, often on the first geometry or in the boundedBy element. If it is missing, check the metadata of the download, the .xsd schema or the website the data came from. Agencies in Europe usually publish in ETRS89: EPSG:4258 for degrees, or a UTM or national grid code for meters. The EPSG number of a national grid is easy to find on epsg.io, which also shows its PROJ string.

How to view a GML file, step by step

Here is the whole workflow with the built-in sample: 50 European countries and 22 capital cities from Natural Earth, written as a WFS 2.0 response in GML 3.2 with latitude-first coordinates, the way a real server sends them.

Empty GML Viewer with the Upload, Sample Data and Street/Sat buttons above a world map
1
Step 1: Open the viewer

The map opens with a street basemap. Use Upload, drag a file onto the map, or tap Sample Data. On a phone the controls sit above the map and the sidebar is below it.

European countries and capital cities loaded from the sample GML file, with the File Info panel
2
Step 2: Load a GML file

The file is read in your browser and every feature type is drawn in its own color. File Info shows the GML version, the number of feature types and features, the coordinate system and the axis order that was found.

Feature types panel with the country and capital types, their checkboxes, colors and download links
3
Step 3: Work with the feature types

The Feature types panel lists each type with its geometry and feature count. Untick a type to hide it, or tap its color square to change the color.

Coordinate system panel with the EPSG code box, the Swap X and Y option and the Apply button
4
Step 4: Check the coordinate system

The Coordinate system panel is where you fix a file that lands in the wrong place. Type an EPSG code such as 28992 or a PROJ string, tick "Swap X and Y" if needed, and press Apply.

Popup on Germany showing its gml_id, name, ISO codes, area and population
5
Step 5: Read the attributes

Click or tap any feature to open its attributes. The popup names the feature type and shows the gml_id and every attribute from the file.

Actions panel with the Download All as GeoJSON button highlighted
6
Step 6: Export to GeoJSON

Use the GeoJSON link next to a feature type to download just that type, or Download All as GeoJSON for everything in one file.

Advertisement
Advertisement

Other ways to open and convert GML

This viewer is for looking at a file quickly. These are the other tools I use when a GML file needs real work.

QGIS

QGIS opens GML through GDAL. Choose Layer, Add Layer, Add Vector Layer and pick the file. Each feature type appears as its own layer. Right-click a layer and choose Export, Save Features As to write GeoPackage, Shapefile or GeoJSON.

ArcGIS

ArcGIS reads GML through the Data Interoperability extension (Quick Import). Without the extension, convert the file in QGIS or with ogr2ogr first, and then add the result to your project.

GDAL and ogr2ogr

GDAL has a GML driver. ogrinfo lists the feature types, their fields and the coordinate system, and ogr2ogr converts to GeoJSON, GeoPackage or Shapefile and can reproject with -t_srs EPSG:4326.

Python and R

GeoPandas reads GML through GDAL, one feature type (layer) at a time. In R, sf::st_read("data.gml") does the same.

The same jobs in code

These commands list the feature types in a GML file, convert it to GeoJSON and GeoPackage, and read it in Python.

# GDAL / OGR
ogrinfo -so -al data.gml                              # feature types, fields and the CRS
ogr2ogr -f GeoJSON out.geojson data.gml -t_srs EPSG:4326
ogr2ogr -f GPKG out.gpkg data.gml

# Python: GeoPandas reads GML through GDAL, one feature type (layer) at a time
import geopandas as gpd
parcels = gpd.read_file("data.gml", layer="park").to_crs(4326)

My take: treat the GML you receive as the source of truth, and convert a copy. GeoJSON or GeoPackage is easier to edit and share, and you can always check the result against the original here.

Advertisement
Advertisement

Typical uses

People open GML files for many practical reasons. These are the most common.

  1. Check a WFS download. You sent a GetFeature request to a WFS service and got a .gml file back. Open it here to see whether it covers the right area and has the right attributes before you load it into a project.
  2. Open government and INSPIRE data. Many data portals publish parcels, addresses, buildings and protected sites as GML. Open the file to see what you really received.
  3. Find out why a file is in the wrong place. When a GML layer lands in the ocean or off the coast of Africa, the axis order or the coordinate system is wrong. The sidebar shows what the viewer found, and you can try other values on the spot.
  4. Open a file without GIS software. You are on a Chromebook, on a phone or on a laptop without QGIS, and someone sent you a .gml file. Open it in the browser. There is nothing to install.
  5. Convert GML to GeoJSON. Export one feature type, or all of them, as GeoJSON for Leaflet, Mapbox or any tool that does not read GML.
  6. Check data before you send it. You exported GML from a planning or cadastre system. Open it to confirm that the geometries, the attributes and the coordinate system are what the receiving agency expects.
  7. Teach GML and WFS. Students can load a small file, see how a posList becomes a polygon and compare the two axis orders. The sample file in the viewer is a good start.
  8. Read attributes quickly. Tap features to read names, codes and dates without scrolling through thousands of lines of XML.

Frequently asked questions

1. What is a GML file?

GML stands for Geography Markup Language. It is an XML format, standardized by the OGC and by ISO (ISO 19136), that stores geographic features: their geometry (points, lines, polygons) and their attributes. Agencies and WFS web services use it to exchange data.

2. How do I open a GML file?

The quickest way is this viewer: press Upload, or drag the file onto the map, and the features appear. To edit the data, open the file in QGIS with Layer, Add Layer, Add Vector Layer, or convert it with ogr2ogr. A text editor shows only the XML.

3. How can I view a GML file online without installing software?

Open this page, press Upload and choose your .gml file. Everything runs in your browser, so there is nothing to install and nothing to log in to. It works on phones and tablets too.

4. How do I convert GML to GeoJSON?

Open the file here and press Download All as GeoJSON, or use the GeoJSON link next to one feature type. The coordinates are converted to longitude and latitude (WGS 84), which GeoJSON requires. On the command line, ogr2ogr -f GeoJSON out.geojson in.gml -t_srs EPSG:4326 does the same job.

5. Why does my GML file appear in the wrong place?

Almost always the axis order or the coordinate system. With urn:ogc:def:crs:EPSG::4326 the numbers are latitude first. The viewer detects this, but if your file has no srsName or an unusual one, type the EPSG code in the Coordinate system box, or tick "Swap X and Y", and press Apply.

6. Which coordinate systems does the viewer support?

WGS 84 and its equivalents, Web Mercator, every UTM zone and many national grids, for example RD New, British National Grid, Lambert-93, ETRS89-LAEA, CH1903+ and Gauss-Krüger. For any other system, paste its PROJ string, which starts with +proj.

7. Can it open GML from a WFS or an INSPIRE download?

Yes. WFS 1.x and 2.0 FeatureCollection responses (with featureMember or member elements) and GML 3.2 simple feature files open directly. A .zip that contains the GML file works too.

8. Does it open .xml files?

Yes, as long as the XML contains GML features. WFS servers often save their answer as .xml, and the viewer reads it the same way as .gml.

9. Is my file uploaded to a server?

No. The file is read and converted in your browser. It is not sent to OnlineMapMaker or to any other server. Only the basemap tiles come from the internet.

10. What is the maximum file size?

Up to 60 MB for the file you choose (a ZIP or GZ file counts at its compressed size). Files with several hundred thousand features can be slow, especially on a phone. For those, filter or convert the data in QGIS or with ogr2ogr first.

11. Does it work with CityGML or 3D data?

The viewer is made for 2D GML feature data. CityGML 3D city models are outside its scope, so use a 3D viewer for those.

12. What is the difference between GML and XML?

XML is a general way to write structured text. GML is a set of XML rules for geographic data: it defines how to write points, lines, polygons and coordinate systems. Every GML file is XML, but not every XML file is GML.

Libraries and data

This viewer is built on open source software and open data. Many thanks to the people behind these projects.

Related GIS file viewers

GML files are read and converted in your browser. No file is ever uploaded to a server. The viewer shows the data as it is stored in the file, and datum shifts below about 2 m are ignored, so do not use it for surveying. The sample uses Natural Earth data (public domain). Map tiles © OpenStreetMap contributors, drawn with Protomaps (hosted by KONAKTIVE), with CARTO as the fallback. Satellite imagery: Esri.

Muhammad Gulraiz Khan, GIS Expert and Founder of KONAKTIVE and OnlineMapMaker.com

About the Author

Muhammad Gulraiz Khan

GIS Expert & Consultant · Founder, KONAKTIVE

Muhammad Gulraiz Khan is a GIS expert with over a decade of professional experience delivering geospatial solutions for the energy sector, including projects for the World Bank, the International Finance Corporation (IFC), and USAID. He built OnlineMapMaker.com to make professional-grade mapping tools free and accessible to everyone.

Advertisement
Advertisement