Single row Points to LinestringHow to merge two dictionaries in a single expression?Limiting floats to two decimal pointsErrors when connecting to router with python codeHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasLabel encoding across multiple columns in scikit-learnpandas DataFrame.replace function broken for datetimeError importing jpype moduleShapely : tuples without commas with LineStringPython 37 - shapely - error in polygon creation

When handwriting 黄 (huáng; yellow) is it incorrect to have a disconnected 草 (cǎo; grass) radical on top?

How to prevent "they're falling in love" trope

How to remove border from elements in the last row?

What is the opposite of "eschatology"?

Placement of More Information/Help Icon button for Radio Buttons

In Bayesian inference, why are some terms dropped from the posterior predictive?

Sums of two squares in arithmetic progressions

Avoiding the "not like other girls" trope?

What is a Samsaran Word™?

What historical events would have to change in order to make 19th century "steampunk" technology possible?

How can saying a song's name be a copyright violation?

Is it "common practice in Fourier transform spectroscopy to multiply the measured interferogram by an apodizing function"? If so, why?

How can I prove that a state of equilibrium is unstable?

How could indestructible materials be used in power generation?

how do we prove that a sum of two periods is still a period?

My ex-girlfriend uses my Apple ID to login to her iPad, do I have to give her my Apple ID password to reset it?

Could the museum Saturn V's be refitted for one more flight?

How could sorcerers who are able to produce/manipulate almost all forms of energy communicate over large distances?

Why didn't Boeing produce its own regional jet?

What's the meaning of "Sollensaussagen"?

Can I hook these wires up to find the connection to a dead outlet?

Do creatures with a speed 0ft., fly 30ft. (hover) ever touch the ground?

How do conventional missiles fly?

How to travel to Japan while expressing milk?



Single row Points to Linestring


How to merge two dictionaries in a single expression?Limiting floats to two decimal pointsErrors when connecting to router with python codeHow to iterate over rows in a DataFrame in Pandas?Select rows from a DataFrame based on values in a column in pandasLabel encoding across multiple columns in scikit-learnpandas DataFrame.replace function broken for datetimeError importing jpype moduleShapely : tuples without commas with LineStringPython 37 - shapely - error in polygon creation













0















I have a pandas dataframe with a series of origins & destinations in the form of shapely Point objects. I would like to convert it to a geodatabase of linestrings.



ID orig_coord dest_coord
0 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)
1 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)
2 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)


I've tried df['line']=df.apply(lambda x: LineString()), but nothing happens.
I've tried df['line']=LineString([df['orig_coord'],df['dest_coord']]), but that gives me



---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
c:users...py3libsite-packagesshapelyspeedups_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

AttributeError: 'list' object has no attribute '__array_interface__'

During handling of the above exception, another exception occurred:

AssertionError Traceback (most recent call last)
<ipython-input-31-fe64089b1dcf> in <module>
----> 1 df['line']=LineString([df['orig_coord'],df['dest_coord']])

c:users...py3libsite-packagesshapelygeometrylinestring.py in __init__(self, coordinates)
46 BaseGeometry.__init__(self)
47 if coordinates is not None:
---> 48 self._set_coords(coordinates)
49
50 @property

c:users...py3libsite-packagesshapelygeometrylinestring.py in _set_coords(self, coordinates)
95 def _set_coords(self, coordinates):
96 self.empty()
---> 97 ret = geos_linestring_from_py(coordinates)
98 if ret is not None:
99 self._geom, self._ndim = ret

c:users...py3libsite-packagesshapelyspeedups_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

AssertionError:









share|improve this question
























  • One problem with your .apply statement is that you need to pass .apply a function pointer, which is the function name without the parenthesis. This is the way the line should be written: df['line']=df.apply(lambda x: LineString)

    – Craig
    Mar 8 at 21:01















0















I have a pandas dataframe with a series of origins & destinations in the form of shapely Point objects. I would like to convert it to a geodatabase of linestrings.



ID orig_coord dest_coord
0 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)
1 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)
2 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)


I've tried df['line']=df.apply(lambda x: LineString()), but nothing happens.
I've tried df['line']=LineString([df['orig_coord'],df['dest_coord']]), but that gives me



---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
c:users...py3libsite-packagesshapelyspeedups_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

AttributeError: 'list' object has no attribute '__array_interface__'

During handling of the above exception, another exception occurred:

AssertionError Traceback (most recent call last)
<ipython-input-31-fe64089b1dcf> in <module>
----> 1 df['line']=LineString([df['orig_coord'],df['dest_coord']])

c:users...py3libsite-packagesshapelygeometrylinestring.py in __init__(self, coordinates)
46 BaseGeometry.__init__(self)
47 if coordinates is not None:
---> 48 self._set_coords(coordinates)
49
50 @property

c:users...py3libsite-packagesshapelygeometrylinestring.py in _set_coords(self, coordinates)
95 def _set_coords(self, coordinates):
96 self.empty()
---> 97 ret = geos_linestring_from_py(coordinates)
98 if ret is not None:
99 self._geom, self._ndim = ret

