GML Format
Description
GML (Geography Markup Language) is an XML-based standard for encoding geographic information. It's an OGC (Open Geospatial Consortium) standard used for exchanging geographic data. GML supports complex geographic features with multiple geometry types.
File Extensions
.gml- GML files
Implementation Details
Reading
The GML implementation:
- Parses GML FeatureCollection elements
- Extracts featureMember elements
- Supports GML 2.0 and 3.2 namespaces
- Extracts geometry (Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon)
- Extracts feature properties
- Converts to GeoJSON-like feature format
- Uses
lxmllibrary for XML parsing
Writing
Writing support:
- Writes GML FeatureCollection structure
- Converts GeoJSON-like features to GML
- Supports Point, LineString, Polygon geometries
- Uses GML 3.2 namespace
- Writes properties as feature attributes
Key Features
- OGC standard: Official OGC standard for geographic data
- Multiple geometries: Supports Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon
- Feature properties: Extracts and writes feature attributes
- Namespace support: Handles GML 2.0 and 3.2 namespaces
- Complex structures: Supports nested geographic structures
Usage
from iterable import open_iterable
# Basic reading
source = open_iterable('data.gml')
for feature in source:
print(feature) # Each feature is a dict with geometry and properties
# feature['type'] == 'Feature'
# feature['geometry'] contains geometry data
# feature['properties'] contains attributes
source.close()
# Writing
dest = open_iterable('output.gml', mode='w')
feature = {
'type': 'Feature',
'geometry': {'type': 'Point', 'coordinates': [102.0, 0.5]},
'properties': {
'name': 'Location',
'id': '1'
}
}
dest.write(feature)
dest.close()
Parameters
prefix_strip(bool): Strip XML namespace prefixes (default:True)feature_member(str): Name of feature member element (default:featureMember)encoding(str): File encoding (default:utf8)
Limitations
- lxml dependency: Requires
lxmlpackage for XML parsing - Memory usage: All features are loaded into memory during reading
- GML complexity: Full GML standard is very complex; this is a simplified implementation
- Coordinate systems: Does not handle CRS (Coordinate Reference System) transformations
Compression Support
GML files can be compressed with all supported codecs:
- GZip (
.gml.gz) - BZip2 (
.gml.bz2) - LZMA (
.gml.xz) - LZ4 (
.gml.lz4) - ZIP (
.gml.zip) - Brotli (
.gml.br) - ZStandard (
.gml.zst)
Use Cases
- OGC workflows: Working with OGC-compliant geographic data
- GIS systems: Exchanging data between GIS systems
- Spatial data: Processing spatial data in standard format
- Government data: Many government agencies use GML
Related Formats
- KML - Keyhole Markup Language
- GeoJSON - JSON-based geographic format
- Shapefile - ESRI Shapefile format
- GeoPackage - SQLite-based geospatial format
- XML - Base XML format