Add content

This commit is contained in:
Carla Iriberri
2016-02-15 11:42:00 +01:00
parent 0da873fd6f
commit d8bc370ab1
4 changed files with 69 additions and 35 deletions

View File

@@ -1,10 +1,10 @@
# Data Services API
The CartoDB Data Services API offers a set of location based services that can be used programatically to empower your geospatial applications.
The CartoDB Data Services API offers a set of location based services that can be used programatically to empower your geospatial applications.
The Geocoder functions allow you to match your data with geometries on your map. This geocoding service can be used programatically to geocode datasets via the CartoDB SQL API. It is fed from _Open Data_ and it serves geometries for countries, provinces, states, cities, postal codes, IP addresses and street addresses.
The Routing functions ---
The Routing functions provide a way to generate isolines in terms of distance and time by means of the available isodistance and isochrone functions useful for Trade Areas Analysis.
## Documentation

View File

@@ -1,20 +1,20 @@
# General concepts
The Geocoder API offers geocoding services on top of the CartoDB SQL API by means of a set of geocoding functions. Each one of these functions is oriented to one kind of geocoding operation and it will return the corresponding geometry (a `polygon` or a `point`) according to the input information.
The Data Services API offers geocoding and routing services on top of the CartoDB SQL API by means of a set of functions. Each one of these functions is oriented to one kind of operation and it will return the corresponding geometry (a `polygon` or a `point`) according to the input information.
The Geocoder API decouples the geocoding service from the CartoDB Editor, and allows to geocode data (being single rows, complete datasets or simple inputs) programatically through authenticated requests.
The Data Services API decouples the geocoding and routing services from the CartoDB Editor. The API allows to geocode data (being single rows, complete datasets or simple inputs) and to perform routing analysis (computing isodistances or isochrones) programatically through authenticated requests.
The geometries provided by this API are projected in the projection [WGS 84 SRID 4326](http://spatialreference.org/ref/epsg/wgs-84/).
The Geocoder API can return different types of geometries (points or polygons) as result of different geocoding processes. The CartoDB platform does not support multigeometry layers or datasets, therefore the final users of this Geocoder API must check that they are using consistent geometry types inside a table to avoid further conflicts in the map visualization.
The Geocoder functions can return different types of geometries (points or polygons) as result of different geocoding processes. The CartoDB platform does not support multigeometry layers or datasets, therefore the final users of this Data Services API must check that they are using consistent geometry types inside a table to avoid further conflicts in the map visualization.
## Authentication
All requests performed to the CartoDB Geocoder API must be authenticated with the user API Key. For more information about where to find your API Key, and how to authenticate your SQL API requests, view the [SQL API authentication](/cartodb-platform/sql-api/authentication/) guide.
All requests performed to the CartoDB Data Services API must be authenticated with the user API Key. For more information about where to find your API Key, and how to authenticate your SQL API requests, view the [SQL API authentication](/cartodb-platform/sql-api/authentication/) guide.
## Errors
Errors are described in the response of the geocoder request. An example is as follows:
Errors are described in the response of the request. An example is as follows:
```json
{
@@ -24,10 +24,10 @@ Errors are described in the response of the geocoder request. An example is as f
}
```
Since the Geocoder API is used on top of the CartoDB SQL API, you can refer to the [Making calls to the SQL API](/cartodb-platform/sql-api/making-calls/) documentation for help debugging your SQL errors.
Since the Data Services API is used on top of the CartoDB SQL API, you can refer to the [Making calls to the SQL API](/cartodb-platform/sql-api/making-calls/) documentation for help debugging your SQL errors.
If the requested information is not in the CartoDB geocoding database, or if CartoDB is unable to recognize your input and match it with a result, the geocoding function returns `null` as a result.
## Limits
Usage of the Geocoder API is subject to the CartoDB SQL API limits, stated in our [Terms of Service](https://cartodb.com/terms/#excessive).
Usage of the Data Services API is subject to the CartoDB SQL API limits, stated in our [Terms of Service](https://cartodb.com/terms/#excessive).

View File

@@ -1,6 +1,6 @@
# Quickstart
If you are using the set of APIs and libraries that CartoDB offers, and you are handling your data with the SQL API, you can make your data visible in your maps by geocoding the dataset programatically.
If you are using the set of APIs and libraries that CartoDB offers, and you are handling your data with the SQL API, you can make your data visible in your maps by geocoding the dataset programatically. The set of Routing functions allow to calculate the area which can be reached by travelling a given distance or time, useful for geospatial analysis such as Trade Area Analysis.
Here is an example of how to geocode a single country:
@@ -13,8 +13,13 @@ In order to geocode an existent CartoDB dataset, an SQL UPDATE statement must be
```bash
https://{username}.cartodb.com/api/v2/sql?q=UPDATE {tablename} SET the_geom = cdb_geocode_admin0_polygon({country_column})&api_key={Your API key}
```
You can use the routing functions to retrieve, for example, isochrone lines from a certain location, specifying the mode and the ranges that will define each of the isolines. The following query calculates isolines for areas that are 5, 10 and 15 minutes (300, 600 and 900 seconds respectively) away of the location by following a path defined by car routing.
Notice that you can make use of Postgres or PostGIS functions in your Geocoder API requests, as the result of it will be a geometry that can be handled by the system. As an example, if you need to retrieve the centroid of a specific country, you can wrap the resulting geometry from the Geocoder API inside the PostGIS `ST_Centroid` function:
```bash
https://{username}.cartodb.com/api/v2/sql?q=SELECT cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300,600,900]::integer[])&api_key={Your API key}
```
Notice that you can make use of Postgres or PostGIS functions in your Data Services API requests, as the result of it will be a geometry that can be handled by the system. As an example, if you need to retrieve the centroid of a specific country, you can wrap the resulting geometry from the geocoder functions inside the PostGIS `ST_Centroid` function:
```bash
https://{username}.cartodb.com/api/v2/sql?q=SELECT ST_Centroid(cdb_geocode_admin0_polygon('USA'))&api_key={Your API key}

View File

@@ -1,7 +1,7 @@
# Routing functions
The following routing functions are available, grouped by categories.
The following routing functions are available.
## Isolines
@@ -13,51 +13,80 @@ This function provides an isolines generator service based on time or distance.
Name | Type | Description | Accepted values
--- | --- | --- | ---
`source` | `geometry` | Source point, in 4326 projection, taken as the start point
`source` | `geometry` | Source point, in 4326 projection, which defines the start location. |
`mode` | `geometry` | Type of transport used to calculate the isolines. | `car` or `walk`
`range` | `integer[]` | Range of the isoline in meters
`options` | `text[]` | Multiple options to add more capabilities to the analysis. See the options section to know more.
`range` | `integer[]` | Range of the isoline in meters. |
`options` | `text[]` | Optional. Multiple options to add more capabilities to the analysis. See the **Optional isolines parameters** section below for details.
#### Options
The options values must be pass in the following way: `option=value`.
Name | Type | Description | Accepted values
--- | --- | --- | ---
`is_destination` | `boolean` | If is true the source point is the destination instead of the starting one.
`mode_type` | `text` | Type of route calculation | `shortest` or `fastest`. By default is `shortest`
`mode_traffic` | `text` | Use the traffic data to calculate the route. | `enabled` or `disabled`. By default is `disabled`
`singlecomponent` | `boolean` | If set to true the isoline service will always return single polygon, instead of creating a separate polygon for each ferry separated island. | `true` or `false`. Default value is false.
`resolution` | `text` | Allows to specify level of detail needed for the isoline polygon. Unit is meters per pixel. Higher resolution may cause increased response time from the service.
`maxpoints` | `text` | Allows to limit amount of points in the returned isoline. If isoline consists of multiple components, sum of points from all components is considered. Each component will have at least 2 points, so it is possible that more points than maxpoints value will be returned. This is in case when 2 * number of components is higher than maxpoints. Enlarging number of maxpoints may cause increased response time from the service.
`quality` | `text` | Allows to reduce the quality of the isoline in favor of the response time. | `1`, `2`, `3`. Default value is 1 and it is the best quality.
#### Returns
Name | Type | Description
--- | --- | ---
`center` | `geometry` | Source point, in 4326 projection, taken as the start point
`data_range` | `integer` | The range that belongs to the generated isoline.
`the_geom` | `geometry (multipolygon)` | Geometry of the generated isoline in 4326 projection.
`center` | `geometry` | Source point, in 4326 projection, which defines the start location.
`data_range` | `integer` | The range that belongs to the generated isoline.
`the_geom` | `geometry(MultiPolygon)` | MultiPolygon geometry of the generated isoline in the 4326 projection.
#### Example
#### Examples
##### Select
##### Select the results of the isodistance function
```bash
SELECT * FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[1000,2000]::integer[]);
```
```bash
SELECT * FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[1000]::integer[], ARRAY['mode_traffic=enabled','quality=3']::text[]);
```
##### Select the geometric results of the isodistance function
```bash
SELECT the_geom FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[1000]::integer[]);
```
### cdb_isochrone(_source geometry, mode text, range integer[], options text[]_)
#### Arguments
This function uses the same parameters and information as the `cdb_isodistance` function with the difference that the range is measured in seconds instead of meters.
#### Example
Name | Type | Description | Accepted values
--- | --- | --- | ---
`source` | `geometry` | Source point, in 4326 projection, which defines the start location. |
`mode` | `geometry` | Type of transport used to calculate the isolines. | `car` or `walk`
`range` | `integer[]` | Range of the isoline in seconds. |
`options` | `text[]` | Optional. Multiple options to add more capabilities to the analysis. See the **Optional isolines parameters** section below for details.
##### Select
#### Examples
##### Select the results of the isochrone function
```bash
SELECT * FROM cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300,900,12000]::integer[]);
```
```bash
SELECT * FROM cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300,900]::integer[], ARRAY['mode_traffic=enabled','quality=3']::text[]);
```
##### Select the geometric results of the isochrone function
```bash
SELECT the_geom FROM cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300]::integer[]);
```
### Optional isoline parameters
The optional value parameters must be passed with the format: `option=value`.
Name | Type | Description | Accepted values
--- | --- | --- | ---
`is_destination` | `boolean` | If true, the source point is the destination instead of the starting location | `true` or `false`
`mode_type` | `text` | Type of route calculation | `shortest` or `fastest`. `shortest` by default
`mode_traffic` | `text` | Use traffic data to calculate the route | `enabled` or `disabled`. `disabled` by default
`singlecomponent` | `boolean` | If true, the isoline service will return a single polygon area, instead of creating a separate polygon for each reachable area separated of the main polygon (known as island). | `true` or `false`. `false` by default
`resolution` | `text` | Allows to specify level of detail needed for the isoline polygon. Unit is meters per pixel. Higher resolution may increase the response time of the service.
`maxpoints` | `text` | Allows to limit the amount of points in the returned isoline. If tge isoline consists of multiple components, the sum of points from all components is considered. Each component will have at least 2 points. It is possible that more points than specified could be returned in case when 2 * number of components` is higher than the `maxpoints` value itself. Increasing the number of `maxpoints` may increase the response time of the service.
`quality` | `text` | Allows to reduce the quality of the isoline in favor of the response time. | `1`, `2`, `3`. Default value is `1`, corresponding to the best quality option.