none
Plot Geojson file issue RRS feed

  • Question

  • Hi,

    We have requirement to plot the Geojson file on map. We have used 'Microsoft.Maps.GeoJson' to plot the GeoJson file on map. We are able to plot the some of the file but for some of the file it throws error.

      //load GeoJson

                Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {

                });

      var shapes = Microsoft.Maps.GeoJson.read(geoJSONFormat);

    We have getting two different error.

     1.  When we tried to plot one of the GeoJson file then we got following error “maximum call stack size exceeded” . This file is too big around 175900 shape.

     2.  When we tried to plot another GeoJson file then we got “not valid latitude“ error. Here is screenshot of GeoJson file. One point we noticed that geometry type is “MultiLineString”. Is anyone have face same issue and have solution for it.


    Balasaheb

    Friday, August 24, 2018 1:18 PM

Answers

  • As you stated in first post you received invalid latitude error message and looking at your GeoJSON coordinates they indeed does not seem right, for example: [328693.41096469155, 113417.21047145149]. Not sure why you have those numbers but Latitudes should be in rage -90 to 90 and Longitudes range from -180 to 180. Try changing that to correct values.

    Thursday, August 30, 2018 1:15 PM
    Moderator

All replies

  • Hi Balasaheb,

    According to https://msdn.microsoft.com/en-us/library/mt712806.aspx multiline string is supported so this would indicate you have a data issue. Are you able to step through the file to find the data that is causing the issue?  Maybe add a check within the parsing code?

    Sincerely,

    IoTGirl

    Friday, August 24, 2018 5:26 PM
    Owner
  • Hi,

    Thanks for your reply.

    We tried many thing but facing same issue.

    When we tried with bing map SDK code. In that code also throwing same issue.

    Below is the sample code that we are using. Can you please and let us know where we did wrong.

    <!DOCTYPE html>
    <html>
    <head>
        <title></title>
        <meta charset="utf-8" />
        <script type='text/javascript' src='http://www.bing.com/mapspreview/MapControl'></script>
        <script type='text/javascript'>
    function GetMap() {
        Microsoft.Maps.loadMap({
            element: '#myMap',
            mapOptions: {
                credentials: 'My bing map key',
                mapType: Microsoft.Maps.MapTypeId.aerial,
                center: new Microsoft.Maps.Location(47.642, -122.128),
                zoom: 18
            }
        },
        function (map) {
            //var myGeoJson = {
            //    "type": "Polygon",
            //    "coordinates": [[
            //            [-122.12901, 47.64178],
            //            [-122.12901, 47.64226],
            //            [-122.12771, 47.64226],
            //            [-122.12771, 47.64178],
            //            [-122.12901, 47.64178]
            //    ]]
            //};

            var myGeoJson = {
                "type": "FeatureCollection",
                "crs": { "type": "name", "properties": { "name": "urn:ogc:def:crs:EPSG::27700" } },
                                                                                    
                "features": [
                {
                    "type": "Feature", "properties": { "PRIMARY": "Combe St Nicholas Church of England VA Primary School", "MIDDLE": null, "SECONDARY": "Holyrood Academy" },
                    "geometry": {
                        "type": "MultiPolygon",
                        "coordinates": [[[[328693.41096469155, 113417.21047145149], [328692.21542969084, 113423.80872353102], [328688.90913718776, 113436.50536370301],
                            [328686.81487161433, 113443.01364288793], [328683.21173039795, 113450.01179738334], [328679.01493285957, 113457.10992744938],
                            [328674.0101001162, 113463.50824624434], [328658.21229633561, 113480.31383993782], [328642.61241274956, 113506.80686038412],
                            [328633.70760977088, 113520.01338517532], [328621.90879159898, 113550.31538053675], [328616.21141908661, 113573.40926822548],
                            [328611.90749862464, 113598.7125642132], [328610.90986062161, 113608.50996603593], [328609.71436461678, 113626.01532168454],
                            [328609.60722771793, 113640.3115256468], [328611.0089832613, 113658.81660652629], [328608.70863046753, 113677.51165020067],
                            [328594.91451559559, 113721.6199863661]]]]
                    }
                }
                ]
            }

            //Load the GeoJson Module.
            Microsoft.Maps.loadModule('Microsoft.Maps.GeoJson', function () {

                //Parse the GeoJson object into a Bing Maps shape.
                try {
                    var shape = Microsoft.Maps.GeoJson.read(myGeoJson, {
                        polygonOptions: {
                            fillColor: 'rgba(255,0,0,0.5)',
                            strokeColor: 'white',
                            strokeThickness: 5
                        }
                    });

                    //Add the shape to the map.
                    map.entities.push(shape);
                } catch (e) {
                    alert(e.message);
                }
            });
        });
    }
        </script>
    </head>
    <body onload='GetMap();'>
        <div id="myMap" style=";width:600px;height:400px;"></div>
    </body>
    </html>

    Thanks!


    Balasaheb

    Thursday, August 30, 2018 8:50 AM
  • As you stated in first post you received invalid latitude error message and looking at your GeoJSON coordinates they indeed does not seem right, for example: [328693.41096469155, 113417.21047145149]. Not sure why you have those numbers but Latitudes should be in rage -90 to 90 and Longitudes range from -180 to 180. Try changing that to correct values.

    Thursday, August 30, 2018 1:15 PM
    Moderator
  • Hi,

    Thanks for your reply. We thought the same but the file we have downloaded from below link https://data.gov.uk/search? and we do not have idea why this file have  such format [328693.41096469155, 113417.21047145149]

    Is there any way to plot such file.

    Thanks!

     


    Balasaheb

    Friday, August 31, 2018 9:18 AM
  • Hi Balasheb,

    You have answered your own question. The file is created by "gov.UK" so you should be asking them about the contents.

    Sincerely,

    IoTGirl

    Friday, August 31, 2018 4:13 PM
    Owner
  • It appear to be a Northing/Easting Coordinates....  May want to start with the British National Grid and work from there to determine what Coordinate projection is being used .... Coordinate converter

    Tuesday, September 4, 2018 4:03 PM