This project also implements a GML serializer which can output JTS geometries as GML.
The Geography Markup Language (GML) is the XML grammar defined by the Open Geospatial Consortium (OGC) to express geographical features. GML serves as a modeling language for geographic systems as well as an open interchange format for geographic transactions on the Internet.
GML is widely used in GIS applications as an exchange format for geographical objects (features). Among other things, GML can also describe geometries of these features. Here's an example of a polygon definition:
The JTS Topology Suite (JTS) is an open source Java software library that provides an object model for Euclidean planar linear geometry together with a set of fundamental geometric function.
When developing GIS applications you often need to work with geometries: perform operations (ex. build an intersection of two geometries), evaluate predicates (ex. check if two geometries are disjoint), store geometries in a database and so on.
JTS is a popular Java library which provides API for working with geometries. It is used in many GIS products and libraries.
One of the most common tasks when working with GML and JTS is reading JTS geometries from GML - and vice verse - exporting JTS geometries as GML. This project provides a lightweight implementation of GML-JTS converter for GML 3.1.1.
|GML 3.1.1 is backwards-compatible with older GML 3.x and GML 2.x specifications. It is not directly compatible with GML 3.2 due to the update of the namespace URI in GML 3.2.|
|GML Element||GML Type||JTS Type|
GML-JTS is distributed via the central Maven repository.
|Check this link for information on GML-JTS Maven artifact.|
In order to use GML-JTS
If you're not using Maven, you'll need to add GML-JTS JAR (ogc-tools-gml-jts-version.jar) as well as a number of dependencies to your project on your own.
- OGC Tools GML-JTS (ogc-gml-v_3_1_1-schema-1.0.2.jar)
- GML 3.1.1 Schema (gml-v_3_1_1-schema-1.0.2.jar)
- JTS (jts-1.11.jar)
- JAXB2-Basics (jaxb2-basics-runtime-0.6.0.jar)
- Commons Lang (commons-lang-2.4.jar)
- JAXB dependencies (typically shipped with JRE):
GML-JTS provides a custom JAXB context implementation which can be used to unmarshal JTS geometries from XML in GML format or to marshal JTS geometries as GML.
- Create a JAXB context for the org.jvnet.ogc.gml.v_3_1_1.jts context path;
- Create an instance of unmarshaller for parsing/unmarshalling;
- Create an instance of marshaller for serializing/marshalling.
Here's a simple code snippet which converts GML to WKT:
When unmarshalling GML, GML-JTS tries to parse srsName as EPSG code using the following patterns:
If srsName matched one of the pattern, it will be parsed as assigned to the SRID property of the JTS geometry.
If none of the patterns matched, srsName will be simply saved to the UserData property of the JTS geometry.
Both geometries will have SRID set to 4326:
If UserData property of the JTS geometry is a string, it will be marshalled as srsName of the GML geometry.
Otherwise, if JTS geometry has a SRID set (geometry.getSRID() != 0), it will be formatted using the following pattern:
The result will be serialized as the srsName attribute of the geometry.