Features API

Developers can get dataset features, add new features and delete existing features. In the future there will be support for accessing and editing individual features.

Endpoint: http://geocommons.com/datasets/:id/features.{format}

Description: The features API allows you to retrieve all or a portion of features in a given dataset.

HTTP Methods Available: GET, POST, DELETE

URL Summary:

TaskURLFormatsHTTP METHOD
Retrieve Filtered Featureshttp://geocommons.com/datasets/{id}/features.{format}jsonGET
Create Featureshttp://geocommons.com/datasets/{id}/features.{format}jsonPOST
Delete Featureshttp://geocommons.com/datasets/{id}/features.{format}?ids={feature_ids}jsonDELETE

Authentication:

Depends on permissions. “Download” required for reading filtered features, and “Edit” required for Creating or Deleting features.

Retrieve Filtered Features

Required Parameters: (none)

Optional Parameters:

ParameterDescriptionExample
limitnumber of features to return (default is 30)limit=2
order‘ascending’ or ‘descending’ of the sort attribute (default ascending)order=descending
startindex to start with. 1 would be the first. Allows paginating through datastart=6
callbackcallback method to wrap the response incallback=filteredLayer
bboxWest/South/East/North is the order of the bounding box to get the features contained within an areabbox=-79.5,20,-78,50
unitssets the unit for the radius parameter by default is km (requires radius parameter)possible options are: km,m,ft,miles,degreesunits=ft
lonlongitude of a point being searched from requires use of radius and lat parameters additionallylon=-77.9998
latlatitude of a point being search from requires use of the radius and lon parameters additionallylat=39.8282
radiusdefines distanced to be search from of a polygon,line,points or lat/lon pair (default is km)radius=100
intersectspecify if polygons are contained or full. By default is set to contained which means only polygons completely inside the buffer will be returned, full means any part inside or touchingintersect=contained
with_distanceset to “true” to get a distance calculation of the centroid of the feature to the boundary polygon sent back with the features.with_distance=1
filterfilter parameters for specific attributes within the datasetfilter[dec_col][][max]=.22
group_byarray of columns to “group by” in aggregating featuresgroup_by[]=state
aggregatesarray of aggregation values. Includes by name and calc. Name is the attribute name and calc can be any of: max,min,sum,averageaggregates[][name]=timestamp&aggregates[][calc]=max
geojsonreturns the geometry in GeoJSON formatgeojson=1
hex_geometryreturns the geometry in HEX EWKB formathex_geometry=1
encodereturns the geometry in Google Maps encoded polyline formatencode=1

all latitude and longitude is in decimal degrees

Curl Examples:

curl http://geocommons.com/datasets/98696/features.json?bbox=-79.5,20,-78,50

Filter features within a bounding box

curl http://geocommons.com/datasets/98696/features.json?lat=39.2&lon=-77.1&radius=100
Filter features within 100 km of a point

curl http://geocommons.com/datasets/98696/features.json?points=-77.1,39.8,-77.2,39.9,-77.3,39.99,-77.1,39.8&radius=100

Filter features within 100 kilometers of multiple points by longitude,latitude

curl http://geocommons.com/datasets/98696/features.json?polygon=-77,34,-78.5,34.5,-82,32,-79,30,-77,34&radius=100

Filter features within a 100 kilometer distance of a polygon

curl http://geocommons.com/datasets/98696/features.json?line=-77,34,-78.5,34.5,-82,32,-79,30&radius=100

Filter features within 100 km of a geographic line (such as a road)

curl http://geocommons.com/datasets/22146/features.json?lat=38.8&lon=-78.9&radius=2&intersect=full

Filter features within or overlapping 2 km of a point

curl http://geocommons.com/datasets/98696/features.json?filter[int_col][][equals]=1&filter[dec_col][][max]=.22

Filter features where int_col is equal to 1 and dec_col is less than 0.22

Filter Parameters:

Datasets can be filtered when requested from the server. This is done by calling the dataset/:id/features/ with the optional filter= paramter. The filter parameter can include a filter for any attribute name, and an array of filter conditions. Filter names must be URI encoded.

ParametersDescriptionExample
minthe minimum value of the attributefilter[financing_amt][][min]=100
maxthe maximum value of the attributefilter[financing_amt][][max]=120
equalsthe value the attribute must be equal tofilter[name][][equals]=bob
http://geocommons.com/datasets/98696/features.json?filter[int_col][][max]=5&filter[name][][equals]=point%201
http://geocommons.com/datasets/98696/features.json?filter[int_col][][max]=5&filter[int_col][][min]=3

Aggregate Statistics

Using the Feature API it’s possible to calculate roll-up statistics of features. Using the group_by and aggregates you can specify to summarize max,min,sum, or average values. If a group_by is specified but no aggregates, then just a count is returned of the number of features in that group.

group_by

The group_by option groups features based on the value of the attribute specified. This ends up with summarized data, by default with a count and optionally with additional aggregates as specified below.

curl http://geocommons.com/datasets/98696/features.json?group_by[]=sortable

aggregates

The aggregates option is an array of objects that contain both a name and a calc. So for example: aggregates[][name]=cost&aggregates[][calc]=average. A request can have multiple aggregates.

The calc parameter can be any of:

  • max – maximum value of all attribute features
  • min – minimum value of all attribute features
  • sum – summation of all values
  • average – average of all values

Example

curl http://geocommons.com/datasets/98696/features.json?aggregates[][name]=int_col&aggregates[][calc]=sum&group_by[]=sortable

Create Features

Required Parameters: (none)

Optional Parameters:

Creating a feature in GeoIQ depends on the format, or schema, of the dataset. The Features include any of the optional attributes that are in the dataset and additionally a Geometry that is formatted as GeoJSON.

ParameterDescriptionExample
any attributeany attribute value from the dataset schema{title: “My new Feature”}
geometryGeoJSON formatted geometry{geometry: {type: “Point”, coordinates: [-100, 80.3]}}

Example:

Given a JSON array of features in a file features.json:

[{name: "My new feature", sortable: "true", dec_col: 50.8, geometry: {type: "Point", coordinates: [-100, 80]}}, {name: "My other feature", sortable: "false", dec_col: 20.8, geometry: {type: "Point", coordinates: [-120, 62.4]}}]

You could then POST this to the endpoint:

cat features.json | curl -X POST -u "user:pass" -H "Content-Type: application/json" -d @- http://geocommons.com/datasets/98696/features.json

Delete Features

At this time, the delete features endpoint requires a “resource identifier” that is not actually used. So you can put whatever value you want for this. The important aspect are the array of ids that will be deleted. Currently these are a simple index into the feature array, starting at 0.

Required Parameters:

ParameterDescriptionExample
idsarray of feature index identifiers. Starts at 0ids=0,5,99

Optional Parameters: (none)

Example:

curl -X DELETE -u "user:pass" http://geocommons.com/maps/98696/features/0.json?ids=0,5,59
 

Comments are closed.