Merge pull request #164 from CartoDB/docs-797-best-practices
added best practices as an H3 under the Overview, data services api i…
This commit is contained in:
commit
d29b156d76
@ -2,7 +2,7 @@
|
||||
|
||||
The [geocoder](https://cartodb.com/data/geocoder-api/) 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. CartoDB provides functions for several different categories of geocoding through the Data Services API.
|
||||
|
||||
_**This service is subject to quota limitations, and extra fees may apply**. View the [Quota Information](http://docs.cartodb.com/cartodb-platform/dataservices-api/quota-information/) section for details, and recommendations, about to quota consumption._
|
||||
_**This service is subject to quota limitations and extra fees may apply**. View the [Quota Information](http://docs.cartodb.com/cartodb-platform/dataservices-api/quota-information/) section for details and recommendations about to quota consumption._
|
||||
|
||||
Here is an example of how to geocode a single country:
|
||||
|
||||
@ -16,6 +16,13 @@ In order to geocode an existent CartoDB dataset, an SQL UPDATE statement must be
|
||||
https://{username}.cartodb.com/api/v2/sql?q=UPDATE {tablename} SET the_geom = cdb_geocode_admin0_
|
||||
```
|
||||
|
||||
Notice that you can make use of Postgres or PostGIS functions in your Data Services API requests, as the result is a geometry that can be handled by the system. For example, suppose 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=UPDATE {tablename} SET the_geom = ST_Centroid(cdb_geocode_admin0_polygon('USA'))&api_key={api_key}
|
||||
```
|
||||
|
||||
|
||||
The following geocoding functions are available, grouped by categories.
|
||||
|
||||
## Country Geocoder
|
||||
@ -38,18 +45,17 @@ Geometry (polygon, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_admin0_polygon('France')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_admin0_polygon({country_column})
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_admin0_polygon('France')
|
||||
```
|
||||
|
||||
## Level-1 Administrative Regions Geocoder
|
||||
|
||||
@ -71,18 +77,19 @@ Geometry (polygon, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_admin1_polygon('Alicante')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_admin1_polygon({province_column})
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_admin1_polygon('Alicante')
|
||||
```
|
||||
|
||||
|
||||
### cdb_geocode_admin1_polygon(_admin1_name text, country_name text_)
|
||||
|
||||
Geocodes the name of the province/state for a specified country into a Level-1 administrative region, displayed as a polygon geometry.
|
||||
@ -100,17 +107,16 @@ Geometry (polygon, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_admin1_polygon('Alicante', 'Spain')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_admin1_polygon({province_column}, {country_column})
|
||||
```
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_admin1_polygon('Alicante', 'Spain')
|
||||
```
|
||||
|
||||
|
||||
## City Geocoder
|
||||
@ -135,16 +141,19 @@ Geometry (point, EPSG 4326) or null
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_namedplace_point('Barcelona')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_namedplace_point({city_column})
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_namedplace_point('Barcelona')
|
||||
```
|
||||
|
||||
|
||||
### cdb_geocode_namedplace_point(_city_name text, country_name text_)
|
||||
|
||||
Geocodes the text name of a city for a specified country into a named place point geometry.
|
||||
@ -162,18 +171,19 @@ Geometry (point, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_namedplace_point('Barcelona', 'Spain')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_namedplace_point({city_column}, 'Spain')
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_namedplace_point('Barcelona', 'Spain')
|
||||
```
|
||||
|
||||
|
||||
### cdb_geocode_namedplace_point(_city_name text, admin1_name text, country_name text_)
|
||||
|
||||
Geocodes your data into a named place point geometry, containing the text name of a city, for a specified province/state and country. This is recommended for the most accurate geocoding of city data.
|
||||
@ -191,18 +201,18 @@ Geometry (point, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_namedplace_point('New York', 'New York', 'USA')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_namedplace_point({city_column}, {province_column}, 'USA')
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_namedplace_point('New York', 'New York', 'USA')
|
||||
```
|
||||
|
||||
## Postal Code Geocoder
|
||||
|
||||
This function geocodes your data into point, or polygon, geometries for postal codes. The postal code polygon geocoder covers the United States, France, Australia and Canada; a request for a different country will return an empty response.
|
||||
@ -226,18 +236,18 @@ Geometry (polygon, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_postalcode_polygon('11211', 'USA')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_postalcode_polygon({postal_code_column}, 'USA')
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_postalcode_polygon('11211', 'USA')
|
||||
```
|
||||
|
||||
### cdb_geocode_postalcode_point(_code text, country_name text_)
|
||||
|
||||
Goecodes the postal code for a specified country into a **point** geometry.
|
||||
@ -255,18 +265,19 @@ Geometry (point, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_postalcode_point('11211', 'USA')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_postalcode_point({postal_code_column}, 'USA')
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_postalcode_point('11211', 'USA')
|
||||
```
|
||||
|
||||
|
||||
## IP Addresses Geocoder
|
||||
|
||||
This function geocodes your data into point geometries for IP addresses. This is useful if you are analyzing location based data, based on a set of user's IP addresses.
|
||||
@ -288,18 +299,18 @@ Geometry (point, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_ipaddress_point('102.23.34.1')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_ipaddress_point('102.23.34.1')
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_ipaddress_point('102.23.34.1')
|
||||
```
|
||||
|
||||
## Street-Level Geocoder
|
||||
|
||||
This function geocodes your data into a point geometry for a street address. CartoDB uses several different service providers for street-level geocoding, depending on your platform. If you access CartoDB on a Google Cloud Platform, [Google Maps geocoding](https://developers.google.com/maps/documentation/geocoding/intro) is applied. All other platform users are provided with [HERE geocoding services](https://developer.here.com/rest-apis/documentation/geocoder/topics/quick-start.html). Additional service providers will be implemented in the future.
|
||||
@ -325,19 +336,14 @@ Geometry (point, EPSG 4326) or null
|
||||
|
||||
#### Example
|
||||
|
||||
##### Select
|
||||
|
||||
Using SELECT for geocoding functions
|
||||
|
||||
```bash
|
||||
SELECT cdb_geocode_street_point('651 Lombard Street, San Francisco, California, United States')
|
||||
SELECT cdb_geocode_street_point('651 Lombard Street', 'San Francisco')
|
||||
SELECT cdb_geocode_street_point('651 Lombard Street', 'San Francisco', 'California')
|
||||
SELECT cdb_geocode_street_point('651 Lombard Street', 'San Francisco', 'California', 'United States')
|
||||
```
|
||||
|
||||
##### Update
|
||||
##### Update the geometry of a table to geocode it
|
||||
|
||||
```bash
|
||||
UPDATE {tablename} SET the_geom = cdb_geocode_street_point({street_name_column})
|
||||
```
|
||||
|
||||
##### Insert a geocoded row into a table
|
||||
|
||||
```bash
|
||||
INSERT INTO {tablename} (the_geom) SELECT cdb_geocode_street_point('651 Lombard Street', 'San Francisco', 'California', 'United States')
|
||||
```
|
||||
|
@ -2,19 +2,12 @@
|
||||
|
||||
[Isolines](https://cartodb.com/data/isolines/) are contoured lines that display equally calculated levels over a given surface area. This enables you to view polygon dimensions by forward or reverse measurements. Isoline functions are calculated as the intersection of areas from the origin point, measured by distance (isodistance) or time (isochrone). For example, the distance of a road from a sidewalk. Isoline services through CartoDB are available by requesting a single function in the Data Services API.
|
||||
|
||||
_**This service is subject to quota limitations, and extra fees may apply**. View the [Quota Information](http://docs.cartodb.com/cartodb-platform/dataservices-api/quota-information/) section for details, and recommendations, about to quota consumption._
|
||||
_**This service is subject to quota limitations and extra fees may apply**. View the [Quota Information](http://docs.cartodb.com/cartodb-platform/dataservices-api/quota-information/) section for details and recommendations about to quota consumption._
|
||||
|
||||
You can use the isoline 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 from the location by following a path defined by car routing.
|
||||
polygon({country_column})&api_key={api_key}
|
||||
You can use the isoline 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 from the location by following a path defined by car routing and inserts them into a table.
|
||||
|
||||
```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={api_key}
|
||||
```
|
||||
|
||||
Notice that you can make use of Postgres or PostGIS functions in your Data Services API requests, as the result is a geometry that can be handled by the system. For example, suppose 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={api_key}
|
||||
https://{username}.cartodb.com/api/v2/sql?q=INSERT INTO {table} (the_geom) SELECT the_geom FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300, 600, 900]::integer[])&api_key={api_key}
|
||||
```
|
||||
|
||||
The following functions provide an isoline generator service, based on time or distance. This service uses the isolines service defined for your account. The default service limits the usage of displayed polygons represented on top of [HERE](https://developer.here.com/coverage-info) maps.
|
||||
@ -43,20 +36,16 @@ Name | Type | Description
|
||||
|
||||
#### Examples
|
||||
|
||||
##### Select the results of the isodistance function
|
||||
##### Calculate and insert isodistance polygons from a point into another table
|
||||
|
||||
```bash
|
||||
SELECT * FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[1000,2000]::integer[]);
|
||||
INSERT INTO {table} (the_geom) SELECT the_geom FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300, 600, 900]::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
|
||||
or equivalently:
|
||||
|
||||
```bash
|
||||
SELECT the_geom FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[1000]::integer[]);
|
||||
INSERT INTO {table} (the_geom) SELECT (cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300, 600, 900]::integer[])).the_geom
|
||||
```
|
||||
|
||||
##### Calculate and insert the generated isolines from `points_table` table to another table
|
||||
@ -65,6 +54,7 @@ SELECT the_geom FROM cdb_isodistance('POINT(-3.70568 40.42028)'::geometry, 'walk
|
||||
INSERT INTO {table} (the_geom) SELECT (cdb_isodistance(the_geom, 'walk', string_to_array(distance, ',')::integer[])).the_geom FROM {points_table}
|
||||
```
|
||||
|
||||
|
||||
## cdb_isochrone(_source geometry, mode text, range integer[], [options text[]]_)
|
||||
|
||||
Displays a contoured line on a map, connecting geometries to a defined area, measured by an equal range of time (in seconds).
|
||||
@ -82,23 +72,19 @@ Name | Type | Description | Accepted values
|
||||
|
||||
#### Examples
|
||||
|
||||
##### Select the results of the isochrone function
|
||||
##### Calculate and insert isochrone polygons from a point into another table
|
||||
|
||||
```bash
|
||||
SELECT * FROM cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300,900,12000]::integer[]);
|
||||
INSERT INTO {table} (the_geom) SELECT the_geom FROM cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300, 900, 12000]::integer[], ARRAY['mode_traffic=enabled','quality=3']::text[])
|
||||
```
|
||||
|
||||
or equivalently:
|
||||
|
||||
```bash
|
||||
SELECT * FROM cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'walk', ARRAY[300,900]::integer[], ARRAY['mode_traffic=enabled','quality=3']::text[]);
|
||||
INSERT INTO {table} (the_geom) SELECT (cdb_isochrone('POINT(-3.70568 40.42028)'::geometry, 'car', ARRAY[300, 900, 12000]::integer[], ARRAY['mode_traffic=enabled','quality=3']::text[])).the_geom
|
||||
```
|
||||
|
||||
##### 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[]);
|
||||
```
|
||||
|
||||
##### Calculate and insert the generated isolines from `points_table` table to another table
|
||||
##### Calculate and insert the generated isolines from `points_table` table into another table
|
||||
|
||||
```bash
|
||||
INSERT INTO {table} (the_geom) SELECT (cdb_isochrone(the_geom, 'walk', string_to_array(time_distance, ',')::integer[])).the_geom FROM {points_table}
|
||||
|
@ -1,6 +1,6 @@
|
||||
# Overview
|
||||
|
||||
By using CartoDB libraries and the SQL API, you can apply location data services to your maps with select functions. These functions are integrated with a number of internal and external services, enabling you to programatically customize subsets of data for your visualizations. For example, you can transform an address to a geometry with [geocoding functions](http://docs.cartodb.com/cartodb-platform/dataservices-api/geocoding-functions/#geocoding-functions). You can also use [isoline functions](http://docs.cartodb.com/cartodb-platform/dataservices-api/isoline-functions/#isoline-functions) to calculate the travel distance for a defined area. These features are useful for geospatial analysis and the results can be saved, and stored, for additional location data service operations.
|
||||
By using CartoDB libraries and the SQL API, you can apply location data services to your maps with unique data services functions. These functions are integrated with a number of internal and external services, enabling you to programatically customize subsets of data for your visualizations. These features are useful for geospatial analysis and the results can be saved, and stored, for additional location data service operations.
|
||||
|
||||
**Note:** Based on your account plan, some of these data services are subject to different [quota limitations](http://docs.cartodb.com/cartodb-platform/dataservices-api/quota-information/#quota-information).
|
||||
|
||||
@ -16,6 +16,14 @@ The geometries provided by this API are projected in the projection [WGS 84 SRID
|
||||
|
||||
**Note:** The Data Services API [geocoding functions](http://docs.cartodb.com/cartodb-platform/dataservices-api/geocoding-functions/#geocoding-functions) return different types of geometries (points or polygons) as result of different geocoding processes. The CartoDB Platform does not support multi-geometry layers or datasets, therefore you must confirm that you are using consistent geometry types inside a table, to avoid future conflicts in your map visualization.
|
||||
|
||||
### Best Practices
|
||||
|
||||
_Be mindful of the following usage notes when using the Data Services functions with the SQL API:_
|
||||
|
||||
It is discouraged to use the SELECT operation with the Data Services API functions in your map layers, as these type of queries consume quota when rendering tiles for your live map views. It may also result in sync performance issues, due to executing multiple requests to the API each time your map is viewed. See details about [Quota Consumption](http://docs.cartodb.com/cartodb-platform/dataservices-api/quota-information/#quota-consumption).
|
||||
|
||||
The Data Services API is **recommended** to be used with INSERT or UPDATE operations, for applying location data to your tables. While SELECT (retrieve) is standard for SQL API requests, be mindful of quota consumption and use INSERT (to insert a new record) or UPDATE (to update an existing record), for best practices.
|
||||
|
||||
## Authentication
|
||||
|
||||
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/) documentation.
|
||||
|
@ -7,5 +7,8 @@
|
||||
Quota consumption is calculated based on the number of request made for each function. Be mindful of the following usage recommendations when using the Data Services API functions:
|
||||
|
||||
* One credit per function call will be consumed. The results are not cached. If the query is applied to a _N_ rows dataset, then _N_ credits are consumed
|
||||
* Avoid running dynamic queries to these functions in your maps. This can result in credit consumption per map view. **Note:** Queries to the Data Services API, and any of its functions in your maps, may be forbidden in the future
|
||||
* Avoid running dynamic queries to these functions in your maps. This can result in credit consumption per map view.
|
||||
|
||||
**Note:** Queries to the Data Services API, and any of its functions in your maps, may be forbidden in the future
|
||||
|
||||
* It is advised to store results of these queries into your datasets, and refresh them as needed. This ensure more control of quota credits for your account
|
||||
|
Loading…
Reference in New Issue
Block a user