R How to convert MultiLineString GeoJson file to dataframe with long and lat columns?How to sort a dataframe by multiple column(s)How to add a GeoJSON layer in GraphHopper?Openlayers: select a feature programmatically from GeoJsonAdding Maplines in HighMaps using geojson fileD3js Map : GeometryCollection Vs FeaturesCollectionTwo geojson files not superposinggeojson file formatting issue, mini-arrays(coordinates) inside larger array of coordinatesgeojson from mysql : convert a postgresql's query with aggregation function json_agg (for web mapping)How to append properties to geojson file in python?loading geojson into Mapbox object not valid

How to have a sharp product image?

How long after the last departure shall the airport stay open for an emergency return?

Philosophical question on logistic regression: why isn't the optimal threshold value trained?

Is it acceptable to use working hours to read general interest books?

Older movie/show about humans on derelict alien warship which refuels by passing through a star

NPN: Not fully sinking to GND

Where was the County of Thurn und Taxis located?

Can I criticise the more senior developers around me for not writing clean code?

Is there a word for the censored part of a video?

Can a stored procedure reference the database in which it is stored?

How do I deal with a coworker that keeps asking to make small superficial changes to a report, and it is seriously triggering my anxiety?

Restricting the options of a lookup field, based on the value of another lookup field?

Is there any pythonic way to find average of specific tuple elements in array?

What is the most expensive material in the world that could be used to create Pun-Pun's lute?

Can a level 2 Warlock take one level in rogue, then continue advancing as a warlock?

"My boss was furious with me and I have been fired" vs. "My boss was furious with me and I was fired"

What does "function" actually mean in music?

What to do with someone that cheated their way through university and a PhD program?

Mistake in years of experience in resume?

Extracting Dirichlet series coefficients

Unknown code in script

Which big number is bigger?

A Paper Record is What I Hamper

What is the unit of time_lock_delta in LND?



R How to convert MultiLineString GeoJson file to dataframe with long and lat columns?


How to sort a dataframe by multiple column(s)How to add a GeoJSON layer in GraphHopper?Openlayers: select a feature programmatically from GeoJsonAdding Maplines in HighMaps using geojson fileD3js Map : GeometryCollection Vs FeaturesCollectionTwo geojson files not superposinggeojson file formatting issue, mini-arrays(coordinates) inside larger array of coordinatesgeojson from mysql : convert a postgresql's query with aggregation function json_agg (for web mapping)How to append properties to geojson file in python?loading geojson into Mapbox object not valid






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








2















I have a MultiLineString Geogeson file exported from gqig gis software.
A small example :




"type": "FeatureCollection",
"name": "route1",
"crs": "type": "name", "properties": "name": "urn:ogc:def:crs:EPSG::3857"
,
"features": [
"type": "Feature", "properties": "FID": 0 , "geometry": "type":
"MultiLineString", "coordinates": [ [ [ 1936131.287994222715497,
-4335318.772792792879045 ], [ -2633407.770391199737787,
1763382.609922708477825 ], [ -2922369.195528693497181,
4600947.908943663351238 ], [ -1640888.092745035886765,
5275789.498084637336433 ], [ -361201.781421858817339, 5970373.793290910311043
], [ -361201.781421858817339, 5970373.793290910311043 ] ] ]

]



How can I convert it in a dataframe binding nodes with long and lat colunms ?
Expected result :



node long lat 
1 1936131.287994222715497 -4335318.772792792879045
2 -2633407.770391199737787 1763382.609922708477825


What I tried (creating a list) :



 route1 <- jsonlite::fromJSON(readr::read_file("routes/route1.geojson"))









share|improve this question
























  • The GeoJSON specification rfc7946 states "GeoJSON uses a geographic coordinate reference system, World Geodetic System 1984, and units of decimal degrees" - so the data you have here is technically not actual valid GeoJSON

    – SymbolixAU
    Mar 12 at 3:44












  • Other CRS values were permitted in previous specifications, but this rule has changed in rfc7946

    – SymbolixAU
    Mar 12 at 3:45

















2















I have a MultiLineString Geogeson file exported from gqig gis software.
A small example :




