Discussion:
[Community] Delete item from a LinearRing
Ari Simmons
2014-02-24 18:30:07 UTC
Permalink
TypeError: 'CoordinateSequence' object doesn't support item deletion
on trying to delete points from a LinearRing (see sample below).
# Remove points indexed in removeList
# Sort the list of indices in reverse order
#so that they can be deleted without throwing off other indices
del(ring.coords[i])
ring.coords is the list of coordinates.. just trying to delete...can this
not be done on a LinearRing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140224/05a10c7d/attachment.htm>
Ari Simmons
2014-02-24 18:55:15 UTC
Permalink
Post by Ari Simmons
['__array_interface__', '__class__', '__del__', '__delattr__',
'__dict__', '__doc__', '__format__', '__geo_interface__', '__geom__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__p__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
'_crs', '_ctypes_data', '_geom', '_get_coords', '_get_geom', '_is_empty',
'_lgeos', '_ndim', '_owned', '_set_coords', '_set_geom', 'almost_equals',
'area', 'array_interface', 'array_interface_base', 'boundary', 'bounds',
'buffer', 'centroid', 'contains', 'convex_hull', 'coords', 'crosses',
'ctypes', 'difference', 'disjoint', 'distance', 'empty', 'envelope',
'equals', 'equals_exact', 'geom_type', 'geometryType', 'has_z', 'impl',
'interpolate', 'intersection', 'intersects', 'is_ccw', 'is_empty',
'is_ring', 'is_simple', 'is_valid', 'length', 'overlaps',
'parallel_offset', 'project', 'relate', 'representative_point', 'simplify',
'symmetric_difference', 'to_wkb', 'to_wkt', 'touches', 'type', 'union',
'within', 'wkb', 'wkt', 'xy']

so, really...I can't delete a coordinate from a LinearRing?
Post by Ari Simmons
TypeError: 'CoordinateSequence' object doesn't support item deletion
on trying to delete points from a LinearRing (see sample below).
# Remove points indexed in removeList
# Sort the list of indices in reverse order
#so that they can be deleted without throwing off other indices
del(ring.coords[i])
ring.coords is the list of coordinates.. just trying to delete...can this
not be done on a LinearRing?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140224/f86c40c9/attachment.htm>
Sean Gillies
2014-02-24 19:41:39 UTC
Permalink
Hi Ari,

No, you can't delete an item like that (by design), but you can reassign to
Post by Ari Simmons
Post by Ari Simmons
from shapely.geometry import Point
p = Point(0, 0)
list(p.coords)
[(0.0, 0.0)]
Post by Ari Simmons
Post by Ari Simmons
p.wkt
'POINT (0 0)'
Post by Ari Simmons
Post by Ari Simmons
p.coords = [(1,1)]
list(p.coords)
[(1.0, 1.0)]
Post by Ari Simmons
Post by Ari Simmons
p.wkt
'POINT (1 1)'

I hope this helps,
Post by Ari Simmons
Post by Ari Simmons
['__array_interface__', '__class__', '__del__', '__delattr__',
'__dict__', '__doc__', '__format__', '__geo_interface__', '__geom__',
'__getattribute__', '__hash__', '__init__', '__module__', '__new__',
'__p__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
'__setstate__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__',
'_crs', '_ctypes_data', '_geom', '_get_coords', '_get_geom', '_is_empty',
'_lgeos', '_ndim', '_owned', '_set_coords', '_set_geom', 'almost_equals',
'area', 'array_interface', 'array_interface_base', 'boundary', 'bounds',
'buffer', 'centroid', 'contains', 'convex_hull', 'coords', 'crosses',
'ctypes', 'difference', 'disjoint', 'distance', 'empty', 'envelope',
'equals', 'equals_exact', 'geom_type', 'geometryType', 'has_z', 'impl',
'interpolate', 'intersection', 'intersects', 'is_ccw', 'is_empty',
'is_ring', 'is_simple', 'is_valid', 'length', 'overlaps',
'parallel_offset', 'project', 'relate', 'representative_point', 'simplify',
'symmetric_difference', 'to_wkb', 'to_wkt', 'touches', 'type', 'union',
'within', 'wkb', 'wkt', 'xy']
so, really...I can't delete a coordinate from a LinearRing?
Post by Ari Simmons
TypeError: 'CoordinateSequence' object doesn't support item deletion
on trying to delete points from a LinearRing (see sample below).
# Remove points indexed in removeList
# Sort the list of indices in reverse order
#so that they can be deleted without throwing off other indices
del(ring.coords[i])
ring.coords is the list of coordinates.. just trying to delete...can this
not be done on a LinearRing?
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
--
Sean Gillies
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20140224/4555981b/attachment.htm>
Mike Toews
2014-02-24 20:20:33 UTC
Permalink
The best way to remove coordinates from a coordinate sequence is to
extract the coordinates as a regular Python list, then use the
built-in list methods to delete/modify the list of coordinates, and
then generate a new Shapely geometry. e.g.

from shapely.geometry import LinearRing
from shapely.wkt import loads
lr = loads('LINEARRING (0 0, 0 1, 1 1, 1 0, 0 0)')
lrc = lr.coords[:] # extract coordinates
del lrc[2] # delete the third coordinate
lr2 = LinearRing(lrc) # make a new geometry
lr2.wkt # 'LINEARRING (0 0, 0 1, 1 0, 0 0)'

-Mike
Post by Ari Simmons
TypeError: 'CoordinateSequence' object doesn't support item deletion
on trying to delete points from a LinearRing (see sample below).
# Remove points indexed in removeList
# Sort the list of indices in reverse order
#so that they can be deleted without throwing off other indices
del(ring.coords[i])
ring.coords is the list of coordinates.. just trying to delete...can this
not be done on a LinearRing?
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
Loading...