c:users...py3libsite-packagesshapelyspeedups_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

AssertionError:









share|improve this question
























  • One problem with your .apply statement is that you need to pass .apply a function pointer, which is the function name without the parenthesis. This is the way the line should be written: df['line']=df.apply(lambda x: LineString)

    – Craig
    Mar 8 at 21:01













0












0








0








I have a pandas dataframe with a series of origins & destinations in the form of shapely Point objects. I would like to convert it to a geodatabase of linestrings.



ID orig_coord dest_coord
0 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)
1 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)
2 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)


I've tried df['line']=df.apply(lambda x: LineString()), but nothing happens.
I've tried df['line']=LineString([df['orig_coord'],df['dest_coord']]), but that gives me



---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
c:users...py3libsite-packagesshapelyspeedups_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

AttributeError: 'list' object has no attribute '__array_interface__'

During handling of the above exception, another exception occurred:

AssertionError Traceback (most recent call last)
<ipython-input-31-fe64089b1dcf> in <module>
----> 1 df['line']=LineString([df['orig_coord'],df['dest_coord']])

c:users...py3libsite-packagesshapelygeometrylinestring.py in __init__(self, coordinates)
46 BaseGeometry.__init__(self)
47 if coordinates is not None:
---> 48 self._set_coords(coordinates)
49
50 @property

c:users...py3libsite-packagesshapelygeometrylinestring.py in _set_coords(self, coordinates)
95 def _set_coords(self, coordinates):
96 self.empty()
---> 97 ret = geos_linestring_from_py(coordinates)
98 if ret is not None:
99 self._geom, self._ndim = ret

c:users...py3libsite-packagesshapelyspeedups_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

AssertionError:









share|improve this question
















I have a pandas dataframe with a series of origins & destinations in the form of shapely Point objects. I would like to convert it to a geodatabase of linestrings.



ID orig_coord dest_coord
0 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)
1 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)
2 POINT (-116.2847753565571 43.61722615312507) POINT (-116.3042144501943 43.60844476082184)


I've tried df['line']=df.apply(lambda x: LineString()), but nothing happens.
I've tried df['line']=LineString([df['orig_coord'],df['dest_coord']]), but that gives me



---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
c:users...py3libsite-packagesshapelyspeedups_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

AttributeError: 'list' object has no attribute '__array_interface__'

During handling of the above exception, another exception occurred:

AssertionError Traceback (most recent call last)
<ipython-input-31-fe64089b1dcf> in <module>
----> 1 df['line']=LineString([df['orig_coord'],df['dest_coord']])

c:users...py3libsite-packagesshapelygeometrylinestring.py in __init__(self, coordinates)
46 BaseGeometry.__init__(self)
47 if coordinates is not None:
---> 48 self._set_coords(coordinates)
49
50 @property

c:users...py3libsite-packagesshapelygeometrylinestring.py in _set_coords(self, coordinates)
95 def _set_coords(self, coordinates):
96 self.empty()
---> 97 ret = geos_linestring_from_py(coordinates)
98 if ret is not None:
99 self._geom, self._ndim = ret

c:users...py3libsite-packagesshapelyspeedups_speedups.pyx in shapely.speedups._speedups.geos_linestring_from_py()

AssertionError:






python pandas gis geopandas shapely






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 8 at 20:48







bcparker21

















asked Mar 8 at 20:36









bcparker21bcparker21

286




286












  • One problem with your .apply statement is that you need to pass .apply a function pointer, which is the function name without the parenthesis. This is the way the line should be written: df['line']=df.apply(lambda x: LineString)

    – Craig
    Mar 8 at 21:01

















  • One problem with your .apply statement is that you need to pass .apply a function pointer, which is the function name without the parenthesis. This is the way the line should be written: df['line']=df.apply(lambda x: LineString)

    – Craig
    Mar 8 at 21:01
















One problem with your .apply statement is that you need to pass .apply a function pointer, which is the function name without the parenthesis. This is the way the line should be written: df['line']=df.apply(lambda x: LineString)

– Craig
Mar 8 at 21:01





One problem with your .apply statement is that you need to pass .apply a function pointer, which is the function name without the parenthesis. This is the way the line should be written: df['line']=df.apply(lambda x: LineString)

– Craig
Mar 8 at 21:01












2 Answers
2






active

oldest

votes


















2














I had already used this to get the Point objects, but it hadn't occurred to me to repeat the process:



df['line']=[LineString(xy) for xy in zip(df.orig_coord,df.dest_coord)]






