4 Replies - 352 Views - Last Post: 12 September 2019 - 12:51 AM Rate Topic: -----

#1 stixmagiggins   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-August 19

Create GeoPandas point from concatenated string

Posted 04 September 2019 - 08:19 PM

Hi there,

I have a Pandas series containing eastings and northings.
To diplay them side by side I print series values as follows otherwise it only prints the eastings first, then the northings underneath.

print(en[0]+','+en[1])


This produces the following

0     338411.19,5770955.43
1     332732.70,5772140.55
2     332808.28,5770951.78
3     330176.83,5767364.24
4     329982.85,5767339.30
5     332684.26,5772126.57.....


I want to create a geopandas Point feature using these side by side values but the problem is it is now a string due to the comma. How do I create two separate fields for each value and exclude the key (1,2,3 etc) so I can pass it to the Point function as two separate floats?

Point(xy) for xy in zip(en[0],en[1])


Is This A Good Question/Topic? 0
  • +

Replies To: Create GeoPandas point from concatenated string

#2 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 551
  • View blog
  • Posts: 1,730
  • Joined: 27-December 13

Re: Create GeoPandas point from concatenated string

Posted 05 September 2019 - 01:32 AM

Did you check the documentation: http://geopandas.org...rom_pandas.html

It seem that first page handles your problem..?

You should be able to do:
[Point(x, y) for x, y in zip(en[0],en[1])]

But they show a preferred wrapper: points_from_xy()
Was This Post Helpful? 0
  • +
  • -

#3 stixmagiggins   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-August 19

Re: Create GeoPandas point from concatenated string

Posted 09 September 2019 - 03:59 PM

Thanks.

That did create a geometry. The problem I'm stuck with now is with this line

orig_node = ox.get_nearest_node(H_xy, en, method='euclidean')


which is finding the nearest point in en to H_xy. No matter which way I go about it I get an error

(base) C:\Users\geogjo>python C:\Users\geogjo\Desktop\PythonTraining\Network_Analysis_Test.py
Traceback (most recent call last):
  File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\ops.py", line 1529, in safe_na_op
    return na_op(lvalues, rvalues)
  File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\ops.py", line 1505, in na_op
    result = expressions.evaluate(op, str_rep, x, y, **eval_kwargs)
  File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\computation\expressions.py", line 208, in evaluate
    return _evaluate(op, op_str, a, b, **eval_kwargs)
  File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\computation\expressions.py", line 68, in _evaluate_standard
    return op(a, B)/>
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\shapely\geometry\base.py", line 273, in __sub__
    return self.difference(other)
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\shapely\geometry\base.py", line 616, in difference
    return geom_factory(self.impl['difference'](self, other))
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\shapely\topology.py", line 65, in __call__
    self._validate(other, stop_prepared=True)
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\shapely\topology.py", line 17, in _validate
    if ob is None or ob._geom is None:
AttributeError: 'tuple' object has no attribute '_geom'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\geogjo\Desktop\PythonTraining\Network_Analysis_Test.py", line 132, in <module>
    orig_node = ox.get_nearest_node(H_xy, en, method='euclidean')
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\osmnx\utils.py", line 484, in get_nearest_node
    x2=df['x'])
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\osmnx\utils.py", line 421, in euclidean_dist_vec
    distance = ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
  File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\ops.py", line 1583, in wrapper
    result = safe_na_op(lvalues, rvalues)
  File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\ops.py", line 1533, in safe_na_op
    lambda x: op(x, rvalues))
  File "pandas\_libs\algos.pyx", line 690, in pandas._libs.algos.arrmap
  File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\ops.py", line 1533, in <lambda>
    lambda x: op(x, rvalues))
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\shapely\geometry\base.py", line 273, in __sub__
    return self.difference(other)
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\shapely\geometry\base.py", line 616, in difference
    return geom_factory(self.impl['difference'](self, other))
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\shapely\topology.py", line 65, in __call__
    self._validate(other, stop_prepared=True)
  File "C:\Users\geogjo\AppData\Local\Continuum\anaconda3\lib\site-packages\shapely\topology.py", line 17, in _validate
    if ob is None or ob._geom is None:
AttributeError: 'numpy.ndarray' object has no attribute '_geom'


I've tested and it keeps coming back to en. The thing is, en is a point feature. It is in eastings northings rather than lat long. I can't seem to get it working.
Was This Post Helpful? 0
  • +
  • -

#4 stixmagiggins   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 5
  • Joined: 24-August 19

Re: Create GeoPandas point from concatenated string

Posted 09 September 2019 - 07:21 PM

So why doesn't it recognise it as a geometry being a point?
Was This Post Helpful? 0
  • +
  • -

#5 DK3250   User is offline

  • Pythonian
  • member icon

Reputation: 551
  • View blog
  • Posts: 1,730
  • Joined: 27-December 13

Re: Create GeoPandas point from concatenated string

Posted 12 September 2019 - 12:51 AM

You cannot seriously expect anyone to be able to debug when all you show is one single line of code.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1