Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions planet/clients/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,49 @@ async def add_items(self,
json=feature,
params=params)
return list(resp.json())

async def update_item(self, collection_id: str, feature_id: str, feature: Union[dict, GeoInterface]) -> Feature:
"""
Update an existing Feature identified by `feature_id` and `collection_id`.
Returns a Feature.

Note the Features API only accepts Polygon and MultiPolygon.

collection_id: the collection to add the feature to
feature: a dict containing a geojson Feature or FeatureCollection, or an
instance of a class that implements __geo_interface__ (e.g. a Shapely or
GeoPandas geometry object)

Example:

```
updated_feature = await features_client.update_feature(
collection_id="my-collection",
feature_id="my-feature"
feature=feature,
)
```

note: if a geojson Geometry is supplied, it will be converted
to a Feature. However, we recommend doing this conversion yourself
so that you can set a title and description property.
"""
url = f'{self._base_url}/collections/{collection_id}/items/{feature_id}'

if isinstance(feature, GeoInterface):
# we expect __geo_interface__ to return a Geometry (not a Feature), so
# we're using the name `feature` liberally. We'll convert to a feature
# at the next step.
feature = feature.__geo_interface__

# convert a geojson geometry into geojson feature
if feature.get("type", "").lower() == "featurecollection":
raise ClientError("FeatureCollection is not supported, must provide a single feature")
if feature.get("type", "").lower() != "feature":
feature = {"type": "Feature", "geometry": feature}

response = await self._session.request(method='PUT',
url=url,
json=feature)

return Feature(**response.json())
29 changes: 29 additions & 0 deletions planet/sync/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,3 +190,32 @@ def add_items(self,
property_id)

return self._client._call_sync(uploaded_features)

def update_item(self, collection_id: str, feature_id: str, feature: Union[dict, GeoInterface]) -> Feature:
"""
Update an existing Feature identified by `feature_id` and `collection_id`.
Returns a Feature.

Note the Features API only accepts Polygon and MultiPolygon.

collection_id: the collection to add the feature to
feature: a dict containing a geojson Feature or FeatureCollection, or an
instance of a class that implements __geo_interface__ (e.g. a Shapely or
GeoPandas geometry object)

Example:

```
updated_feature = await features_client.update_feature(
collection_id="my-collection",
feature_id="my-feature"
feature=feature,
)
```

note: if a geojson Geometry is supplied, it will be converted
to a Feature. However, we recommend doing this conversion yourself
so that you can set a title and description property.
"""
return self._client._call_sync(
self._client.update_item(collection_id, feature_id, feature))
Loading