When I look up the specs of GeoJson I see that circles are supported:
http://geopriv.dreamhosters.com/geojson/geojson-spec.html#circleExample
When I try out the code in geojsonlint (http://geojsonlint.com/) however, it gives me an error.
Input:
{
"type": "Circle",
"coordinates": [4.884, 52.353],
"radius": 200
}
Gives:
"Circle" is not a valid GeoJSON type.
I want to show different places of interests with a range of influence on a map by using d3. It needs GeoJson for input but it is true that circles are not supported with GeoJson?
GeoJSON doesn't have a circle geometry type, or any kind of curve.
CRS (Coordinate Reference System) See https://tools.ietf.org/html/rfc7946#page-12 for further information. The coordinate reference system for all GeoJSON coordinates is a geographic coordinate reference system, using the World Geodetic System 1984 (WGS84) datum, with longitude and latitude units of decimal degrees.
GeoJSON is an open standard geospatial data interchange format that represents simple geographic features and their nonspatial attributes.
Introduction GeoJSON is a format for encoding a variety of geographic data structures using JavaScript Object Notation (JSON) [RFC7159]. A GeoJSON object may represent a region of space (a Geometry), a spatially bounded entity (a Feature), or a list of Features (a FeatureCollection).
When I look up the specs of GeoJson I see that circles are supported
They aren't. Seems you managed to find some fake or incorrect specs. Go to geojson.org to find the specs, there's nothing about circles.
As the accepted answer explains, circles are not supported in the GeoJson spec.
Most map implementations will, however, let you create circles, but in case this doesn't work for you (eg. you need to store it in a database and query it), the solution is to create a polygon that roughly approximates a circle (imagine a polygon with 32+ edges).
I wrote a module that does this. You can use it like this:
const circleToPolygon = require('circle-to-polygon');
const coordinates = [-27.4575887, -58.99029]; //[lon, lat]
const radius = 100; // in meters
const numberOfEdges = 32; //optional that defaults to 32
let polygon = circleToPolygon(coordinates, radius, numberOfEdges);
To clarify why circles are not supported, it has to do with the curvature of the earth. Because the earth is not a perfect sphere, if you were to draw a circular shape on it, it wouldn't be a perfect circle either. However, the solution above works for most scenarios in which you don't require critical precision.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With