The Map SDK provides a variety of data functions, allowing you to add, remove, and update datasets on your Studio Maps.

For data operations such as uploading, copying, and deleting datasets on the Studio Cloud, utilize the [Data SDK](https://docs.foursquare.com/developer/docs/data-sdk-data-functions).

---

# Add Dataset

Add a local tabular or tiled dataset objects to the map. Dataset properties are passed through a dataset object. This object should contain an ID, its label text and color, and data in CSV, JSON, or GeoJSON format.

You may also specify several options, such as whether to automatically create layers from the dataset, or whether to automatically center the viewport on the newly added dataset (both options default to `true`).

JavaScriptPython

```javascript
// Assume dataset is a valid dataset

map.addDataset(
  {
    id: "test-dataset-01",
    label: "Cities",
    color: [245, 166, 35],
    data: datasetData,
  },
  {
    autoCreateLayers: true,
    centerMap: true,
  }
);
```

```python
map.add_dataset(
    LocalDatasetCreationProps(
        id="sample-data",
        data=my_dataframe, # it supports str, List, DataFrame or GeoDataFrame
    ),
    auto_create_layers=False,
)
```

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `dataset` | `object` | An object containing dataset details. |
| `dataset.id` | `string` | Unique identifier of the dataset. |
| `dataset.label` | `string` | User-facing dataset label. |
| `dataset.color` | [`RGBColor`](https://docs.foursquare.com/developer/docs/studio-map-sdk-data-functions#rgbcolor) | Color label of the dataset. |
| `dataset.fields` | [`Field[]`](https://docs.foursquare.com/developer/docs/studio-map-sdk-data-functions#studio-map-sdk-types#studio-map-sdk-types#field) | Schema describing the fields of the dataset. |
| `dataset.data` | `string`, `object`, `unknown[][]` | Data used to create a dataset, in CSV, JSON, GeoJSON format. |
| `options` | `object` | Options available for dataset creation. |
| `options.autoCreateLayers` | `bool` | Whether or not to automatically create layers from the new dataset. Default: `true` |
| `options.centerMap` | `bool` | Whether or not to center the map on the dataset. Default: `true` |

For more information, including full Python documentation, [see `addDataset()` in the full API reference.](https://docs.foursquare.com/developer/docs/studio-map-sdk-api-reference#adddataset)

---

# Add Tile Dataset

Add a tiled dataset (i.e raster or vector data) by including a reference to its remote location.

JavaScriptPython

```javascript
map.addTileDataset(
  {
    id: "foo",
    type: "raster-tile",
    label: "Dataset",
    color: [0, 92, 255],
    metadata: {
      // NOTE: This must be a live, reachable URL
      metadataUrl: "https://path.to.metadata.json",
    },
  },
  {
    autoCreateLayers: true,
    centerMap: true,
  }
);
```

```python
map.add_tile_dataset(RasterTileDatasetRemoteCreationProps(
    id="raster-dataset-id",
    label="dataset-label",
    metadata=RasterTileRemoteMetadata(
        metadata_url="http://example.com",
    )
))
```

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `dataset.id` | `string` | Unique identifier of the dataset. |
| `dataset.label` | `string` | User-facing dataset label. |
| `dataset.color` | `RGBColor` | A three-digit array representing an RGB color value. |
| `dataset.fields` | [`Field[]`](https://docs.foursquare.com/developer/docs/studio-map-sdk-data-functions#studio-map-sdk-types#studio-map-sdk-types#studio-map-sdk-types#field) | Schema describing the fields of the dataset. |
| `dataset.metadata` | `object` | Tileset metadata. |
| `dataset.metadata.metadataUrl` | `string` | A reachable URL path to tile metadata. |
| `options` | `object` | Options available for dataset creation. |
| `options.autoCreateLayers` | `bool` | Whether or not to automatically create layers from the new dataset. Default: `true` |
| `options.centerMap` | `bool` | Whether or not to center the map on the dataset. Default: `true` |

For more information, including full Python documentation, [see `addTileDataset()` in the full API reference.](https://docs.foursquare.com/developer/docs/studio-map-sdk-api-reference#addtiledataset)

---

# Get Dataset by ID

Retrieve a dataset by passing its `id`. If the `id` is associated with an existing dataset, the dataset object is returned.

This function returns the `Dataset` object associated with the identifier, which includes the dataset's metadata, and does not include the tabular data associated with the dataset. For this functionality, check out [`getDatasetWithData`](https://docs.foursquare.com/developer/docs/studio-map-sdk-data-functions#getdatasetwithdata).

JavaScriptPython

```javascript
dataset = map.getDatasetById("test-dataset-01");
```

```python
dataset = map.get_dataset_by_id("test-dataset-01")
```

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `datasetId` | `string` | The identifier for the dataset to retrieve. |

For more information, including full Python documentation, [see `getDatasetById()` in the full API reference.](https://docs.foursquare.com/developer/docs/studio-map-sdk-api-reference#getdatasetbyid)

---

# Get Dataset with Data

Retrieve a dataset record along with its data by passing the dataset's `id`. This is useful if you need to retrieve or operate on data from Studio.

JavaScriptPython

```javascript
dataset = map.getDatasetWithData("test-dataset-01");
```

```python
dataset = map.get_dataset_with_data('test-dataset-01')
```

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `datasetId` | `string` | The identifier for the dataset to retrieve. |

For more information, including full Python documentation, [see `getDatasetWithData()` in the full API reference.](https://docs.foursquare.com/developer/docs/studio-map-sdk-api-reference#getdatasetwithdata)

---

# Get Datasets

Retrieve a list of all datasets available on the map. This is returned as an array of `Dataset` objects, each containing the dataset's `id`, `label`, `color` and other specified options.

JavaScriptPython

```javascript
datasets = map.getDatasets();
```

```python
datasets = map.get_datasets()
```

For more information, including full Python documentation, [see `getDatasets()` in the full API reference.](https://docs.foursquare.com/developer/docs/studio-map-sdk-api-reference#getdatasets)

---

# Remove Dataset

Remove a dataset from the map by passing its `id`.

> Important note: When a dataset is removed, all associated layers are also removed. Please ensure no layers you wish to keep rely on the dataset you wish to delete.

JavaScriptPython

```javascript
map.removeDataset("test-dataset-01");
```

```python
map.remove_dataset('test-dataset-01')
```

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `datasetId` | `string` | The identifier of the dataset to remove. |

For more information, including full Python documentation, [see `removeDataset()` in the full API reference.](https://docs.foursquare.com/developer/docs/studio-map-sdk-api-reference#removedataset)

---

# Replace Dataset

Select a dataset to replace as `thisDatasetId`, then provide a new `Dataset` object in `withDataset`. This function is particularly useful for replacing an existing dataset for a new one with a similar schema, updating all layers with the new data.

JavaScriptPython

```javascript
// suppose newDataset is a valid Dataset object
map.replaceDataset("old-dataset-01", newDataset, { strict: true });
```

```python
map.replace_dataset(
    this_dataset_id="dataset-id-to-replace",
    with_dataset=LocalDatasetCreationProps(
        data=my_other_dataframe_data,
    ),
    strict=True
)
```

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `thisDatasetId` | `string` | Identifier of the dataset to replace. |
| `withDataset` | `object` | A dataset object to use as a replacement. |
| `withDataset.label` | `string` | User-facing dataset label. |
| `withDataset.color` | `RGBColor` | A three-digit array representing an RGB color value. |
| `withDataset.fields` | [`Field[]`](https://docs.foursquare.com/developer/docs/studio-map-sdk-data-functions#studio-map-sdk-types#studio-map-sdk-types#field) | Schema describing the fields of the dataset. |
| `withDataset.data` | `string`, `object`, `unknown[][]` | Data used to create a dataset, in CSV, JSON, GeoJSON format. |
| `options` | `object` | Options available for dataset replacement. |
| `options.force` | `bool` | Whether to force a dataset replace, even if the compatibility check fails. Default: `false`. |
| `options.strict` | `bool` | Whether to ensure strict equality of types for each field being replaced. Default: `false`. |

For more information, including full Python documentation, [see `replaceDataset()` in the full API reference.](https://docs.foursquare.com/developer/docs/studio-map-sdk-api-reference#replacedataset)

---

# Update Dataset

Update an existing dataset's configuration by passing its `id`. This function should be used to update the dataset's user-facing label, color, or field schema.

JavaScriptPython

```javascript
map.updateDataset("test-dataset-01", {
  label: "Dataset",
  color: [245, 166, 35],
});
```

```python
map.update_dataset('dataset-id', DatasetUpdateProps(
    label="My new label",
    color=(255,0,0)
))
```

### Arguments

| Argument | Type | Description |
| --- | --- | --- |
| `datasetId` | `string` | The identifier of the dataset to update. |
| `values` | `object` | The values to update. |
| `values.label` | `string` | User-facing dataset label. |
| `values.color` | `RGBColor` | A three-digit array representing an RGB color value. |
| `values.fields` | [`Field[]`](https://docs.foursquare.com/developer/docs/studio-map-sdk-data-functions#studio-map-sdk-types#studio-map-sdk-types#field) | Schema describing the fields of the dataset. |

For more information, including full Python documentation, [see `updateDataset()` in the full API reference.](https://docs.foursquare.com/developer/docs/studio-map-sdk-api-reference#updatedataset)
