Hello everyone,
For a particular project, I need to collect the distance data from each US county to the nearest intersection of interstate highway ?
Is there any way I can find the data where I can show the distance from each county to the nearest intersection of interstate highway by using stata??
I know how to approach the problem using python like the following
If I update it to
it will create a column named distance with the distance between the nearest features from the 2 geodataframes. When an interstate intersects the county, the distance will be 0.0.
Can anyone help me with this to converting it to stata ??
For a particular project, I need to collect the distance data from each US county to the nearest intersection of interstate highway ?
Is there any way I can find the data where I can show the distance from each county to the nearest intersection of interstate highway by using stata??
I know how to approach the problem using python like the following
Code:
import geopandas as gpd
from shapely.geometry import Point
# Load shapefiles
counties = gpd.read_file('path/to/counties.shp')
interstates = gpd.read_file('path/to/interstates.shp')
# Perform spatial join to find nearest interstate for each county
joined = gpd.sjoin_nearest(counties, interstates)
# Calculate distance between each county and its nearest interstate
def calculate_distance(row):
county_point = row.geometry.x, row.geometry.y
interstate_point = row.geometry_nearest.x, row.geometry_nearest.y
return Point(county_point).distance(Point(interstate_point))
joined['distance'] = joined.apply(calculate_distance, axis=1)
# Save results to file
joined.to_file('path/to/output.shp')
Code:
joined = gpd.sjoin_nearest(interstates, counties, distance_cal='distance')
Can anyone help me with this to converting it to stata ??

Comment