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
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
add a comment |
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
One problem with your.applystatement is that you need to pass.applya 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
add a comment |
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
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
python pandas gis geopandas shapely
edited Mar 8 at 20:48
bcparker21
asked Mar 8 at 20:36
bcparker21bcparker21
286
286
One problem with your.applystatement is that you need to pass.applya 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
add a comment |
One problem with your.applystatement is that you need to pass.applya 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
add a comment |
2 Answers
2
active
oldest
votes
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)]
add a comment |
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'])
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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)]
add a comment |
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)]
add a comment |
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)]
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)]
answered Mar 8 at 20:59
bcparker21bcparker21
286
286
add a comment |
add a comment |
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'])
add a comment |
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'])
add a comment |
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'])
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'])
edited Mar 9 at 7:29
answered Mar 9 at 7:24
FrenchyFrenchy
1,8922515
1,8922515
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
One problem with your
.applystatement is that you need to pass.applya 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