arcgis-python-api icon indicating copy to clipboard operation
arcgis-python-api copied to clipboard

Support creation of SEDF containing geodesic linestrings similar to arcpy.management.XYToLine

Open cgpeltier opened this issue 3 years ago • 0 comments
trafficstars

Is your feature request related to a problem? Please describe. Given a Pandas DataFrame in the form of X1, Y1, X2, Y2, create an SEDF with a geometry column containing geodesic lines. Solution would allow for passing other attribute feature columns as well.

My solution below (also in the Community here) uses the module GeodesicLine2GIS, but I'm assuming an ArcGIS API for Python implementation would use arcpy or the underlying calculations directly. The solution below assumes that the input DF only contains the X1, Y1, X2, Y2 columns, but a production implementation would likely allow the user to specify the XY columns and optionally include the other columns as attributes.

from shapely.geometry import Point, LineString
import pandas as pd
from arcgis.features import GeoAccessor
from geodesiclinestogis.geodesicline2gisfile import GeodesicLine2Gisfile
gtg = GeodesicLine2Gisfile()

def make_geodesic_line(row):
    long_lats = tuple(row)
    cd = gtg.gdlComp(long_lats)

    line = [Point(x) for x in cd]
    line = LineString(line)
    line = str(line)
    
    return line
    
lines = start_df.apply(make_geodesic_line, axis = 1)

df = pd.DataFrame({
    'id' : list_of_ids,
    'SHAPE' : lines
})

sedf = pd.DataFrame().spatial.from_df(df, geometry_column = 'SHAPE')

Describe the solution you'd like Create an SEDF with a SHAPE column of geodesic lines, given an input Pandas DataFrame with X1, Y1, X2, Y2 columns.

cgpeltier avatar Feb 15 '22 19:02 cgpeltier