"type": "FeatureCollection",
"name": "route1",
"crs": "type": "name", "properties": "name": "urn:ogc:def:crs:EPSG::3857"
,
"features": [
"type": "Feature", "properties": "FID": 0 , "geometry": "type":
"MultiLineString", "coordinates": [ [ [ 1936131.287994222715497,
-4335318.772792792879045 ], [ -2633407.770391199737787,
1763382.609922708477825 ], [ -2922369.195528693497181,
4600947.908943663351238 ], [ -1640888.092745035886765,
5275789.498084637336433 ], [ -361201.781421858817339, 5970373.793290910311043
], [ -361201.781421858817339, 5970373.793290910311043 ] ] ]

]



How can I convert it in a dataframe binding nodes with long and lat colunms ?
Expected result :



node long lat 
1 1936131.287994222715497 -4335318.772792792879045
2 -2633407.770391199737787 1763382.609922708477825


What I tried (creating a list) :



 route1 <- jsonlite::fromJSON(readr::read_file("routes/route1.geojson"))









share|improve this question
























  • The GeoJSON specification rfc7946 states "GeoJSON uses a geographic coordinate reference system, World Geodetic System 1984, and units of decimal degrees" - so the data you have here is technically not actual valid GeoJSON

    – SymbolixAU
    Mar 12 at 3:44












  • Other CRS values were permitted in previous specifications, but this rule has changed in rfc7946

    – SymbolixAU
    Mar 12 at 3:45













2












2








2








I have a MultiLineString Geogeson file exported from gqig gis software.
A small example :




"type": "FeatureCollection",
"name": "route1",
"crs": "type": "name", "properties": "name": "urn:ogc:def:crs:EPSG::3857"
,
"features": [
"type": "Feature", "properties": "FID": 0 , "geometry": "type":
"MultiLineString", "coordinates": [ [ [ 1936131.287994222715497,
-4335318.772792792879045 ], [ -2633407.770391199737787,
1763382.609922708477825 ], [ -2922369.195528693497181,
4600947.908943663351238 ], [ -1640888.092745035886765,
5275789.498084637336433 ], [ -361201.781421858817339, 5970373.793290910311043
], [ -361201.781421858817339, 5970373.793290910311043 ] ] ]

]



How can I convert it in a dataframe binding nodes with long and lat colunms ?
Expected result :



node long lat 
1 1936131.287994222715497 -4335318.772792792879045
2 -2633407.770391199737787 1763382.609922708477825


What I tried (creating a list) :



 route1 <- jsonlite::fromJSON(readr::read_file("routes/route1.geojson"))









share|improve this question
















I have a MultiLineString Geogeson file exported from gqig gis software.
A small example :




"type": "FeatureCollection",
"name": "route1",
"crs": "type": "name", "properties": "name": "urn:ogc:def:crs:EPSG::3857"
,
"features": [
"type": "Feature", "properties": "FID": 0 , "geometry": "type":
"MultiLineString", "coordinates": [ [ [ 1936131.287994222715497,
-4335318.772792792879045 ], [ -2633407.770391199737787,
1763382.609922708477825 ], [ -2922369.195528693497181,
4600947.908943663351238 ], [ -1640888.092745035886765,
5275789.498084637336433 ], [ -361201.781421858817339, 5970373.793290910311043
], [ -361201.781421858817339, 5970373.793290910311043 ] ] ]

]



How can I convert it in a dataframe binding nodes with long and lat colunms ?
Expected result :



node long lat 
1 1936131.287994222715497 -4335318.772792792879045
2 -2633407.770391199737787 1763382.609922708477825


What I tried (creating a list) :



 route1 <- jsonlite::fromJSON(readr::read_file("routes/route1.geojson"))






r geojson






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 9 at 7:07







Wilcar

















asked Mar 9 at 6:55









WilcarWilcar

6301931




6301931












  • The GeoJSON specification rfc7946 states "GeoJSON uses a geographic coordinate reference system, World Geodetic System 1984, and units of decimal degrees" - so the data you have here is technically not actual valid GeoJSON

    – SymbolixAU
    Mar 12 at 3:44












  • Other CRS values were permitted in previous specifications, but this rule has changed in rfc7946

    – SymbolixAU
    Mar 12 at 3:45

















  • The GeoJSON specification rfc7946 states "GeoJSON uses a geographic coordinate reference system, World Geodetic System 1984, and units of decimal degrees" - so the data you have here is technically not actual valid GeoJSON

    – SymbolixAU
    Mar 12 at 3:44












  • Other CRS values were permitted in previous specifications, but this rule has changed in rfc7946

    – SymbolixAU
    Mar 12 at 3:45
















