I’m trying to combine multiple processing in one python code, so I’m switching from QGIS to an Anaconda environment. I already have correctly deployed my local server, and some tests are doing well:
import openrouteservice
# Initialize the client with the correct base_url
client = openrouteservice.Client(base_url='http://localhost:8080/ors')
# Define the coordinates
coords = [(7.680929, 45.070339), (7.672074, 45.071198)]
# Make the directions request
response = client.directions(
coordinates=coords,
profile='foot-walking'
)
# Check if 'routes' key exists in the response
if 'routes' in response:
print("Connection successful", response)
else:
print("Connection failed:", response)
Anyway, when I tried to add a shapefile as an input, I got an error. Here is my code:
import openrouteservice
import geopandas as gpd
# Initialize the client with the correct base_url
client = openrouteservice.Client(base_url='http://localhost:8080/ors')
# Read the input shapefile
shapefile_path = 'mypath/.shp'
gdf = gpd.read_file(shapefile_path)
# Extract the coordinates from the shapefile
coords = [(point.x, point.y) for point in gdf.geometry]
# Specify the range parameter
range_type = 'time' # or 'distance'
range_value = [120] # in seconds or meters, depending on the range_type
# Make the isochrones request
response = client.isochrones(
locations=coords,
profile='foot-walking',
range_type=range_type,
range=range_value
)
# Check if 'features' key exists in the response
if 'features' in response:
print("Connection successful")
# Process the response as needed
# ...
else:
print("Connection failed:", response)
Here is the error
ApiError: 400 ({'error': {'code': 3004, 'message': "Parameter 'locations=144' is out of range. Maximum possible value is 2."}, 'info': {'engine': {'version': '7.0.1', 'build_date': '2023-03-08T12:06:41Z'}, 'timestamp': 1684530655990}})
It seems like ORS is doing like I was accessing the online API