Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array of geometry types #140

Merged
merged 1 commit into from
Nov 18, 2022
Merged
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
Binary file modified examples/example.parquet
Binary file not shown.
4 changes: 2 additions & 2 deletions examples/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@


metadata = {
"version": "0.4.0",
"version": "0.5.0-dev",
"primary_column": "geometry",
"columns": {
"geometry": {
"encoding": "WKB",
"geometry_type": ["Polygon", "MultiPolygon"],
"geometry_types": ["Polygon", "MultiPolygon"],
"crs": json.loads(df.crs.to_json()),
"edges": "planar",
"bbox": [round(x, 4) for x in df.total_bounds],
Expand Down
6 changes: 3 additions & 3 deletions examples/example_metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
83.6451
],
"crs": {
"$schema": "https://proj.org/schemas/v0.4/projjson.schema.json",
"$schema": "https://proj.org/schemas/v0.5/projjson.schema.json",
"area": "World.",
"bbox": {
"east_longitude": 180,
Expand Down Expand Up @@ -108,13 +108,13 @@
},
"edges": "planar",
"encoding": "WKB",
"geometry_type": [
"geometry_types": [
"Polygon",
"MultiPolygon"
]
}
},
"primary_column": "geometry",
"version": "0.4.0"
"version": "0.5.0-dev"
}
}
19 changes: 9 additions & 10 deletions format-specs/geoparquet.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ Each geometry column in the dataset must be included in the columns field above
| Field Name | Type | Description |
| --- | --- | --- |
| encoding | string | **REQUIRED** Name of the geometry encoding format. Currently only 'WKB' is supported. |
| geometry_type | string or \[string] | **REQUIRED** The geometry type(s) of all geometries, or 'Unknown' if they are not known. |
| geometry_types | \[string] | **REQUIRED** The geometry types of all geometries, or an empty array if they are not known. |
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the field can be empty, why require it anyway?

Copy link
Collaborator

@m-mohr m-mohr Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, the description should probably mention that it's a set of values (i.e. unique items in the array - see also the other comment regarding the schema)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it is optional, I assume we wouldn't assign any different meaning to {} and {"geometry_types": []}. So then do we want "minItems": 1?

I like the idea of avoiding two ways to say the same thing. No strong preference between optional with min length of one vs required. Though it seems slightly more explicit to say that [] means "unknown" (whereas the absence of the property might either mean "unknown" or "I forgot" - not sure if there is any significant difference between the two though).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the point I think you are making though. If it isn't required that the geometry types be known, why require the geometry types in the metadata?

Copy link
Collaborator

