Create and manage a dataset

<br />

<br />

Select platform: [Android](https://developers.google.com/maps/documentation/android-sdk/dds-datasets/create-dataset.md.txt "View this page for the Android platform docs.") [iOS](https://developers.google.com/maps/documentation/ios-sdk/dds-datasets/create-dataset.md.txt "View this page for the iOS platform docs.") [JavaScript](https://developers.google.com/maps/documentation/javascript/dds-datasets/create-dataset.md.txt "View this page for the JavaScript platform docs.")

<br />

Datasets let you upload geospatial data from a local file or from Google Cloud Storage to
the Google Maps Platform. You can then associate a dataset with one or more map styles in
the Cloud console. After associating the dataset with a map style, use the
data-driven styling API to dynamically style your maps application.

You can also use a REST API to upload your geospatial data to a dataset. For more information,
see [Maps Datasets API](https://developers.google.com/maps/documentation/datasets).

## Configure roles

To create and manage datasets in a Google Cloud project, you must hold either the
[Owner or Editor IAM role](https://cloud.google.com/iam/docs/roles-overview#role-types)
on the project.

> [!NOTE]
> **Note:** If you created the project, then you have the Owner role on the project. The [**IAM** page](https://console.cloud.google.com/iam-admin/iam) of the Google Cloud console shows the project owners and editors.

Alternatively, you can assign the following IAM roles to a user account or
service account that you use to manage datasets:

- The `Maps Platform Datasets Admin` role grants the user or services account read/write access to datasets in the project. This role lets the user perform all operations on a dataset.
- The `Maps Platform Datasets Viewer` role grants read-only access to datasets in the project. This role lets you perform a list, get, or download operation on a dataset.

For more information, see
[Grant an IAM role by using the Google Cloud console](https://cloud.google.com/iam/docs/grant-role-console).

## Data source for a dataset

After you create a dataset, upload the data to the dataset from
[Google Cloud Storage](https://cloud.google.com/storage/docs)
or from a local file.

- When uploading data from Cloud Storage, specify the path to the resource containing
  the data in Cloud Storage. This path is in the form
  `gs://GCS_BUCKET/FILE`.

  You need the [Storage Object Viewer](https://cloud.google.com/storage/docs/access-control/iam-roles)
  role, or any other role that includes the `storage.objects.get` permission. For
  more information about managing access to Cloud Storage, see
  [Overview of access control](https://cloud.google.com/storage/docs/access-control).
- When uploading data from a local file, specify the path to the GeoJSON, KML, or CSV file containing the data to upload.

## Prerequisites

When creating a dataset:

- Display names must be unique within your Google Cloud project.
- Display names must be less than 64 bytes (Because these characters are represented in UTF-8, in some languages each character can be represented by multiple bytes).
- Descriptions must be less than 1000 bytes.

When uploading data:

- The supported file types are CSV, GeoJSON, and KML.
- The maximum supported file size is 500 MB.
- Attribute column names cannot begin with the string "?_".
- Three-dimensional geometries are not supported. This includes the "Z" suffix in the WKT format, and the altitude coordinate in the GeoJSON format.

> [!NOTE]
> **Note:**Depending on the size of the data file, the upload can take minutes or even hours to complete. If there is an error with the upload, you will get an error message. Don't attempt to delete the dataset until it has returned a response from the upload operation.

> [!NOTE]
> **Note:**Map tiles created with data uploaded using the Maps Datasets API may drop or simplify dense or complex data at low zoom levels. For example, when a user zooms out to a state or country (for example, zoom level 5-12), the tiled data may look different than when zoomed into a city or neighborhood (for example, zoom level 13-18). This happens in order to keep tiles slim and performant using the tiles with a map renderer.

> [!IMPORTANT]
> **Tip:**If your data file is large and has many attributes in it that you don't need for styling, and you would like to optimize rendering performance, edit the file to remove the unneeded attributes. Reducing the number of attributes reduces the size of the map's tiles, thereby improving rendering performance.

### Data preparation best practices

If your source data is complex or large, such as dense points, long linestrings or polygons
(often source file sizes larger than 50 MB fall into this category), consider simplifying your data
before uploading to achieve the best performance in a visual map.

Here are some best practices for preparing your data:

1. **Minimize feature properties** . Only keep feature properties needed to style your map, for example "id" and "category". You can join additional properties to a feature in a client application using data-driven styles on a unique identifier key. For example, see [See your data in real time with Data-driven styling](https://developers.google.com/maps/architecture/dds-real-time.md.txt).
2. **Use simple data types** for property objects where possible, such as integers, to minimize tile size and improve map performance.
3. **Simplify complex geometries** prior to uploading a file. You can do this in a geospatial tool of your choice, such as the open source [Mapshaper.org](https://mapshaper.org/) utility, or in BigQuery using [ST_Simplify](https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_simplify) on complex polygon geometries.
4. **Cluster very dense points** prior to uploading a file. You can do this in a geospatial tool of your choice, such as the open source [turf.js cluster functions](https://turfjs.org/docs/#clustersDbscan), or in BigQuery using [ST_CLUSTERDBSCAN](https://cloud.google.com/bigquery/docs/reference/standard-sql/geography_functions#st_clusterdbscan) on dense point geometries.

See additional guidance about datasets best practices in
[Visualize your data with Datasets and BigQuery](https://developers.google.com/maps/architecture/bigquery-datasets-visualization.md.txt#design_considerations).

### GeoJSON requirements

Maps JavaScript API supports the current
[GeoJSON specification](https://datatracker.ietf.org/doc/html/rfc7946).
Maps JavaScript API also support GeoJSON files that contain any of the following object types:

- **Geometry objects**. A geometry object is a spatial shape, described as a union of points, lines, and polygons with optional holes.
- **Feature objects**. A feature object contains a geometry plus additional name/value pairs, whose meaning is application-specific.
- **Feature collections**. A feature collection is a set of feature objects.

Maps JavaScript API does not support GeoJSON files that have data in a coordinate reference system
(CRS) other than [WGS84](https://epsg.io/4326).

For more information on GeoJSON, see
[RFC 7946 compliant](https://www.rfc-editor.org/rfc/rfc7946).

### KML requirements

Maps JavaScript API has the following requirements:

- All URLs must be local (or relative) to the file itself.
- Point, line, and polygon geometries supported.
- All data attributes are considered strings.

The following KML features are not supported:

<!-- -->

- Icons or `<styleUrl>` defined outside of the file.
- Network links, such as `<NetworkLink>`
- Ground overlays, such as `<GroundOverlay>`
- 3D geometries or any altitude-related tags such as `<altitudeMode>`
- Camera specifications such as `<LookAt>`
- Styles defined inside the KML file.

### CSV requirements

For CSV files, the supported column names are listed below in order of priority:

- `latitude`, `longitude`
- `lat`, `long`
- `x`, `y`
- `wkt` [(Well-Known Text)](https://en.wikipedia.org/wiki/Well-known_text_representation_of_geometry)
- `address`, `city`, `state`, `zip`
- `address`
- A single column containing all address information, such as `1600 Amphitheatre Parkway Mountain View, CA 94043`

For example, your file contains columns named `x`, `y`, and `wkt`.
Because `x` and `y` have a higher priority, as determined by the order of
supported column names in the list above, the values in the `x` and `y` columns
are used and the `wkt` column is ignored.

In addition:

- Each column name must belong to a single column. That is, you cannot have a column named `xy` that contains both x and y coordinate data. The x and y coordinates must be in separate columns.
- Column names are case-insensitive.
- The order of the column names does not matter. For example, if your CSV file contains `lat` and `long` columns, they can occur in any order.

## Handle data upload errors

When uploading data to a dataset, you might experience one of the common errors described in this
section.

### GeoJSON errors

Common GeoJSON errors include:

- Missing `type` field, or the `type` is not a string. The uploaded GeoJSON data file must contain a string field named `type` as part of each Feature object and Geometry object definition.

### KML errors

Common KML errors include:

- The data file must not contain any of the unsupported KML features listed above, otherwise the data import might fail.

### CSV errors

Common CSV errors include:

- Some rows are missing values for a geometry column. All rows in a CSV file must contain non-empty values for the geometry columns. The geometry columns include:
  - `latitude`, `longitude`
  - `lat`, `long`
  - `x`, `y`
  - `wkt`
  - `address`, `city`, `state`, `zip`
  - `address`
  - A single column containing all address information, such as `1600 Amphitheatre Parkway Mountain View, CA 94043`

  > [!NOTE]
  > **Note:**This error is often described by a message in the form "Unable to convert ' ' to a double" or "Could not parse input to geography.: Geography value is missing".

- If `x` and `y` are your geometry columns, ensure that the units are longitude and latitude. Some public datasets use different coordinate systems under the headers `x` and `y`. If the wrong units are used, the dataset might import successfully, but the rendered data can show the dataset points in unexpected locations.

## Create a dataset

To create a dataset:

1. In the Google Cloud console, [go to the **Datasets** page](https://console.cloud.google.com/google/maps-apis/datasets).
2. Click **Create Dataset**.
3. Enter the dataset name. The name must be unique among all datasets.
4. Optional: Enter a dataset **Description**.
5. Click **Continue** . The **Import data** page appears.
6. Select the **Upload source** of the data used to populate the dataset as **Desktop** , meaning a local file on your system, or **Google Cloud Storage bucket** .
   - For **Desktop** , click **Browse**, and then select the file from the file chooser.
   - For **Google Cloud Storage bucket** , click **Browse**, and then select the bucket and file containing the data.
7. Select the **File format** , and then click **Continue** to review your settings.
8. Click **Create** . The **Datasets** page appears showing your new
   dataset, and the status is **Processing**.

   If the data uploads successfully:
   - The status of the dataset is set to **COMPLETED**.
   - The dataset becomes the "active" version and is the version used by your app.

   If there's an error in the upload:
   - The status of the new dataset version is set to a status other than **COMPLETED**.

## View or modify a dataset

To view or modify a dataset:

1. In the Google Cloud console, [go to the **Datasets** page](https://console.cloud.google.com/google/maps-apis/datasets).
2. Click the name of the dataset. The **Dataset details** page appears.
   - Click the **Details** tab to see information about the dataset. On this tab, you can also edit the dataset name and description.
   - Click the **Preview** tab to see your dataset on a map. This tab is available only for datasets with a state of **COMPLETED** or **REVERTED**.
   - Click the **Table Data** tab to see all attributes of the dataset. This tab is available only for datasets with a state of **COMPLETED** or **REVERTED**. You can use these attributes to style the dataset on the map.
   - To download the data to a local file, click **Download**.
   - To delete the dataset, click **Delete**.
   - To upload new data to the dataset, click **Import Data File**.

     Uploading new data to the dataset creates a new version of the dataset. If the new data
     uploads successfully:
     - The status of the new version of the dataset is set to **COMPLETED**.
     - The new version becomes the "active" version and is the version used by your app.

     If there's an error in the upload:
     - The status of the new dataset version is set to a status other than **COMPLETED** . For example, if there's a previous "active" version, the status of the dataset is set to **REVERTED**.
     - The previously "active" dataset version stays as the "active" version and is the version used by your app.