1

I am trying to get a point that exists along a line at X distance. I have a geodataframe that is a line feature as line_gdf and from this source Returns a point interpolated along a line using geopandas I determined that I can return a point using

line_gdf.interpolate(x) #where x is the distance along the line
print(line_gdf.interpolate(x)

prints to the terminal

FEATURE_ID
2590.0    POINT (3436860.037 1626965.958)
dtype: geometry

I'm trying to pass this geometry to a new dataframe being created with stat field

stat_pts = pd.DataFrame(
                {'NAME': [point_set['NAME'].loc[cindex], point_set['NAME'].loc[cindex + 1]],
                 'ID': [point_set['FEATURE_ID'].loc[cindex], point_set['FEATURE_ID'].loc[cindex + 1]],
                 'TRANS': [point_set['TRANS'].loc[cindex], point_set['TRANS'].loc[cindex + 1]],
                 'POSITION_UTC_DATE': [sdate, edate],
                 'SPEED': [(point_set['SPEED'].loc[cindex] + point_set['SPEED'].loc[cindex + 1]) / 2, (point_set['SPEED'].loc[cindex] + point_set['SPEED'].loc[cindex + 1]) / 2],
                 'geometry': [(line_gdf.interpolate(x)), line_gdf.interpolate(x)]})

When I try to make this into a geodataframe with geometry='geometry' I get the feature collection error. I found that when I export the pandas dataframe to csv that my geometry column is not populated properly with FEATURE_ID filling the field; not the ID number but 'FEATURE_ID' adding .geometry didn't change anything.

How do I gather the geometry info from this object and pass it to the geometry column of the new dataframe?

MrKingsley
  • 1,443
  • 13
  • 26
  • I spent most of the morning working on this and it seems that the value I am passing to geometry is FEATURE_ID 2590.0 POINT (3436860.037 1626965.958) dtype: geometry as oppose to something like POINT (3436860.037 1626965.958). Cannot seem to isolate the POINT (3436860.037 1626965.958) part of the output. – MrKingsley Nov 23 '22 at 17:33

1 Answers1

2

I need to use iloc[0] to specify the index location.

gpd.GeoDataFrame(geometry=gpd.GeoSeries((vt.pointstolines(point_set, key, 'geometry').interpolate(pdist)))).geometry.iloc[0]

worked to return just the geometry.

MrKingsley
  • 1,443
  • 13
  • 26