Wednesday, October 18, 2017

Domain-Specific Language (Geographic Markup Language - GML)

Hello there,
According to wikipedia: A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains.

There is a wide variety of DSLs, some examples include:-
~ HTML
~ Logo for pencil-like drawing
~ Verilog and VHDL hardware description languages
~ MATLAB and GNU Octave for matrix programming
~ Mathematica, Maple and Maxima for symbolic mathematics
~ Specification and Description Language for reactive and distributed systems
~ spreadsheet formulas and macros
~ SQL for relational database queries
~ YACC grammars for creating parsers
~ regular expressions for specifying lexers
~ the Generic Eclipse Modeling System for creating diagramming languages
~ Csound for sound and music synthesis
~ GML - Geographic Markup Language
~ KML - Keyhole Markup Language




In this post, I will explore more GML - Geographic Markup Language since this blog is mostly about GIS and its related technologies.

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 model
GML contains a rich set of primitives which are used to build application specific schemas or application languages. These primitives include:

  • Feature
  • Geometry
  • Coordinate reference system
  • Topology
  • Time
  • Dynamic feature
  • Coverage (including geographic images)
  • Unit of measure
  • Directions
  • Observations
  • Map presentation styling rules


Coding a GML file - Going from XML to GML
Because GML is derived from XML, we first create an XML code before spicing it up with GML specific attributes.

<?xml version="1.0" encoding="UTF-8"?>
<MyParcelDb>
 <parcel>
  <id>1</id>
  <owner>Hassa Samaila</owner>
  <area>2.95ha</area>
 </parcel>

 <parcel>
  <id>2</id>
  <owner>Umar Tanimu</owner>
  <area>1.53ha</area>
 </parcel>

 <parcel>
  <id>3</id>
  <owner>John Sam</owner>
  <area>2.00ha</area>
 </parcel>

 <parcel>
  <id>4</id>
  <owner>Amina Farhan</owner>
  <area>0.87ha</area>
 </parcel>

</MyParcelDb>

The code above is an XML representing four parcel details. Lets turn it into a GML code by...
1- Saving the code with .gml file extension
2- Reference to the GML schema (xmlns:gml)
3- Add GML ID for each parcel (gml:id)
4- Add the parcel location/position (<position>....</position>)

The updated code will now look like this....

<?xml version="1.0" encoding="UTF-8"?>
<MyParcelDb xmlns:gml="http://opengis.net/gml" >
 <parcel gml:id="GML Parcle 1"> 
  <id>1</id>
  <owner>Hassa Samaila</owner>
  <area>2.95ha</area>
  <position>
   <gml:Polygon srsName="EPSG:3006">
    <gml:outBoundaryls>
     <gml:LinearRing>
      <gml:coord>
       <X>6655200</X>
       <Y>667300</Y>
      </gml:coord>

      <gml:coord>
       <X>6655300</X>
       <Y>667300</Y>
      </gml:coord>

      <gml:coord>
       <X>6655300</X>
       <Y>667400</Y>
      </gml:coord>

      <gml:coord>
       <X>6655200</X>
       <Y>667400</Y>
      </gml:coord>

      <gml:coord>
       <X>6655200</X>
       <Y>667300</Y>
      </gml:coord> 
     </gml:LinearRing>
    </gml:outBoundaryls>
   </gml:Polygon>
  </position>
 </parcel>

 <parcel gml:id="GML Parcle 2">
  <id>2</id>
  <owner>Umar Tanimu</owner>
  <area>1.53ha</area>
  <position>
   <gml:Polygon srsName="EPSG:3006">
    <gml:outBoundaryls>
     <gml:LinearRing>
      <gml:coord>
       <X>6655320</X>
       <Y>667300</Y>
      </gml:coord>

      <gml:coord>
       <X>6655420</X>
       <Y>667300</Y>
      </gml:coord>

      <gml:coord>
       <X>6655420</X>
       <Y>667400</Y>
      </gml:coord>

      <gml:coord>
       <X>6655320</X>
       <Y>667400</Y>
      </gml:coord>

      <gml:coord>
       <X>6655320</X>
       <Y>667300</Y>
      </gml:coord> 
     </gml:LinearRing>
    </gml:outBoundaryls>
   </gml:Polygon>
  </position>
 </parcel>

 <parcel gml:id="GML Parcle 3">
  <id>3</id>
  <owner>John Sam</owner>
  <area>2.00ha</area>
  <position>
   <gml:Polygon srsName="EPSG:32632">
    <gml:outBoundaryls>
     <gml:LinearRing>
      <gml:coord>
       <X>6655440</X>
       <Y>667300</Y>
      </gml:coord>

      <gml:coord>
       <X>6655740</X>
       <Y>667300</Y>
      </gml:coord>

      <gml:coord>
       <X>6655740</X>
       <Y>667400</Y>
      </gml:coord>

      <gml:coord>
       <X>6655440</X>
       <Y>667400</Y>
      </gml:coord>

      <gml:coord>
       <X>6655440</X>
       <Y>667300</Y>
      </gml:coord> 
     </gml:LinearRing>
    </gml:outBoundaryls>
   </gml:Polygon>
  </position>
 </parcel>

 <parcel gml:id="GML Parcle 4">
  <id>4</id>
  <owner>Amina Farhan</owner>
  <area>0.87ha</area>
  <position>
   <gml:Polygon srsName="EPSG:3006">
    <gml:outBoundaryls>
     <gml:LinearRing>
      <gml:coord>
       <X>6655700</X>
       <Y>667300</Y>
      </gml:coord>

      <gml:coord>
       <X>6655800</X>
       <Y>667300</Y>
      </gml:coord>

      <gml:coord>
       <X>6655800</X>
       <Y>667400</Y>
      </gml:coord>

      <gml:coord>
       <X>6655700</X>
       <Y>667400</Y>
      </gml:coord>

      <gml:coord>
       <X>6655700</X>
       <Y>667300</Y>
      </gml:coord> 
     </gml:LinearRing>
    </gml:outBoundaryls>
   </gml:Polygon>
  </position>
 </parcel>

</MyParcelDb>

Thanks for following

No comments:

Post a Comment