@m-mohr m-mohr Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, if it is optional, minItems should be set to 1, indeed. I have a slight tendency for not requiring it as for me an empty array reads more as "no type". On the other hand, having it required makes people think about it (if implementations don't set a default such as write_geoparquet(geometry_types = [], ...) - but I guess a validator should anyway throw a warning if the field is present.

Copy link
Collaborator

@jorisvandenbossche jorisvandenbossche Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some discussion on this topic happened in the original issue #41. The idea was indeed that we wanted to avoid two ways to say the same thing (not specified if optional, vs geometry_type="Unknown".

And I think the rationale for making it required was indeed to have people think about it / recommend to specify a useful value (instead of just leaving out): #41 (comment)

I also find the empty array a bit less clear in indicating "unknown". Another option could also be to keep the field required and allow either the single string "Unknown" or either a list of minimum length 1.

Copy link
Collaborator Author

@tschaub tschaub Nov 8, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

len(geometry_types) == 0

vs

geometry_types[0] == "Unknown"

(I misspelled Unknown twice while trying to type that :)

Copy link
Collaborator

@m-mohr m-mohr Nov 9, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm not a big fan of "Unknown" either. Also, thinking a bit more about STAC it seems for everything we made required to make people think about it, it did not really work that way. People still just push things out without validation, so I could also see that people just omit geometry_types although required. So I tend towards not required and minLength: 1 for the array. As an explicit way to formulate "unknown" we could also consider null.

| crs | JSON object | **OPTIONAL** [PROJJSON](https://proj.org/specifications/projjson.html) JSON object representing the Coordinate Reference System (CRS) of the geometry. If the crs field is not included then the data in this column must be stored in longitude, latitude based on the WGS84 datum, and CRS-aware implementations should assume a default value of [OGC:CRS84](https://www.opengis.net/def/crs/OGC/1.3/CRS84). |
| orientation | string | **OPTIONAL** Winding order of exterior ring of polygons. If present must be 'counterclockwise'; interior rings are wound in opposite order. If absent, no assertions are made regarding the winding order. |
| edges | string | **OPTIONAL** Name of the coordinate system for the edges. Must be one of 'planar' or 'spherical'. The default value is 'planar'. |
Expand Down Expand Up @@ -110,26 +110,25 @@ The axis order of the coordinates in WKB stored in a GeoParquet follows the de f
(x, y) where x is easting or longitude and y is northing or latitude. This ordering explicitly overrides the axis order as specified in the CRS.
This follows the precedent of [GeoPackage](https://geopackage.org), see the [note in their spec](https://www.geopackage.org/spec130/#gpb_spec).

#### geometry_type
#### geometry_types

This field captures the geometry type(s) of the geometries in the
This field captures the geometry types of the geometries in the
column, when known. Accepted geometry types are: "Point", "LineString",
"Polygon", "MultiPoint", "MultiLineString", "MultiPolygon",
"GeometryCollection".

In addition, the following rules are used:

- In case of 3D geometries, a " Z" suffix gets added (e.g. "Point Z").
- The value can be a single string or an array of strings in case multiple
geometry types are present (e.g. ["Polygon", "MultiPolygon"]).
- Additionally the value "Unknown" is accepted to explicitly signal that the
geometry type is not known.
- In case of 3D geometries, a " Z" suffix gets added (e.g. ["Point Z"]).
- A list of multiple values indicates that multiple geometry types are present (e.g. ["Polygon", "MultiPolygon"]).
- An empty array explicitly signals that the geometry types are not known.
- The geometry types in the list must be unique (e.g. ["Point", "Point"] is not valid).

It is expected that this field is strictly correct. For
example, if having both polygons and multipolygons, it is not sufficient to
specify "MultiPolygon", but it is expected to specify
specify ["MultiPolygon"], but it is expected to specify
["Polygon", "MultiPolygon"]. Or if having 3D points, it is not sufficient to
specify "Point", but it is expected to list "Point Z".
specify ["Point"], but it is expected to list ["Point Z"].

#### orientation

Expand Down
34 changes: 11 additions & 23 deletions format-specs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
"properties": {
"version": {
"type": "string",
"const": "0.4.0",
"const": "0.5.0-dev",
"description": "The version of the GeoParquet metadata standard used when writing."
},
"primary_column": {
Expand All @@ -25,20 +25,14 @@
"enum": ["WKB"],
"description": "Name of the geometry encoding format. Currently only 'WKB' is supported."
},
"geometry_type": {
"oneOf": [
{
"$ref": "#/$defs/geometry_type"
},
{
"type": "array",
"items": {
"$ref": "#/$defs/geometry_type"
},
"uniqueItems": true
}
],
"description": "The geometry type(s) of all geometries, or 'Unknown' if they are not known."
"geometry_types": {
"description": "The geometry types of all geometries, or an empty array if they are not known.",
"type": "array",
tschaub marked this conversation as resolved.
Show resolved Hide resolved
"uniqueItems": true,
"items": {
"type": "string",
"pattern": "^(GeometryCollection|(Multi)?(Point|LineString|Polygon))( Z)?$"
}
},
"crs": {
"oneOf": [
Expand Down Expand Up @@ -89,17 +83,11 @@
}
},
"additionalProperties": true,
"required": ["encoding", "geometry_type"]
"required": ["encoding", "geometry_types"]
}
}
}
},
"additionalProperties": true,
"required": ["version", "primary_column", "columns"],
"$defs": {
"geometry_type": {
"type": "string",
"enum": ["Point", "LineString", "Polygon", "MultiPoint", "MultiLineString", "MultiPolygon", "GeometryCollection", "Unknown"]
}
}
"required": ["version", "primary_column", "columns"]
}