3

GeoJson file coordinates are in [X, Y] meters not in [lng, lat]. How to display it on google map?

GeoJson data

{
  "type": "FeatureCollection",
  "features": [
    {
      "type": "Feature",
      "geometry": {
        "type": "MultiPolygon",
        "coordinates": [
          [
            [
              [
                360590,
                555610
              ],
              [
                360590,
                555555.0128
              ],
              [
                360590,
                555540
              ],
              [
                360592.4439,
                555540
              ],
              [
                360600,
                555540
              ],
              [
                360600,
                555518.8277
              ]
            ]
          ]
        ]
      }
    }
  ]
}

here, [360590, 555610] - [X, Y] coordinates is in meters, Now we need to display this coordinates on google map, Is there any solution for this?

also we must have to use addGeoJson or loadGeoJson method because we have 200MB data in GeoJson file.

5
  • 1
    Sounds like the data is in a different projection (perhaps EPSG:3857). If that is true you need to reproject the points into EPSG:4326 (if it isn't true, you still need to get the equivalent WGS84/ESPG:4326 points).
    – geocodezip
    Commented Dec 26, 2019 at 14:00
  • yes @geocodezip may be that happens, but i need code snippet to resolve this issue, i found many solutions but neither was worked for me.
    – Niravdas
    Commented Dec 27, 2019 at 8:10
  • After long Research I found that I am getting points in EPSG:27700. now need java code to transform individual points in WGS84/ESPG:4326 points.
    – Niravdas
    Commented Jan 1, 2020 at 13:07
  • i found solution on ageeksnotes.blogspot.com/2010/09/… but it's not working.
    – Niravdas
    Commented Jan 1, 2020 at 13:20

1 Answer 1

0

Converting in the backend would be better but there's a JS way too -- using proj4js and epsg.io to find the corresponding datums.

Important point: the first and last positions of the linear ring need to be identical. Otherwise your GeoJSON is not valid. So notice how my points array starts and ends w/ the same point.


After installing / importing proj4js:

// from https://epsg.io/27700
const EPSG_27700_DATUM = "+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 +x_0=400000 +y_0=-100000 +ellps=airy +towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 +units=m +no_defs";

// from https://epsg.io/4326
const WGS84_DATUM = "+proj=longlat +datum=WGS84 +no_defs";

const points = [[360590,555610],[360590,555555.0128],[360590,555540],[360592.4439,555540],[360600,555540],[360600,555518.8277],[360590,555610]];

const converted_points = points.map(([lon, lat]) => {
    return proj4(EPSG_27700_DATUM, WGS84_DATUM, [lon, lat]);
});

console.info({ converted_points });

Validating that your polygon is indeed inside of GB:

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.