Re: confused about coordinate dimension

Daniel Baston via gdal-dev <[email protected]> Mon, 29 Jun 2026 14:57:58 -0400
Newsgroups gmane.comp.gis.gdal.devel
Message-ID <CA+K_q_o1Wm2+ZUfSW9rG-7ae5_pv==Bgf2UH0nde=6iA2H81+Q@mail.gmail.com>
--===============6912832468103051932==
Content-Type: multipart/alternative; boundary="00000000000038fc380655690aa7"

--00000000000038fc380655690aa7
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

Hi Rich,

I'm sure there's a historical reason for this, but it looks like GDAL has
two very similar methods: GetCoordinateDimension() and
CoordinateDimension(). The former, rather surprisingly, returns only 2 or
3. The latter one returns the value you're looking for:

>>> from osgeo import ogr
>>> g =3D ogr.CreateGeometryFromWkt('POINT ZM (1 2 3 4)')
>>> g.CoordinateDimension()
4
>>> g.GetCoordinateDimension()
3

Dan

On Mon, Jun 29, 2026 at 2:45=E2=80=AFPM Richard Greenwood via gdal-dev <
[email protected]> wrote:

> In Python, I want to find the coordinate dimension of my source. For
> example, with a postgis table with geometry(MultiLineStringZM,4326). My
> Python:
>
> in_lyr =3D in_ds.ExecuteSQL(select)
> feature0 =3D in_lyr.GetNextFeature()
> feature0_geom =3D feature0.GetGeometryRef()
> feature0_geom.GetGeometryType()        # 3005
> ogr.GeometryTypeToName(3005)            #  '3D Measured Multi Line String=
'
> feature0_geom.GetCoordinateDimension()  # 3
>
> Based on:
> https://gdal.org/en/stable/api/vector_c_api.html#_CPPv425OGR_G_Coordinate=
Dimension12OGRGeometryH
> I am expecting the coordinate dimension to be 4. Am I approaching this
> incorrectly?
>
> --
> Richard W. Greenwood
> _______________________________________________
> gdal-dev mailing list
> [email protected]
> https://lists.osgeo.org/mailman/listinfo/gdal-dev
>

--00000000000038fc380655690aa7
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr">Hi Rich,<div><br></div><div>I&#39;m sure there&#39;s a his=
torical reason for this, but it looks like GDAL has two very similar method=
s: GetCoordinateDimension() and CoordinateDimension(). The former, rather s=
urprisingly, returns only 2 or 3. The latter one returns the value you&#39;=
re looking for:</div><div><br></div><div>&gt;&gt;&gt; from osgeo import ogr=
<br>&gt;&gt;&gt; g =3D ogr.CreateGeometryFromWkt(&#39;POINT ZM (1 2 3 4)&#3=
9;)<br>&gt;&gt;&gt; g.CoordinateDimension()<br>4<br>&gt;&gt;&gt; g.GetCoord=
inateDimension()<br>3<br></div><div><br></div><div>Dan</div></div><br><div =
class=3D"gmail_quote gmail_quote_container"><div dir=3D"ltr" class=3D"gmail=
_attr">On Mon, Jun 29, 2026 at 2:45=E2=80=AFPM Richard Greenwood via gdal-d=
ev &lt;<a href=3D"mailto:[email protected]">[email protected]=
</a>&gt; wrote:<br></div><blockquote class=3D"gmail_quote" style=3D"margin:=
0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left=
-color:rgb(204,204,204);padding-left:1ex"><div dir=3D"ltr"><div>In Python, =
I want to find the coordinate dimension of my source. For example,<span sty=
le=3D"background-color:transparent">=C2=A0with a postgis table with=C2=A0ge=
ometry(MultiLineStringZM,4326). My Python:</span></div><blockquote style=3D=
"margin:0px 0px 0px 40px;border:medium;padding:0px"><div>in_lyr =3D in_ds.E=
xecuteSQL(select)</div><div>feature0 =3D in_lyr.GetNextFeature()</div><div>=
feature0_geom =3D feature0.GetGeometryRef()</div>feature0_geom<span style=
=3D"background-color:transparent">.GetGeometryType()=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 # 3005</span><div>ogr.GeometryTypeToName(3005)=C2=A0 =C2=A0 =C2=A0 =
=C2=A0 =C2=A0 =C2=A0 #=C2=A0 &#39;3D Measured Multi Line String&#39;</div>f=
eature0_geom.GetCoordinateDimension()<span style=3D"background-color:transp=
arent">=C2=A0 # 3</span></blockquote><div>Based on:=C2=A0<a href=3D"https:/=
/gdal.org/en/stable/api/vector_c_api.html#_CPPv425OGR_G_CoordinateDimension=
12OGRGeometryH" target=3D"_blank">https://gdal.org/en/stable/api/vector_c_a=
pi.html#_CPPv425OGR_G_CoordinateDimension12OGRGeometryH</a></div><div>I am =
expecting the coordinate dimension to be 4. Am I approaching this incorrect=
ly?</div><div><br></div><span class=3D"gmail_signature_prefix">-- </span><b=
r><div dir=3D"ltr" class=3D"gmail_signature"><div dir=3D"ltr">Richard W. Gr=
eenwood<br></div></div></div>
_______________________________________________<br>
gdal-dev mailing list<br>
<a href=3D"mailto:[email protected]" target=3D"_blank">gdal-dev@list=
s.osgeo.org</a><br>
<a href=3D"https://lists.osgeo.org/mailman/listinfo/gdal-dev" rel=3D"norefe=
rrer" target=3D"_blank">https://lists.osgeo.org/mailman/listinfo/gdal-dev</=
a><br>
</blockquote></div>

--00000000000038fc380655690aa7--

--===============6912832468103051932==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
gdal-dev mailing list
[email protected]
https://lists.osgeo.org/mailman/listinfo/gdal-dev

--===============6912832468103051932==--