[GeoJSON] GeoJSON in OpenLayers

Sean Gillies sgillies at frii.com
Mon Mar 26 07:53:41 PDT 2007

Tim Schaub wrote:
> Hello-
> I've put together a GeoJSON reader/writer for OpenLayers.  You can 
> digitize some features and see the resulting GeoJSON (my own flavor) in 
> this example:
> http://dev.openlayers.org/sandbox/tschaub/geojson/examples/geojson.html
> I'm not going to do anything with the reader until there is some 
> agreement on the data structure.  Also, I think this is understood, but 
> I would suggest that any service that accepts something like 
> outputformat=json also takes a callback=somestring - where the result is 
>   mime-type text/javascript and looks something like "somestring(json);" 
> (allowing the somestring to be anything, including "NameSpace.property = 
> " or "myFunction").
> If you digitize some points, lines, and polygons, I think the data 
> structure I've got in mind should be obvious.  It looks something like:
> {
>      "features": array,
>      "crs": string
> }
> The features array is an array of features where each feature looks 
> something like:
> {
>      "id": string,
>      "type": string,
>      "attributes: object,
>      "data": array
> }

> The id string is any string. The type string is one of "point", 
> "multipoint", "linestring", "multilinestring", "polygon", or 
> "multipolygon" (and I'm entirely open to CamelCase).  The attributes 
> object is any object and the data array depends on the type.
> For type point, the data array is an array of coordinates like:
> [number, number]
> For type multipoint, the data array is an array of points as described 
> above.
> For type linestring, the data array is an array of points as described 
> above.
> For type multilinestring, the data array is an array of linestrings as 
> described above.
> For type polygon, the data array is an array of linestrings as described 
> above - and the client assumes that those linestrings will be linear 
> rings.  The first item in the array is the exterior ring and any 
> subsequent items are interior rings.
> For type multipolygon, the data array is an array of polygons as 
> described above.
> Finally, all features in the array have the same coordinate reference 
> system, represented by the crs string.
> Though I haven't read too carefully, I think this captures the 
> alternatives discussed here.  Sean's Pleiades GeoJSON would use the 
> attributes object for things like title, classname, and center.  Same 
> with things like AREA, PERIMETER, and DESCRIPTION from Chris.
> I'm happy to add this to the wiki somewhere if it looks sensible.  Or, 
> if it looks like gibberish, let me know.
> Tim
> Related links -
> The GeoJSON reader/writer
> http://dev.openlayers.org/sandbox/tschaub/geojson/lib/OpenLayers/Format/GeoJSON.js
> Which requires
> http://dev.openlayers.org/sandbox/tschaub/geojson/lib/OpenLayers/Format/JSON.js
> And if you want to make your own GeoJSON enabled OpenLayers application, 
> point it to
> http://dev.openlayers.org/sandbox/tschaub/geojson/lib/OpenLayers.js


I prefer "properties" (GML terminology) to "attributes" to avoid 
confusion with Javascript or HTML terms. I also have a preference for an 
explicit "geometry" attribute containing type and data. My $0.02.

I'm looking forward to trying out the new OpenLayers code soon.


Sean Gillies

More information about the GeoJSON mailing list