We are working on updating this book for the latest version. Some content might be out of date.
Shapes are represented using GeoJSON, a simple open
standard for encoding two-dimensional shapes in JSON.
Each shape definition
contains the type of shape—point, line, polygon, envelope,—and one or more arrays of longitude/latitude points.
For instance, we can index a polygon representing Dam Square in Amsterdam as follows:
PUT /attractions/landmark/dam_square
{
"name" : "Dam Square, Amsterdam",
"location" : {
"type" : "polygon",
"coordinates" : [[
[ 4.89218, 52.37356 ],
[ 4.89205, 52.37276 ],
[ 4.89301, 52.37274 ],
[ 4.89392, 52.37250 ],
[ 4.89431, 52.37287 ],
[ 4.89331, 52.37346 ],
[ 4.89305, 52.37326 ],
[ 4.89218, 52.37356 ]
]]
}
}
The | |
The list of |
The excess of square brackets in the example may look confusing, but the GeoJSON syntax is quite simple:
Each
lon/latpoint is represented as an array:[lon,lat]
A list of points is wrapped in an array to represent a polygon:
[[lon,lat],[lon,lat], ... ]
A shape of type
polygoncan optionally contain several polygons; the first represents the polygon proper, while any subsequent polygons represent holes in the first:[ [[lon,lat],[lon,lat], ... ], # main polygon [[lon,lat],[lon,lat], ... ], # hole in main polygon ... ]
See the Geo-shape mapping documentation for more details about the supported shapes.