Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

find the last point of line geopanda

import geopandas as gpd
from shapely.geometry import Point, LineString
line1 = LineString([Point(0,0), Point(-1,-1), Point(2,-3), Point(4,5)])
line2 = LineString([Point(-2,8), Point(7,4), Point(0,-1), Point(0,2)])
gdf = gpd.GeoDataFrame(
    {'City': ['Buenos Aires','Rio de Janeiro'],
     'Country': ['Argentina', 'Brazil'], 'geometry': [line1, line2]})

gdf['first'] = None
gdf['last'] = None

for index, row in gdf.iterrows():
    coords = [(coords) for coords in list(row['geometry'].coords)]
    first_coord, last_coord = [ coords[i] for i in (0, -1) ]
    gdf.at[index,'first'] = Point(first_coord)
    gdf.at[index,'last'] = Point(last_coord)
    gdf
Comment

PREVIOUS NEXT
Code Example
Python :: check if all elements in list are equal 
Python :: python module location 
Python :: re date python 
Python :: numpy ndarray to matrix 
Python :: get the path of a module in python 
Python :: get coordinates in xarray 
Python :: check datatype python 
Python :: best scraping package in python 
Python :: freecodecamp python 
Python :: download image from url selenium python 
Python :: can serializer returns an object in django 
Python :: python merge dict 
Python :: comtypes python 
Python :: how to copy the list in python 
Python :: Difference between two dates and times in python 
Python :: permission denied when converting dataframe to csv 
Python :: django cleanup 
Python :: how to move the last column to the first column in pandas 
Python :: adam optimizer keras learning rate degrade 
Python :: python sort by length and alphabetically 
Python :: read list stored as a string with pandas read csv 
Python :: confusion matrix 
Python :: function wrapper with variable number of arguments python 
Python :: condition in python 
Python :: method get first last name python 
Python :: python list add to start 
Python :: pyqt set focus 
Python :: pandas sub columns 
Python :: flask rest api upload image 
Python :: print data type array 
ADD CONTENT
Topic
Content
Source link
Name
6+9 =