Use The Power of Open Source Web GIS #3 GeoJSON : Geographic Data Structure Used Everywhere

Yunus Emre Özkaya
3 min readApr 4, 2023

--

The primary purpose of map applications is, of course, to perform operations on geographical data. It is necessary to use standard data structures for this data to be understandable and shareable between systems. At this point, GeoJSON, supported by almost all map-based software, comes to the fore.

Although there are different data structures in which we can use geospatial data, GeoJSON would be a good starting point as it is common.

GeoJSON is a very rich data structure. I will only touch on the basic geometry types of points, lines, and polygons here. You can find the full spec of GeoJSON at https://geojson.org.

Feature

Features are elements that contain geometry. Features contain type, geometry, and properties members.

  • For features, the “type” member is “Feature”.
  • The “geometry” member has two members of its own. These are “type” and “coordinates”. “type” holds the type of the geometry (Point, LineString, Polygon, MultiPoint, MultiLineString, MultiPolygon), while “coordinates” holds the coordinate information of the geometry. The coordinates are in x, y order.
  • “properties” member holds the attributes of the object as key values.

Below is an example of a point feature and its general structure is as follows. There is only one coordinate because there is point geometry here.

{
"type" : "Feature",
"geometry" : {
"type" : "Point",
"coordinates" : [35, 39]
},
"properties": {
"name" : "City center"
}
}

Below is an example of a line feature and its general structure is as follows. Since there is line geometry here, there are multiple coordinates. Line geometries must contain at least two coordinates.

{
"type" : "Feature",
"geometry" : {
"type" : "LineString",
"coordinates" : [
[35, 39],
[36, 40],
[37, 38],
[38, 39]
]
},
"properties": {
"name" : "Kızılırmak",
"status" : "River"
}
}

Below is an example of a polygon feature and its general structure is as follows. Since there is polygon geometry here, there are multiple coordinates. The difference between polygon geometries and line geometries is that the first and last coordinates of polygon geometries are the same because it represents a closed area.

{
"type" : "Feature",
"geometry" : {
"type" : "Polygon",
"coordinates" : [
[
[35, 39],
[37, 38],
[36, 40],
[35, 39]

]
]
},
"properties": {
"name" : "Ankara"
}
}

Feature Collection

Feature collections are elements that contain a feature list. We use Feature collections to hold multiple features. They contain type and features members.

  • For feature collections, the “type” member is “FeatureCollection”.
  • The “features” element holds an array of features.

Below is an example of a feature collection and its general structure is as follows.

{
"type": "FeatureCollection",
"features": [{
"type": "Feature",
"geometry": {
"type": "Point",
"coordinates" : [34, 39]
},
"properties": {
"name" : "City center"
}
}, {
"type" : "Feature",
"geometry" : {
"type" : "LineString",
"coordinates" : [
[37, 39],[37, 40],[38, 38],[39, 39]
]
},
"properties": {
"name" : "Kızılırmak",
"status" : "River"
}
}, {
"type" : "Feature",
"geometry" : {
"type" : "Polygon",
"coordinates" : [
[
[35, 39],[37, 38],[36, 40],[35, 39]

]
]
},
"properties": {
"name" : "Ankara"
}
}]
}

You can test all these geojson objects and your own geojson objects on https://geojson.io

I tried to talk briefly about GeoJSON in this story because we will use GeoJSON in the following stories.

Always be scout. Leave the code more clean than you found.

--

--

Yunus Emre Özkaya

Developer of related software on gis and stock markets. Runner, trail runner.