Aug-28-2019, 06:33 AM
Hi there,
I've been trying to use the Point method from shapely.geometry module to create a point, but using two fields in the shapefile being used.
As you can see I have created a dataframe from the shapefile. Even though the features have their own geometry I want to use a separate field with eastings/northing to create points. They represent another feature.
Thanks
I've been trying to use the Point method from shapely.geometry module to create a point, but using two fields in the shapefile being used.
As you can see I have created a dataframe from the shapefile. Even though the features have their own geometry I want to use a separate field with eastings/northing to create points. They represent another feature.
PTV_Playground_Joined_initial = gpd.read_file("file string to shp") df = PTV_Playground_Joined_initial orig_xy = [] for i in df: #create point of df orig_xy.append([Point(i[float(df.loc[i,"PTV_E"])], i[float(df.loc[i,"PTV_N"])])]) print(orig_xy)The problem must be due to the fact that I am using two strings from two fields in the Points method, which I guess isn't the normal way of using this. There is KeyError: 'RouteUsing' in the below 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\indexes\base.py", line 2657, in get_loc return self._engine.get_loc(key) File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 129, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index_class_helper.pxi", line 91, in pandas._libs.index.Int64Engine._check_type KeyError: 'RouteUsing' 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 106, in <module> orig_xy.append([Point(i[float(df.loc[i,"PTV_E"])], i[float(df.loc[i,"PTV_N"])])]) File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexing.py", line 1494, in __getitem__ return self._getitem_tuple(key) File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexing.py", line 868, in _getitem_tuple return self._getitem_lowerdim(tup) File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexing.py", line 988, in _getitem_lowerdim section = self._getitem_axis(key, axis=i) File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexing.py", line 1913, in _getitem_axis return self._get_label(key, axis=axis) File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexing.py", line 141, in _get_label return self.obj._xs(label, axis=axis) File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\generic.py", line 3585, in xs loc = self.index.get_loc(key) File "C:\Users\geogjo\AppData\Roaming\Python\Python37\site-packages\pandas\core\indexes\base.py", line 2659, in get_loc return self._engine.get_loc(self._maybe_cast_indexer(key)) File "pandas\_libs\index.pyx", line 108, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index.pyx", line 129, in pandas._libs.index.IndexEngine.get_loc File "pandas\_libs\index_class_helper.pxi", line 91, in pandas._libs.index.Int64Engine._check_type KeyError: 'RouteUsing'I am fairly new to Python so apologies if this is an obvious fix.
Thanks