The GeoJSON specification rfc7946 states "GeoJSON uses a geographic coordinate reference system, World Geodetic System 1984, and units of decimal degrees" - so the data you have here is technically not actual valid GeoJSON

– SymbolixAU
Mar 12 at 3:44






The GeoJSON specification rfc7946 states "GeoJSON uses a geographic coordinate reference system, World Geodetic System 1984, and units of decimal degrees" - so the data you have here is technically not actual valid GeoJSON

– SymbolixAU
Mar 12 at 3:44














Other CRS values were permitted in previous specifications, but this rule has changed in rfc7946

– SymbolixAU
Mar 12 at 3:45





Other CRS values were permitted in previous specifications, but this rule has changed in rfc7946

– SymbolixAU
Mar 12 at 3:45












2 Answers
2






active

oldest

votes


















2














library(sf) can read GeoJSON. This will give you an sf object. If you want the coordinates you can use the st_coordinates() function.



library(sf)

sf <- sf::st_read( geo, quiet = T )
df <- as.data.frame( sf::st_coordinates( sf ) )

# X Y L1 L2
# 1 1936131.3 -4335319 1 1
# 2 -2633407.8 1763383 1 1
# 3 -2922369.2 4600948 1 1
# 4 -1640888.1 5275789 1 1
# 5 -361201.8 5970374 1 1
# 6 -361201.8 5970374 1 1


This extra L1 and L2 columns tell you to which linestring within the MULTILINESTRING each coordinate pair belong.






