About existing packages
Dealing with geospatial data is not a new topic for Pharo community. Contributors have already worked on parsing geospatial data files, and building classes to represent and vizualise them.
Let's detail here Pharo existing packages relative to our topic, which could be useful for our project.
GeoJSON & KML parsers
GeoJSON parser
GeoJSON provides a conversion from a GeoJSON file into its own geospatial data object model.
We can test it with a sample found on GitHub (here). The given GeoJSON file describes a Point, a LineString of 4 points and a Polygon (a square).
Note: coordinate reference system used by GeoJSON is the World Geodic System (WGS84). The associate map projection called Web Mercator projection, is a variant of Mercator projection and became a well-known standard for Web mapping applications. Google Maps actually uses it.
More details about GeoJSON in specification: https://datatracker.ietf.org/doc/html/rfc7946#section-3.1.1
To parse our file, GeoJSON class implements the fromString: method which returns the associate objects of GeoJSON Pharo model.
Launch conversion in Pharo executing the following example code in playground:
This execution returns a Feature Collection object, with given features:
Adapting this GeoJSON parser to return objects based on OGC-Pharo model we're working on in this GSoC context could be interesting to provide a complete service.
KML parser
KML provides a conversion from a KML file into our OGC-Pharo model.
We convert our GeoJSON sample into KML format gives the following file (using online converter):
<?xml version="1.0" encoding="utf-8" ?>
<kml xmlns="http://www.opengis.net/kml/2.2">
<Document id="root_doc">
<Schema name="sample.json" id="sample.json">
<SimpleField name="prop0" type="string"></SimpleField>
<SimpleField name="prop1" type="string"></SimpleField>
</Schema>
<Folder><name>sample.json</name>
<Placemark>
<ExtendedData><SchemaData schemaUrl="#sample.json">
<SimpleData name="prop0">value0</SimpleData>
</SchemaData></ExtendedData>
<Point><coordinates>102.0,0.5</coordinates></Point>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#sample.json">
<SimpleData name="prop0">value0</SimpleData>
<SimpleData name="prop1">0.000000</SimpleData>
</SchemaData></ExtendedData>
<LineString><coordinates>102,0 103,1 104,0 105,1</coordinates></LineString>
</Placemark>
<Placemark>
<Style><LineStyle><color>ff0000ff</color></LineStyle><PolyStyle><fill>0</fill></PolyStyle></Style>
<ExtendedData><SchemaData schemaUrl="#sample.json">
<SimpleData name="prop0">value0</SimpleData>
<SimpleData name="prop1">{ "this": "that" }</SimpleData>
</SchemaData></ExtendedData>
<Polygon><outerBoundaryIs><LinearRing><coordinates>100,0 101,0 101,1 100,1 100,0</coordinates></LinearRing></outerBoundaryIs></Polygon>
</Placemark>
</Folder>
</Document></kml>
After recording this file as a string in a kmlString variable, we can parse it with KMLReader class and obtain a KMLDocument:
This resulting KMLDocument has a KMLFolder which contains a collection of features with a OGCPoint, a OGCLineString and a KMLPolygon.
Geometry
GitHub source: pharo-contributions/Geometry (forked from TelescopeSt)
Geometry provides a model to represent geometric elements. This package also enable elementary computations.
We can project our GIS features to this geometric model, espacially:
GPoint for our OGCPoint
GSegment for our OGCLine
GPolygon for our OGCPolygon - which also includes GTriangle for our OGCTriangle.
Let's keep in mind that this geometric model can be used if we work witha planar projection, like Mercator projection for instance.
In this case, interesting methods to perform GIS computations are:
distanceTo
intersectionWithSegment, intersectionWithPoint
area
includes