share|improve this answer






























    2














    here one solution:



    from shapely.geometry import Point, LineString

    o = [Point (-116.2847753565571, 43.61722615312507),
    Point(-116.2847753565571, 43.61722615312507),
    Point (-116.2847753565571,43.61722615312507)]

    d = [Point (-116.3042144501943, 43.60844476082184),
    Point(-116.3042144501943,43.60844476082184),
    Point(-116.3042144501943,43.60844476082184)]

    df = pd.DataFrame('orig_coord' : o, 'dest_coord': d)
    df['line']=df.apply(lambda x: LineString([x['orig_coord'], x['dest_coord']),axis=1)

    print(df['line'])





    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%2f55070635%2fsingle-row-points-to-linestring%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














      I had already used this to get the Point objects, but it hadn't occurred to me to repeat the process:



      df['line']=[LineString(xy) for xy in zip(df.orig_coord,df.dest_coord)]






      share|improve this answer



























        2














        I had already used this to get the Point objects, but it hadn't occurred to me to repeat the process:



        df['line']=[LineString(xy) for xy in zip(df.orig_coord,df.dest_coord)]






        share|improve this answer

























          2












          2








          2







          I had already used this to get the Point objects, but it hadn't occurred to me to repeat the process:



          df['line']=[LineString(xy) for xy in zip(df.orig_coord,df.dest_coord)]






          share|improve this answer













          I had already used this to get the Point objects, but it hadn't occurred to me to repeat the process:



          df['line']=[LineString(xy) for xy in zip(df.orig_coord,df.dest_coord)]







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 8 at 20:59









          bcparker21bcparker21

          286




          286























              2














              here one solution:



              from shapely.geometry import Point, LineString

              o = [Point (-116.2847753565571, 43.61722615312507),
              Point(-116.2847753565571, 43.61722615312507),
              Point (-116.2847753565571,43.61722615312507)]

              d = [Point (-116.3042144501943, 43.60844476082184),
              Point(-116.3042144501943,43.60844476082184),
              Point(-116.3042144501943,43.60844476082184)]

              df = pd.DataFrame('orig_coord' : o, 'dest_coord': d)
              df['line']=df.apply(lambda x: LineString([x['orig_coord'], x['dest_coord']),axis=1)

              print(df['line'])





              share|improve this answer





























                2














                here one solution:



                from shapely.geometry import Point, LineString

                o = [Point (-116.2847753565571, 43.61722615312507),
                Point(-116.2847753565571, 43.61722615312507),
                Point (-116.2847753565571,43.61722615312507)]

                d = [Point (-116.3042144501943, 43.60844476082184),
                Point(-116.3042144501943,43.60844476082184),
                Point(-116.3042144501943,43.60844476082184)]

                df = pd.DataFrame('orig_coord' : o, 'dest_coord': d)
                df['line']=df.apply(lambda x: LineString([x['orig_coord'], x['dest_coord']),axis=1)

                print(df['line'])





                share|improve this answer



























                  2












                  2








                  2







                  here one solution:



                  from shapely.geometry import Point, LineString

                  o = [Point (-116.2847753565571, 43.61722615312507),
                  Point(-116.2847753565571, 43.61722615312507),
                  Point (-116.2847753565571,43.61722615312507)]

                  d = [Point (-116.3042144501943, 43.60844476082184),
                  Point(-116.3042144501943,43.60844476082184),
                  Point(-116.3042144501943,43.60844476082184)]

                  df = pd.DataFrame('orig_coord' : o, 'dest_coord': d)
                  df['line']=df.apply(lambda x: LineString([x['orig_coord'], x['dest_coord']),axis=1)

                  print(df['line'])





                  share|improve this answer















                  here one solution:



                  from shapely.geometry import Point, LineString

                  o = [Point (-116.2847753565571, 43.61722615312507),
                  Point(-116.2847753565571, 43.61722615312507),
                  Point (-116.2847753565571,43.61722615312507)]

                  d = [Point (-116.3042144501943, 43.60844476082184),
                  Point(-116.3042144501943,43.60844476082184),
                  Point(-116.3042144501943,43.60844476082184)]

                  df = pd.DataFrame('orig_coord' : o, 'dest_coord': d)
                  df['line']=df.apply(lambda x: LineString([x['orig_coord'], x['dest_coord']),axis=1)

                  print(df['line'])






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Mar 9 at 7:29

























                  answered Mar 9 at 7:24









                  FrenchyFrenchy

                  1,8922515




                  1,8922515



























                      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%2f55070635%2fsingle-row-points-to-linestring%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

                      How to get text form Clipboard with JavaScript in Firefox 56?How to validate an email address in JavaScript?How do JavaScript closures work?How do I remove a property from a JavaScript object?How do you get a timestamp in JavaScript?How do I copy to the clipboard in JavaScript?How do I include a JavaScript file in another JavaScript file?Get the current URL with JavaScript?How to replace all occurrences of a string in JavaScriptHow to check whether a string contains a substring in JavaScript?How do I remove a particular element from an array in JavaScript?

                      Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme

                      List of MPs elected to the English parliament in 1640 (April) Contents List of constituencies and members See also Notes References Navigation menueNational Archives – The Glynde Place ArchivesCobbett's Parliamentary history of England, from the Norman Conquest in 1066 to the year 1803'Aldermen in Parliament', The Aldermen of the City of London: Temp. Henry III – 1912onepage&q&f&#61, false 229