share|improve this answer
































    2














    If you examine the structure of the obtained list with str(route1) you can see that the data is stored in an array, which you can extract.



    a <- route1$features$geometry$coordinates[[1]]
    a

    # , , 1
    #
    # [,1] [,2] [,3] [,4] [,5] [,6]
    # [1,] 1936131 -2633408 -2922369 -1640888 -361201.8 -361201.8
    #
    # , , 2
    #
    # [,1] [,2] [,3] [,4] [,5] [,6]
    # [1,] -4335319 1763383 4600948 5275789 5970374 5970374


    Now, just do a cbind() to get what you want.



    cbind(a[, , 1], a[, , 2])
    # [,1] [,2]
    # [1,] 1936131.3 -4335319
    # [2,] -2633407.8 1763383
    # [3,] -2922369.2 4600948
    # [4,] -1640888.1 5275789
    # [5,] -361201.8 5970374
    # [6,] -361201.8 5970374


    Or as data frame:



    d <- data.frame(long=a[, , 1], lat=a[, , 2])
    d <- cbind(node=rownames(d), d)
    d
    # node long lat
    # 1 1 1936131.3 -4335319
    # 2 2 -2633407.8 1763383
    # 3 3 -2922369.2 4600948
    # 4 4 -1640888.1 5275789
    # 5 5 -361201.8 5970374
    # 6 6 -361201.8 5970374





    share|improve this answer

























      Your Answer






      StackExchange.ifUsing("editor", function ()
      StackExchange.using("externalEditor", function ()
      StackExchange.using("snippets", function ()
      StackExchange.snippets.init();
      );
      );
      , "code-snippets");

      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "1"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074839%2fr-how-to-convert-multilinestring-geojson-file-to-dataframe-with-long-and-lat-col%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      2














      library(sf) can read GeoJSON. This will give you an sf object. If you want the coordinates you can use the st_coordinates() function.



      library(sf)

      sf <- sf::st_read( geo, quiet = T )
      df <- as.data.frame( sf::st_coordinates( sf ) )

      # X Y L1 L2
      # 1 1936131.3 -4335319 1 1
      # 2 -2633407.8 1763383 1 1
      # 3 -2922369.2 4600948 1 1
      # 4 -1640888.1 5275789 1 1
      # 5 -361201.8 5970374 1 1
      # 6 -361201.8 5970374 1 1


      This extra L1 and L2 columns tell you to which linestring within the MULTILINESTRING each coordinate pair belong.






      share|improve this answer





























        2














        library(sf) can read GeoJSON. This will give you an sf object. If you want the coordinates you can use the st_coordinates() function.



        library(sf)

        sf <- sf::st_read( geo, quiet = T )
        df <- as.data.frame( sf::st_coordinates( sf ) )

        # X Y L1 L2
        # 1 1936131.3 -4335319 1 1
        # 2 -2633407.8 1763383 1 1
        # 3 -2922369.2 4600948 1 1
        # 4 -1640888.1 5275789 1 1
        # 5 -361201.8 5970374 1 1
        # 6 -361201.8 5970374 1 1


        This extra L1 and L2 columns tell you to which linestring within the MULTILINESTRING each coordinate pair belong.






        share|improve this answer



























          2












          2








          2







          library(sf) can read GeoJSON. This will give you an sf object. If you want the coordinates you can use the st_coordinates() function.



          library(sf)

          sf <- sf::st_read( geo, quiet = T )
          df <- as.data.frame( sf::st_coordinates( sf ) )

          # X Y L1 L2
          # 1 1936131.3 -4335319 1 1
          # 2 -2633407.8 1763383 1 1
          # 3 -2922369.2 4600948 1 1
          # 4 -1640888.1 5275789 1 1
          # 5 -361201.8 5970374 1 1
          # 6 -361201.8 5970374 1 1


          This extra L1 and L2 columns tell you to which linestring within the MULTILINESTRING each coordinate pair belong.






          share|improve this answer















          library(sf) can read GeoJSON. This will give you an sf object. If you want the coordinates you can use the st_coordinates() function.



          library(sf)

          sf <- sf::st_read( geo, quiet = T )
          df <- as.data.frame( sf::st_coordinates( sf ) )

          # X Y L1 L2
          # 1 1936131.3 -4335319 1 1
          # 2 -2633407.8 1763383 1 1
          # 3 -2922369.2 4600948 1 1
          # 4 -1640888.1 5275789 1 1
          # 5 -361201.8 5970374 1 1
          # 6 -361201.8 5970374 1 1


          This extra L1 and L2 columns tell you to which linestring within the MULTILINESTRING each coordinate pair belong.







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Mar 12 at 3:45

























          answered Mar 11 at 20:52









          SymbolixAUSymbolixAU

          17k33292




          17k33292























              2














              If you examine the structure of the obtained list with str(route1) you can see that the data is stored in an array, which you can extract.



              a <- route1$features$geometry$coordinates[[1]]
              a

              # , , 1
              #
              # [,1] [,2] [,3] [,4] [,5] [,6]
              # [1,] 1936131 -2633408 -2922369 -1640888 -361201.8 -361201.8
              #
              # , , 2
              #
              # [,1] [,2] [,3] [,4] [,5] [,6]
              # [1,] -4335319 1763383 4600948 5275789 5970374 5970374


              Now, just do a cbind() to get what you want.



              cbind(a[, , 1], a[, , 2])
              # [,1] [,2]
              # [1,] 1936131.3 -4335319
              # [2,] -2633407.8 1763383
              # [3,] -2922369.2 4600948
              # [4,] -1640888.1 5275789
              # [5,] -361201.8 5970374
              # [6,] -361201.8 5970374


              Or as data frame:



              d <- data.frame(long=a[, , 1], lat=a[, , 2])
              d <- cbind(node=rownames(d), d)
              d
              # node long lat
              # 1 1 1936131.3 -4335319
              # 2 2 -2633407.8 1763383
              # 3 3 -2922369.2 4600948
              # 4 4 -1640888.1 5275789
              # 5 5 -361201.8 5970374
              # 6 6 -361201.8 5970374





              share|improve this answer





























                2














                If you examine the structure of the obtained list with str(route1) you can see that the data is stored in an array, which you can extract.



                a <- route1$features$geometry$coordinates[[1]]
                a

                # , , 1
                #
                # [,1] [,2] [,3] [,4] [,5] [,6]
                # [1,] 1936131 -2633408 -2922369 -1640888 -361201.8 -361201.8
                #
                # , , 2
                #
                # [,1] [,2] [,3] [,4] [,5] [,6]
                # [1,] -4335319 1763383 4600948 5275789 5970374 5970374


                Now, just do a cbind() to get what you want.



                cbind(a[, , 1], a[, , 2])
                # [,1] [,2]
                # [1,] 1936131.3 -4335319
                # [2,] -2633407.8 1763383
                # [3,] -2922369.2 4600948
                # [4,] -1640888.1 5275789
                # [5,] -361201.8 5970374
                # [6,] -361201.8 5970374


                Or as data frame:



                d <- data.frame(long=a[, , 1], lat=a[, , 2])
                d <- cbind(node=rownames(d), d)
                d
                # node long lat
                # 1 1 1936131.3 -4335319
                # 2 2 -2633407.8 1763383
                # 3 3 -2922369.2 4600948
                # 4 4 -1640888.1 5275789
                # 5 5 -361201.8 5970374
                # 6 6 -361201.8 5970374





                share|improve this answer



























                  2












                  2








                  2







                  If you examine the structure of the obtained list with str(route1) you can see that the data is stored in an array, which you can extract.



                  a <- route1$features$geometry$coordinates[[1]]
                  a

                  # , , 1
                  #
                  # [,1] [,2] [,3] [,4] [,5] [,6]
                  # [1,] 1936131 -2633408 -2922369 -1640888 -361201.8 -361201.8
                  #
                  # , , 2
                  #
                  # [,1] [,2] [,3] [,4] [,5] [,6]
                  # [1,] -4335319 1763383 4600948 5275789 5970374 5970374


                  Now, just do a cbind() to get what you want.



                  cbind(a[, , 1], a[, , 2])
                  # [,1] [,2]
                  # [1,] 1936131.3 -4335319
                  # [2,] -2633407.8 1763383
                  # [3,] -2922369.2 4600948
                  # [4,] -1640888.1 5275789
                  # [5,] -361201.8 5970374
                  # [6,] -361201.8 5970374


                  Or as data frame:



                  d <- data.frame(long=a[, , 1], lat=a[, , 2])
                  d <- cbind(node=rownames(d), d)
                  d
                  # node long lat
                  # 1 1 1936131.3 -4335319
                  # 2 2 -2633407.8 1763383
                  # 3 3 -2922369.2 4600948
                  # 4 4 -1640888.1 5275789
                  # 5 5 -361201.8 5970374
                  # 6 6 -361201.8 5970374





                  share|improve this answer















                  If you examine the structure of the obtained list with str(route1) you can see that the data is stored in an array, which you can extract.



                  a <- route1$features$geometry$coordinates[[1]]
                  a

                  # , , 1
                  #
                  # [,1] [,2] [,3] [,4] [,5] [,6]
                  # [1,] 1936131 -2633408 -2922369 -1640888 -361201.8 -361201.8
                  #
                  # , , 2
                  #
                  # [,1] [,2] [,3] [,4] [,5] [,6]
                  # [1,] -4335319 1763383 4600948 5275789 5970374 5970374


                  Now, just do a cbind() to get what you want.



                  cbind(a[, , 1], a[, , 2])
                  # [,1] [,2]
                  # [1,] 1936131.3 -4335319
                  # [2,] -2633407.8 1763383
                  # [3,] -2922369.2 4600948
                  # [4,] -1640888.1 5275789
                  # [5,] -361201.8 5970374
                  # [6,] -361201.8 5970374


                  Or as data frame:



                  d <- data.frame(long=a[, , 1], lat=a[, , 2])
                  d <- cbind(node=rownames(d), d)
                  d
                  # node long lat
                  # 1 1 1936131.3 -4335319
                  # 2 2 -2633407.8 1763383
                  # 3 3 -2922369.2 4600948
                  # 4 4 -1640888.1 5275789
                  # 5 5 -361201.8 5970374
                  # 6 6 -361201.8 5970374






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 9 at 8:42

























                  answered Mar 9 at 8:37









                  jay.sfjay.sf

                  7,38831842




                  7,38831842



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55074839%2fr-how-to-convert-multilinestring-geojson-file-to-dataframe-with-long-and-lat-col%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      AWS Lex not identifying response if by a variable The 2019 Stack Overflow Developer Survey Results Are In Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 17/18, 2019 at 00:00UTC (8:00pm US/Eastern) The Ask Question Wizard is Live! Data science time! April 2019 and salary with experienceEnforcing custom enumeration in AWS LEX for slot valuesHow to give response based on user response in Amazon Lex?Intercepting AWS Lambda Response to a AWS Lex QueryLex chat bot error: Reached second execution of fulfillment lambda on the same utteranceamazon lex showing invalid responseLambda response send back to Lex slot?Response card in Amazon lexAmazon Lex - Lambda response return HTML to botHow can I solve 424 (Failed Dependency) (python) obtained from Amazon lex?

                      Алба-Юлія

                      Захаров Федір Захарович