Is there a function in the ArcGIS API for Python for the XY to Line tool (like arcpy's arcpy.management.XYToLine)? I haven't been able to find it in the documentation if it exists.
Solved! Go to Solution.
Thanks Dan.
For anyone else looking for something similar in the future, I ended up using the GeodesicLinesToGIS module as the basis for this. Given a DataFrame called 'start_df' that contains two sets of long/lats i.e. X1, Y1, X2, Y2:
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')
If you wanted, then it shouldn't be too difficult to take the calculations from the GeodesicLinesToGIS module directly instead of importing it as a dependency.
No, but you can roll out your own if you want to use arcpy or even shapely
Thanks Dan.
For anyone else looking for something similar in the future, I ended up using the GeodesicLinesToGIS module as the basis for this. Given a DataFrame called 'start_df' that contains two sets of long/lats i.e. X1, Y1, X2, Y2:
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')
If you wanted, then it shouldn't be too difficult to take the calculations from the GeodesicLinesToGIS module directly instead of importing it as a dependency.