votes up 1

Dimension mismatch.

Package:
django
github stars 57383
Exception Class:
TypeError

Raise code

                if not isinstance(coord, (tuple, list, Point)):
                    raise TypeError('Each coordinate should be a sequence (list or tuple)')

                if ndim is None:
                    ndim = len(coord)
                    self._checkdim(ndim)
                elif len(coord) != ndim:
                    raise TypeError('Dimension mismatch.')

        # Creating a coordinate sequence object because it is easier to
        # set the points using its methods.
        cs = GEOSCoordSeq(capi.create_cs(ncoords, ndim), z=bool(ndim == 3))
        point_setter = cs._set_point_3d if ndim == 3 else cs._set_point_2d

        for i in range(ncoords):

Ways to fix

votes up 2 votes down

Error codes:

from django.contrib.gis.goes import LineString

ls = LineString((1, 1), (2, 2, 4)) #Error here 

or

from django.contrib.gis.goes import LineString

ls = LineString([3,4], [[1,3]]) #Error here

In both scenarios, we are getting an error, because:

1) In the first code, tuples within LineString don't have the same length.

2) In the second code, arrays' dimensions must be 1, not 2.

Fix codes:

from django.contrib.gis.goes import LineString 

ls = LineString((1, 1), (2, 2))

or

from django.contrib.gis.goes import LineString 

ls = LineString([3,4], [1,3])

Jun 11, 2021 nurlan.taghi answer
nurlan.taghi 1.4k

Add a possible fix

Please authorize to post fix