yeesian / ArchGDAL.jl

A high level API for GDAL - Geospatial Data Abstraction Library
https://yeesian.github.io/ArchGDAL.jl/stable/
Other
141 stars 27 forks source link

Why does `createlinearring` create a wkbLineString #314

Closed rafaqz closed 2 years ago

rafaqz commented 2 years ago

See: https://github.com/yeesian/ArchGDAL.jl/blob/master/test/test_geometry.jl#L292

I'm trying to fix type stability of geometry creation for performance (some large gains from small changes) but createlinearring is a strange wart to special-case.

Why does it return a wkbLineString? as the comment says, it seems very odd.

visr commented 2 years ago

I don't really understand. LINEARRING is a non-standard extension of WKT that several projects support. It basically is a closed LINESTRING. The OGRwkbGeometryType has both wkbLineString and wkbLinearRing. GDAL seems to support it with a createlinearring function that creates a LINEARRING on toWKT. But why not use wkbLinearRing as a geometry type? Perhaps because LINESTRING is the more general type, which you can also close by having the first and last coordinate equal?

rafaqz commented 2 years ago

Yeah seems like something like that. So the question is really in what cases does GDAL actually return wkbLinearRing form ogr_g_getgeometrytype, if ever?

Hard to make things type stable without knowing that. This is a pretty commmon path too - getting rings from a polygon - so it would be good to make it faster.

visr commented 2 years ago

It seems never, based on this comment:

wkbLinearRing = 101,    /**< non-standard, just for createGeometry() */

From https://github.com/OSGeo/gdal/blob/v3.5.1/ogr/ogr_core.h#L401

rafaqz commented 2 years ago

Ok great. We can lock in wkbLineString as the type parameter.

Edit: but I guess we still need to handle passing wkbLinearRing but getting back a wkbLineString. So a line or two of special casing for createlinearring.