I am currently trying to retrieve some data on intercity bus travel from (https://www.bts.gov/intercity-busing/data-maps-and-apps). The data is only available as an interactive map, but I need to retrieve it into something I can analyze in Python such as a .json or .csv. To this end I found a url that I can make queries at (https://geo.dot.gov/server/rest/services/IntercityBus/nbta_routes_20190120/FeatureServer/query) and found that this problem was similar to (Query Feature Service on ESRI ArcGIS REST API with Python Requests).
How can I use this query tool to retrieve all of the data? I think I need to figure out what keys work, because I tried entering "*" or similar "all" files but could not get any of the data returned.
1 Answer 1
Firstly, you need to go up one level from that URL (by clicking on the link at the top of it) to find yourself at the feature service base URL of:
https://geo.dot.gov/server/rest/services/IntercityBus/nbta_routes_20190120/FeatureServer
From there, you can see that it lists all of that layers in that feature service with a link for each of them. There is only one layer listed, so click on the link for that layer, which takes you to the layer's URL at:
https://geo.dot.gov/server/rest/services/IntercityBus/nbta_routes_20190120/FeatureServer/0
Now scroll down to the bottom of the page and click on the 'Query' link at the bottom of the page, which will take you to the query page for that layer at:
https://geo.dot.gov/server/rest/services/IntercityBus/nbta_routes_20190120/FeatureServer/0/query
Now you have a web page with a form that you can use to query the layer. You can set the output 'Format' (at the bottom) to 'JSON' (ESRI JSON) or 'GeoJSON' if that's the format you want. But leave it on 'HTML' while testing so that you can more easily view your results. Use the Query 'GET'
button NOT the Query 'POST'
button if you want to end up with a URL (in the resulting browser page) that you can easily use to repeat the query any time.
All the other options are up to you and your preferences. However, most (all?) feature services are configured to only return a limited number of results (usually capped at 1,000). So it is very unlikely that this feature service will let you download everything!
I usually set the following in the query form:
- `Where: "1=1"
Out Fields
: "*"Return Geometry
: "False"
And this seems to work for this Feature Layer, returning 1271 records.
I also found this URL:
https://geo.dot.gov/server/rest/services/IntercityBus/nbta_stops_20200409/FeatureServer/0/query
Entering the same values in this form returns 1092 records.
-
-
This data will not be coming from Shapefiles. It will be coming from a geodatabase. (ESRI feature services cannot be run from shapefiles.) But maybe you are wondering if you can include the shape data and build shapefiles or similar from this data? If you have the "Return Geometry" field set to "True", then the geometry (shape) data will be included. There are tools that you can use to convert the GeoJSON (or ESRI JSON) into ESRI shapefiles or similar.Son of a Beach– Son of a Beach2023年03月05日 22:20:38 +00:00Commented Mar 5, 2023 at 22:20
-
Yes, geometry data would be great, but when I turn on "Return Geometry" I get the response "Error performing query operation". In the layer information it says that esriGeometryPolyline data should exist, but I cannot figure out the proper query for it.Joshua– Joshua2023年03月06日 15:07:35 +00:00Commented Mar 6, 2023 at 15:07