Search code examples
geojsoncesiumjsturfjs

Change map projection in Cesium.js to match results from turf.js inside query


I am displaying a point and a polygon in Cesium.js, and using turf.js to check is the point inside the polygon.

When displayed in Cesium (or geojson.io), the point is clearly outside the polygon, as can be seen here:

http://geojson.io/#id=gist:kujosHeist/1030e392bd751daf5d9af57aa412a49c&map=3/46.80/-22.76

However, when I queried this on the turf.js issiues page:

https://github.com/Turfjs/turf-inside/issues/15

I was told it was because geojson, (and therefore Cesium) is "misrepresenting the point since it uses World Web Mercator projection (EPSG:3857)" and that "viewing the same point/polygon using WGS84 with QGIS" ...shows the point is inside the polygon.

So my question is: How can I change the map projection used in Cesium (and also in geojson.io if possible), so that the point is correctly displayed inside the polygon?


Solution

  • I am not sure how well geojson.io or Cesium will handle different coordinate systems, but you can specify a CRS element in your GeoJSON that indicates the coordinate system used by points of your features. This is added as a member under your feature collection. For example:

    {
        {
        "type": "FeatureCollection",
        "crs": {
        "type": "name",
        "properties": {
          "name": "urn:ogc:def:crs:OGC:1.3:CRS84"
        },
        ...the rest of your structure...
    }
    

    But like I said, it's up to the map display software to pay attention to your specified CRS and use it to project coords. If it doesn't support the coordinate system you have, then you'll need to pick some other map display software or convert the coords to a supported coordinate system.