Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
Merge remote-tracking branch 'origin/master' into normalize-collection
Browse files Browse the repository at this point in the history
  • Loading branch information
perrygeo committed Nov 2, 2016
2 parents 7a8c84a + 532ef39 commit 4d0f6db
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 75 deletions.
6 changes: 6 additions & 0 deletions CHANGES
@@ -1,3 +1,9 @@
0.10.0 (?)
----------
- Breaking change: batch update of dataset features has been removed (#137).
- Bug fix: improper boolean test of tile inputs prevented access to zoom
level 0 tile containing longitude, latitude (0, 0) (#130). Fixed in #131.

0.9.0 (2016-06014)
------------------
- bbox support for forward geocoding (#124)
Expand Down
33 changes: 8 additions & 25 deletions docs/datasets.md
Expand Up @@ -104,7 +104,7 @@ create a new dataset and then add a GeoJSON feature to it.
>>> feature = {
... 'type': 'Feature', 'id': '1', 'properties': {'name': 'Insula Nulla'},
... 'geometry': {'type': 'Point', 'coordinates': [0, 0]}}
>>> resp = datasets.batch_update_features(new_id, put=[feature])
>>> resp = datasets.update_feature(new_id, '1', feature)
>>> resp.status_code
200

Expand All @@ -124,23 +124,6 @@ In the feature collection of the dataset you will see this feature.

```

Using the same `batch_update_features()` method, you can modify or delete
up to 100 features.

```python
>>> feature2 = {
... 'type': 'Feature', 'id': '2', 'properties': {'name': 'Insula Nulla B'},
... 'geometry': {'type': 'Point', 'coordinates': [0, 0]}}
>>> resp = datasets.batch_update_features(new_id, put=[feature2], delete=['1'])
>>> resp.status_code
200

```

Replication of the updates across data centers takes a small but finite amount
of time. Your next call to `datasets.list_features()` may not reflect the most
recent updates.

## Individual feature access

You can also read, update, and delete features individually.
Expand All @@ -150,14 +133,14 @@ You can also read, update, and delete features individually.
The `read_feature()` method has the semantics of HTTP GET.

```python
>>> resp = datasets.read_feature(new_id, '2')
>>> resp = datasets.read_feature(new_id, '1')
>>> resp.status_code
200
>>> feature = resp.json()
>>> feature['id']
'2'
'1'
>>> feature['properties']['name']
'Insula Nulla B'
'Insula Nulla'

```

Expand All @@ -168,11 +151,11 @@ feature in the dataset with the given id, a new feature will be created.

```python
>>> update = {
... 'type': 'Feature', 'id': '2', 'properties': {'name': 'Insula Nulla C'},
... 'type': 'Feature', 'id': '1', 'properties': {'name': 'Insula Nulla C'},
... 'geometry': {'type': 'Point', 'coordinates': [0, 0]}}
>>> update = datasets.update_feature(new_id, '2', update).json()
>>> update = datasets.update_feature(new_id, '1', update).json()
>>> update['id']
'2'
'1'
>>> update['properties']['name']
'Insula Nulla C'

Expand All @@ -183,7 +166,7 @@ feature in the dataset with the given id, a new feature will be created.
The `delete_feature()` method has the semantics of HTTP DELETE.

```python
>>> resp = datasets.delete_feature(new_id, '2')
>>> resp = datasets.delete_feature(new_id, '1')
>>> resp.status_code
204

Expand Down
2 changes: 1 addition & 1 deletion docs/geocoding.md
Expand Up @@ -134,7 +134,7 @@ Place results may be limited to those falling within a given bounding box.
```python

>>> response = geocoder.forward(
... "washington", bbox=[-78.338320,38.520792,-77.935454,38.864909])
... "washington", bbox=[-78.338320,38.520792,-77.935454,38.864909], types=('place',))
>>> response.status_code
200
>>> first = response.geojson()['features'][0]
Expand Down
2 changes: 1 addition & 1 deletion mapbox/__init__.py
@@ -1,5 +1,5 @@
# mapbox
__version__ = "0.9.0"
__version__ = "0.10.0"

from .services.datasets import Datasets
from .services.directions import Directions
Expand Down
20 changes: 0 additions & 20 deletions mapbox/services/datasets.py
Expand Up @@ -104,26 +104,6 @@ def list_features(self, dataset, reverse=False, start=None, limit=None):
params['limit'] = int(limit)
return self.session.get(uri, params=params)

def batch_update_features(self, dataset, put=None, delete=None):
"""Update features of a dataset.
Up to 100 features may be deleted or modified in one request.
:param dataset: the dataset identifier string.
:param put: an array of GeoJSON features to be created or
modified with the semantics of HTTP PUT.
:param delete: an array of feature ids to be deleted with
the semantics of HTTP DELETE.
"""
uri = URITemplate(self.baseuri + '/{owner}/{id}/features').expand(
owner=self.username, id=dataset)
updates = {}
if put:
updates['put'] = put
if delete:
updates['delete'] = delete
return self.session.post(uri, json=updates)

def read_feature(self, dataset, fid):
"""Read a dataset feature.
Expand Down
3 changes: 2 additions & 1 deletion mapbox/services/geocoding.py
Expand Up @@ -120,6 +120,7 @@ def place_types(self):
'country': "Sovereign states and other political entities. Examples: United States, France, China, Russia.",
'place': "City, town, village or other municipality relevant to a country's address or postal system. Examples: Cleveland, Saratoga Springs, Berlin, Paris.",
'neighborhood': "A smaller area within a place, often without formal boundaries. Examples: Montparnasse, Downtown, Haight-Ashbury.",
'poi': "Places of interest including commercial venues, major landmarks, parks, and other features. Examples: Yosemite National Park, Lake Superior.",
'poi': "Places of interest including commercial venues, major landmarks, parks, and other features. Examples: Subway Restaurant, Yosemite National Park, Statue of Liberty.",
'poi.landmark': "Places of interest that are particularly notable or long-lived like parks, places of worship and museums. A strict subset of the poi place type. Examples: Yosemite National Park, Statue of Liberty.",
'postcode': "Postal code, varies by a country's postal system. Examples: 20009, CR0 3RL.",
'region': "First order administrative divisions within a country, usually provinces or states. Examples: California, Ontario, Essonne."}
22 changes: 0 additions & 22 deletions tests/test_datasets.py
Expand Up @@ -202,28 +202,6 @@ def test_dataset_list_features_pagination():
assert response.json()['type'] == 'FeatureCollection'


@responses.activate
def test_batch_update_features():
"""Features update works"""

def request_callback(request):
payload = json.loads(request.body.decode())
assert payload['put'] == [{'type': 'Feature'}]
assert payload['delete'] == ['1']
return (200, {}, "")

responses.add_callback(
responses.POST,
'https://api.mapbox.com/datasets/v1/{0}/{1}/features?access_token={2}'.format(
username, 'test', access_token),
match_querystring=True,
callback=request_callback)

response = Datasets(access_token=access_token).batch_update_features(
'test', put=[{'type': 'Feature'}], delete=['1'])
assert response.status_code == 200


# Tests of feature-scoped methods.

@responses.activate
Expand Down
11 changes: 6 additions & 5 deletions tests/test_geocoder.py
Expand Up @@ -104,7 +104,8 @@ def test_geocoder_place_types():
('country', "Sovereign states and other political entities. Examples: United States, France, China, Russia."),
('neighborhood', 'A smaller area within a place, often without formal boundaries. Examples: Montparnasse, Downtown, Haight-Ashbury.'),
('place', "City, town, village or other municipality relevant to a country's address or postal system. Examples: Cleveland, Saratoga Springs, Berlin, Paris."),
('poi', "Places of interest including commercial venues, major landmarks, parks, and other features. Examples: Yosemite National Park, Lake Superior."),
('poi', "Places of interest including commercial venues, major landmarks, parks, and other features. Examples: Subway Restaurant, Yosemite National Park, Statue of Liberty."),
('poi.landmark', "Places of interest that are particularly notable or long-lived like parks, places of worship and museums. A strict subset of the poi place type. Examples: Yosemite National Park, Statue of Liberty."),
('postcode', "Postal code, varies by a country's postal system. Examples: 20009, CR0 3RL."),
('region', "First order administrative divisions within a country, usually provinces or states. Examples: California, Ontario, Essonne.")]

Expand Down Expand Up @@ -139,15 +140,15 @@ def test_geocoder_forward_types():

responses.add(
responses.GET,
'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?types=address,country,place,poi,postcode,region&access_token=pk.test',
'https://api.mapbox.com/geocoding/v5/mapbox.places/1600%20pennsylvania%20ave%20nw.json?types=address,country,place,poi.landmark,postcode,region&access_token=pk.test',
match_querystring=True,
body='{"query": ["1600", "pennsylvania", "ave", "nw"]}', status=200,
content_type='application/json')

response = mapbox.Geocoder(
access_token='pk.test').forward(
'1600 pennsylvania ave nw',
types=('address', 'country', 'place', 'poi', 'postcode', 'region'))
types=('address', 'country', 'place', 'poi.landmark', 'postcode', 'region'))
assert response.status_code == 200
assert response.json()['query'] == ["1600", "pennsylvania", "ave", "nw"]

Expand All @@ -161,7 +162,7 @@ def test_geocoder_reverse_types():

responses.add(
responses.GET,
'https://api.mapbox.com/geocoding/v5/mapbox.places/{0},{1}.json?types=address,country,place,poi,postcode,region&access_token=pk.test'.format(lon, lat),
'https://api.mapbox.com/geocoding/v5/mapbox.places/{0},{1}.json?types=address,country,place,poi.landmark,postcode,region&access_token=pk.test'.format(lon, lat),
match_querystring=True,
body=body,
status=200,
Expand All @@ -170,7 +171,7 @@ def test_geocoder_reverse_types():
response = mapbox.Geocoder(
access_token='pk.test').reverse(
lon=lon, lat=lat,
types=('address', 'country', 'place', 'poi', 'postcode', 'region'))
types=('address', 'country', 'place', 'poi.landmark', 'postcode', 'region'))
assert response.status_code == 200
assert response.json()['query'] == [lon, lat]

Expand Down

0 comments on commit 4d0f6db

Please sign in to comment.