Opened 9 years ago

Closed 9 years ago

#25663 closed Cleanup/optimization (fixed)

`LinearRing` and `LineString` don't check number of points during instantiation

Reported by: Sergey Fedoseev Owned by: Sergey Fedoseev
Component: GIS Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

In [3]: LinearRing([(0,0)])
GEOS_ERROR: IllegalArgumentException: point array must contain 0 or >1 elements


---------------------------------------------------------------------------
GEOSException                             Traceback (most recent call last)
<ipython-input-3-035f8526bfee> in <module>()
----> 1 LinearRing([(0,0)])

/home/sergey/dev/django/django/contrib/gis/geos/linestring.py in __init__(self, *args, **kwargs)
     77         # Calling the base geometry initialization with the returned pointer
     78         #  from the function.
---> 79         super(LineString, self).__init__(self._init_func(cs.ptr), srid=srid)
     80 
     81     def __iter__(self):

/home/sergey/dev/django/django/contrib/gis/geos/libgeos.pyc in __call__(self, *args, **kwargs)
    155         if self.func is None:
    156             self.func = self.get_func(*self.args, **self.kwargs)
--> 157         return self.func(*args, **kwargs)
    158 
    159     def get_func(self, *args, **kwargs):

/home/sergey/dev/django/django/contrib/gis/geos/prototypes/threadsafe.pyc in __call__(self, *args)
     54             # Call the threaded GEOS routine with pointer of the context handle
     55             # as the first argument.
---> 56             return self.cfunc(self.thread_context.handle.ptr, *args)
     57         else:
     58             return self.cfunc(*args)

/home/sergey/dev/django/django/contrib/gis/geos/prototypes/errcheck.pyc in check_geom(result, func, cargs)
     30     "Error checking on routines that return Geometries."
     31     if not result:
---> 32         raise GEOSException('Error encountered checking Geometry returned from GEOS C function "%s".' % func.__name__)
     33     return result
     34 

GEOSException: Error encountered checking Geometry returned from GEOS C function "GEOSGeom_createLinearRing_r".
In [4]: LineString([(0,0)])
GEOS_ERROR: IllegalArgumentException: point array must contain 0 or >1 elements


---------------------------------------------------------------------------
GEOSException                             Traceback (most recent call last)
<ipython-input-4-25f3ed7c8486> in <module>()
----> 1 LineString([(0,0)])

/home/sergey/dev/django/django/contrib/gis/geos/linestring.py in __init__(self, *args, **kwargs)
     77         # Calling the base geometry initialization with the returned pointer
     78         #  from the function.
---> 79         super(LineString, self).__init__(self._init_func(cs.ptr), srid=srid)
     80 
     81     def __iter__(self):

/home/sergey/dev/django/django/contrib/gis/geos/libgeos.pyc in __call__(self, *args, **kwargs)
    155         if self.func is None:
    156             self.func = self.get_func(*self.args, **self.kwargs)
--> 157         return self.func(*args, **kwargs)
    158 
    159     def get_func(self, *args, **kwargs):

/home/sergey/dev/django/django/contrib/gis/geos/prototypes/threadsafe.pyc in __call__(self, *args)
     54             # Call the threaded GEOS routine with pointer of the context handle
     55             # as the first argument.
---> 56             return self.cfunc(self.thread_context.handle.ptr, *args)
     57         else:
     58             return self.cfunc(*args)

/home/sergey/dev/django/django/contrib/gis/geos/prototypes/errcheck.pyc in check_geom(result, func, cargs)
     30     "Error checking on routines that return Geometries."
     31     if not result:
---> 32         raise GEOSException('Error encountered checking Geometry returned from GEOS C function "%s".' % func.__name__)
     33     return result
     34 

GEOSException: Error encountered checking Geometry returned from GEOS C function "GEOSGeom_createLineString_r".

Change History (10)

comment:1 by Sergey Fedoseev, 9 years ago

Owner: changed from nobody to Sergey Fedoseev
Status: newassigned

comment:2 by Claude Paroz, 9 years ago

Do you think it's better to get an exception from Django instead of GEOS? For what gain?

comment:3 by Sergey Fedoseev, 9 years ago

I think the reasons are the same we decided to raise TypeError from Func with help of arity and don't rely on exception from DB backend.

comment:4 by Claude Paroz, 9 years ago

Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization
Version: 1.8master

comment:5 by Sergey Fedoseev, 9 years ago

Has patch: set

comment:6 by Tim Graham <timograham@…>, 9 years ago

Resolution: fixed
Status: assignedclosed

In 1e35dd1:

Fixed #25663 -- Added checking of the number of points for LinearRing and LineString.

comment:7 by Sergey Fedoseev, 9 years ago

Resolution: fixed
Status: closednew

It looks like I was inattentive while working on the patch and I put check in the wrong place so it doesn't work if LineString is constructed from numpy array.
Here's another PR -- https://github.com/django/django/pull/5710

comment:8 by Simon Charette, 9 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Tim Graham <timograham@…>, 9 years ago

In 229fc793:

Refs #25663 -- Fixed checking of the number of points for LineString if initialized from numpy.array.

comment:10 by Tim Graham, 9 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top