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

                      Thal And Out Agency railway station See also References External links Navigation menuOfficial Web Site of Pakistan RailwaysArchivedOfficial Web Site of Pakistan Railwayseeexpanding ite

                      Understanding generators in Python2019 Community Moderator ElectionGenerator function not working pythonFor loop not executing two timesGenerators - Printing generated valuesWhy can a python generator only be used once?What exactly do generators do?What does the “yield” keyword do?What does “list comprehension” mean? How does it work and how can I use it?sklearn Kfold acces single fold instead of for loopIs a generator the callable? Which is the generator?Apply Border To Range Of Cells Using OpenpyxlCalling an external command in PythonWhat are metaclasses in Python?What is the difference between @staticmethod and @classmethod?Finding the index of an item given a list containing it in PythonDifference between append vs. extend list methods in PythonHow can I safely create a nested directory in Python?Does Python have a ternary conditional operator?Understanding slice notationUnderstanding Python super() with __init__() methodsDoes Python have a string 'contains' substring method?

                      How can I change the color of pagination dots of UIPageControl?How to change UIPageControl dotsIs there a way to change page indicator dots colorCustomize dot with image of UIPageControl at index 0 of UIPageControlNo visible @interface for 'NSObject<PageControlDelegate>' declares the selector 'pageControlPageDidChange:'How to change the color of pagination dots in UIPageControl with a different color per pagepagecontrol indicator custom image instead of DefaultChanging the colour of UIPageControl dots in MonoTouchpagecontrol selectable page visibility color?Alternative way to load ViewControllers on a UIPageControlHow to set only layer.border-color for UIpage control dots in swiftHow can I develop for iPhone using a Windows development machine?How to change the name of an iOS app?UITableView - change section header coloruipagecontrol indicator(dot)issueCustom UIPageControl dots color not changingchange the interspace between UIPageControl dotsHow to change Status Bar text color in iOSHow can I change image tintColor in iOS and WatchKitUIPageControl dots with larger space in between each dotsHow to change the color of pagination dots in UIPageControl with a different color per page