Skip to content

Commit

Permalink
update migration docs
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentsarago committed May 1, 2020
1 parent a3b02a3 commit 0e0a122
Showing 1 changed file with 104 additions and 0 deletions.
104 changes: 104 additions & 0 deletions docs/v3_migration.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,110 @@

### MosaicJSON pydantic model

We now use [pydantic](https://pydantic-docs.helpmanual.io) to define the MosaicJSON document. Pydantic

From Pydantic docs:
> Define how data should be in pure, canonical python; validate it with pydantic.
Pydantic model enforce the mosaicjson specification for the whole project by validating each items.

```python
from pydantic import BaseModel

class MosaicJSON(BaseModel):
"""
MosaicJSON model.
Based on https://github.com/developmentseed/mosaicjson-spec
"""

mosaicjson: str
name: Optional[str]
description: Optional[str]
version: str = "1.0.0"
attribution: Optional[str]
minzoom: int = Field(0, ge=0, le=30)
maxzoom: int = Field(30, ge=0, le=30)
quadkey_zoom: Optional[int]
bounds: List[float] = Field([-180, -90, 180, 90])
center: Optional[Tuple[float, float, int]]
tiles: Dict[str, List[str]]
```

##### Validation

```python
mosaic_definition = dict(
mosaicjson="0.0.2",
minzoom=1,
maxzoom=2,
quadkey_zoom=1,
bounds=[-180, -90, 180, 90],
center=(0, 0, 1),
tiles={},
)

m = MosaicJSON(**mosaic_definition)
> MosaicJSON(mosaicjson='0.0.2', name=None, description=None, version='1.0.0', attribution=None, minzoom=1, maxzoom=2, quadkey_zoom=1, bounds=[-180.0, -90.0, 180.0, 90.0], center=(0.0, 0.0, 1), tiles={})
```

```python
# convert the mode to a dict
m.dict(exclude_none=True)
> {'mosaicjson': '0.0.2',
'version': '1.0.0',
'minzoom': 1,
'maxzoom': 2,
'quadkey_zoom': 1,
'bounds': [-180.0, -90.0, 180.0, 90.0],
'center': (0.0, 0.0, 1),
'tiles': {}}
```

```python
mosaic_definition = dict(
mosaicjson="0.0.2",
minzoom=1,
maxzoom=100,
quadkey_zoom=1,
bounds=[-180, -90, 180, 90],
center=(0, 0, 1),
tiles={},
)

m = MosaicJSON(**mosaic_definition)
...
ValidationError: 1 validation error for MosaicJSON
maxzoom
ensure this value is less than or equal to 30 (type=value_error.number.not_le; limit_value=30)
```

### Creation

The `MosaicJSON` class comes also with helper functions:
- **MosaicJSON.from_urls**: Create a mosaicjson from a set of COG urls
- **MosaicJSON.from_features**: Create a mosaicjson from a set of GeoJSON features
- **MosaicJSON._create_mosaic** (semi-private): Low level mosaic creation methods used by public methods (`from_urls` and `from_features`).

```python
#V2
from cogeo_mosaic.utils import create_mosaic

mosaic_definition: Dict = create_mosaic(dataset)


#V3
from cogeo_mosaic.mosaic import MosaicJSON

mosaic_definition: MosaicJSON = MosaicJSON.from_urls(dataset)

# or from a list of GeoJSON Features
mosaic_definition: MosaicJSON = MosaicJSON.from_features(dataset, minzoom=1, maxzoom=3)
```


To learn more about the low-level api checkout [/docs/AdvancedTopics.md](/docs/AdvancedTopics.md)

### Backend Storage

Expand Down

0 comments on commit 0e0a122

Please sign in to comment.