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

Add OGRLayer::GetGeometryTypes() #6491

Merged
merged 6 commits into from Oct 23, 2022
Merged

Conversation

rouault
Copy link
Member

@rouault rouault commented Oct 9, 2022

This method iterates over features to retrieve their geometry types. This
is mostly useful for layers that report a wkbUnknown geometry type.

By default this method returns an array of nEntryCount entries with each
geometry type (in OGRGeometryTypeCounter::eGeomType) and the corresponding
number of features (in OGRGeometryTypeCounter::nCount).
Features without geometries are reported as eGeomType == wkbNone.

Optimized implementations for GPKG and PostgreSQL

@rouault rouault added this to the 3.6.0 milestone Oct 9, 2022
rouault added a commit to rouault/QGIS that referenced this pull request Oct 9, 2022
…ypes()

Use OGR_L_GetGeometryTypes() to get the actual geometry types of a
layer.

Cf OSGeo/gdal#6491
@jratike80
Copy link
Collaborator

jratike80 commented Oct 19, 2022

Sorry that I cannot read the details from the code.

Do you stop with MIXED if just linestring and multilinestring, or polygon and multipolygon are found? They could still be handled by promoting the geometries to MULTI without a need to change the geometry field into generic GEOMETRY if no other geometry types are found?

In case of GeoPackage, do you first check that the geometry_type_name in gpkg_geometry_columns is GEOMETRY (means geom_type=ogr.wkbUnknown), because otherwise it should be impossible to have mixed geometrytypes? But on the other hand, gpkg can be invalid and the metadata and the contents of the table do not necessarily match.

@rouault
Copy link
Member Author

rouault commented Oct 19, 2022

Do you stop with MIXED if just linestring and multilinestring, or polygon and multipolygon are found?

yes. I had some hesitation about that, but I decided to keep things simple. It could be tricky to decide which grouping of "equivalent" geometry types make sense. In some context linestring ~= multilinestring, but circularstring, compoundcurve or multicurve should be treated differently. In other contexts, all types of lines should be considered equivalent. Thus the user can just query all types and decide by itself which groupings make sense.

In case of GeoPackage, do you first check that the geometry_type_name

No, the implementation of GetGeometryTypes() is really checking all features. It is the responsibility of the user to only call it when it makes sense (ie GetGeomType() == wkbUnknown).

But on the other hand, gpkg can be invalid and the metadata and the contents of the table do not necessarily match.

That wasn't the motivation, but yes could be used for that.

This method iterates over features to retrieve their geometry types. This
is mostly useful for layers that report a wkbUnknown geometry type.

By default this method returns an array of nEntryCount entries with each
geometry type (in OGRGeometryTypeCounter::eGeomType) and the corresponding
number of features (in OGRGeometryTypeCounter::nCount).
Features without geometries are reported as eGeomType == wkbNone.
@rouault rouault merged commit ac9ed9c into OSGeo:master Oct 23, 2022
rouault added a commit to qgis/QGIS that referenced this pull request Nov 21, 2022
…ypes() (#50491)

Use OGR_L_GetGeometryTypes() to get the actual geometry types of a
layer.

Cf OSGeo/gdal#6491
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants