,

US Distance to Coast API

support@georiskservices.com Avatar

The US Distance to Coast API by GeoRiskServices.com allows you to calculate the distance of a given location to the nearest U.S. coastline. Whether you are using geographic coordinates (latitude and longitude) or a physical address, this API provides flexibility and precision. Here’s how to use it effectively.


API Endpoint

The API can be accessed via the following endpoint:

The API accepts input as a JSON object with the following schema:

The API requires one of the following sets of parameters:

  1. Latitude and Longitude:
    • lat: Latitude (number, between -90 and 90)
    • lon: Longitude (number, between -180 and 180)
  2. Address:
    • address: A string representing a physical address (e.g., “1600 Pennsylvania Ave NW, Washington, DC 20500”).
  • perf: Boolean – Enables performance metrics. Default: false.
  • lines: Boolean – Returns additional line information. Default: false.
  • anno: Boolean – Includes annotations in the response. Default: true.
{
"lat": 34.052235,
"lon": -118.243683,
"perf": true,
"lines": false,
"anno": true
}

Or using an address:

{
"address": "235 2nd St, San Francisco, CA 94105",
"perf": false,
"lines": true,
"anno": false
}

Choose the method of input:

  • Use lat and lon if you have geographic coordinates.
  • Use address if you have a street address.

Make a POST request to the API endpoint with the prepared JSON payload. Here’s an example using curl:

Using Latitude and Longitude:

curl --location 'https://Geo-Risk-Services.proxy-production.allthingsdev.co/usdistance2coast' \
--header 'Content-Type: application/json' \
--header 'x-apihub-key: fj1jXaBtgygVVeOXYx6F1mNcd70F00XmnLnbEvGnNr831j-t5f' \
--header 'x-apihub-host: Geo-Risk-Services.allthingsdev.co' \
--header 'x-apihub-endpoint: 269e60f1-4ed9-4804-988e-0eb35f3e036e' \
--header 'Content-Type: application/json' \
--data '{
  "lat": 37.473834777940986, 
  "lng": -77.66064516962939,
  "perf": true,
  "lines": true,
  "anno": false
}'

Using an Address:

curl --location 'https://Geo-Risk-Services.proxy-production.allthingsdev.co/usdistance2coast' \
--header 'Content-Type: application/json' \
--header 'x-apihub-key: fj1jXaBtgygVVeOXYx6F1mNcd70F00XmnLnbEvGnNr831j-t5f' \
--header 'x-apihub-host: Geo-Risk-Services.allthingsdev.co' \
--header 'x-apihub-endpoint: 269e60f1-4ed9-4804-988e-0eb35f3e036e' \
--header 'Content-Type: application/json' \
--data '{
  "address": "235 2nd St, San Francisco, CA 94105",
  "perf": true,
  "lines": true,
  "anno": false
}'


The API will return a JSON response. For example:

{
"status": "success",
"db_perf_ms": 732,
"api_perf_ms": 1241,
"error": "",
"input_params": {
"lat": 37.786045080005515,
"lon": -122.3972321615382,
"address": "235 2nd St, San Francisco, CA 94105",
"perf": true,
"lines": true,
"anno": true,
"elev_ft": 43.38062480353428
},
"results": [
{
"dist_m": 7516.5,
"dist_km": 7.52,
"coast_name": "Pacific",
"dist_miles": 4.67,
"ln_to_coast": {
"type": "LineString",
"coordinates": [
[
-122.397232162,
37.78604508
],
[
-122.477896,
37.808449
]
]
}
},
{
"dist_m": 8454.46,
"dist_km": 8.45,
"coast_name": "Pacific",
"dist_miles": 5.25,
"ln_to_coast": {
"type": "LineString",
"coordinates": [
[
-122.397232162,
37.78604508
],
[
-122.479094,
37.825424
]
]
}
},
{
"dist_m": 10459.39,
"dist_km": 10.46,
"coast_name": "Pacific",
"dist_miles": 6.5,
"ln_to_coast": {
"type": "LineString",
"coordinates": [
[
-122.397232162,
37.78604508
],
[
-122.515183,
37.777929
]
]
}
}
],
"annotations": {
"annotations": [
{
"org": "US Census",
"org_link": "https://www.census.gov/",
"data_service": "https://geocoding.geo.census.gov/geocoder/",
"grs_last_udpate": "2024-08-17T22:22:32.631807+00:00"
},
{
"org": "US Census",
"org_link": "https://www.census.gov/",
"data_service": "https://catalog.data.gov/dataset/tiger-line-shapefile-2023-nation-u-s-coastline/resource/9637b61e-ec60-4ce2-a47b-16dfd54e60db?inner_span=True",
"grs_last_udpate": "2024-08-17T22:22:32.631807+00:00"
},
{
"org": "USGS",
"org_link": "https://www.usgs.gov",
"data_service": "https://apps.nationalmap.gov/epqs/",
"grs_last_udpate": "2024-09-01T01:25:43.77738+00:00"
}
]
}
}

  • distance_to_coast: Distance from the input location to the nearest U.S. coastline.
  • units: Measurement units for the distance (e.g., miles, kilometers).
  • annotations: Optional details about the sources involved.

  1. Real Estate Applications: Determine how close properties are to the coast.
  2. Environmental Analysis: Assess vulnerability to coastal hazards.
  3. Travel and Logistics: Plan routes or stops based on proximity to the coast.

  • Use geographic coordinates (lat, lon) for more accurate results.
  • Enable perf only if you need performance metrics.
  • Test queries with different configurations of lines and anno to customize the response.

This API is an excellent tool for various geospatial analysis needs. With its simple input structure and detailed response, it’s easy to integrate into your applications or workflow