Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def __setstate__(self, state):
self.empty()
self.__geom__ = deserialize_wkb(state)
self._is_empty = False
if lgeos.methods['has_z'](self.__geom__):
self._ndim = 3
else:
self._ndim = 2
assert N == 2 or N == 3
subs = (c_void_p * L)()
for i, ob in enumerate(obs):
if isinstance(ob, polygon.Polygon):
shell = ob.exterior
holes = ob.interiors
else:
shell = ob[0]
holes = ob[1]
geom, ndims = polygon.geos_polygon_from_py(shell, holes)
subs[i] = cast(geom, c_void_p)
return (lgeos.GEOSGeom_createCollection(6, subs, L), N)
def ctypes(self):
if not self._ctypes_data:
temp = c_double()
n = self._ndim
m = len(self.geoms)
array_type = c_double * (m * n)
data = array_type()
for i in range(m):
g = self.geoms[i]._geom
cs = lgeos.GEOSGeom_getCoordSeq(g)
lgeos.GEOSCoordSeq_getX(cs, 0, byref(temp))
data[n*i] = temp.value
lgeos.GEOSCoordSeq_getY(cs, 0, byref(temp))
data[n*i+1] = temp.value
if n == 3: # TODO: use hasz
lgeos.GEOSCoordSeq_getZ(cs, 0, byref(temp))
data[n*i+2] = temp.value
self._ctypes_data = data
return self._ctypes_data
or _coords(ob[0])[0] != _coords(ob[-1])[0]
or _coords(ob[0])[1] != _coords(ob[-1])[1]
):
M = m + 1
else:
M = m
# Create a coordinate sequence
if update_geom is not None:
if n != update_ndim:
raise ValueError(
"Coordinate dimensions mismatch: target geom has {} dims, "
"update geom has {} dims".format(n, update_ndim))
cs = lgeos.GEOSGeom_getCoordSeq(update_geom)
else:
cs = lgeos.GEOSCoordSeq_create(M, n)
# add to coordinate sequence
for i in range(m):
coords = _coords(ob[i])
# Because of a bug in the GEOS C API,
# always set X before Y
lgeos.GEOSCoordSeq_setX(cs, i, coords[0])
lgeos.GEOSCoordSeq_setY(cs, i, coords[1])
if n == 3:
try:
lgeos.GEOSCoordSeq_setZ(cs, i, coords[2])
except IndexError:
raise ValueError("Inconsistent coordinate dimensionality")
# Add closing coordinates to sequence?
if M > m:
def dumps(ob, trim=False, **kw):
"""Dump a WKT representation of a geometry to a string.
See available keyword output settings in ``shapely.geos.WKTWriter``.
"""
return geos.WKTWriter(geos.lgeos, trim=trim, **kw).write(ob)
def __call__(self, this):
self._validate(this)
env = this.envelope
if env.geom_type == 'Point':
return env.bounds
cs = lgeos.GEOSGeom_getCoordSeq(env.exterior._geom)
cs_len = c_uint(0)
lgeos.GEOSCoordSeq_getSize(cs, byref(cs_len))
minx = 1.e+20
maxx = -1e+20
miny = 1.e+20
maxy = -1e+20
temp = c_double()
for i in range(cs_len.value):
lgeos.GEOSCoordSeq_getX(cs, i, byref(temp))
x = temp.value
if x < minx: minx = x
if x > maxx: maxx = x
lgeos.GEOSCoordSeq_getY(cs, i, byref(temp))
y = temp.value
if y < miny: miny = y
if y > maxy: maxy = y
return (minx, miny, maxx, maxy)
The source may be a MultiLineString, a sequence of LineString objects,
or a sequence of objects than can be adapted to LineStrings.
"""
source = getattr(lines, 'geoms', None) or lines
try:
source = iter(source)
except TypeError:
source = [source]
finally:
obs = [self.shapeup(l) for l in source]
geom_array_type = c_void_p * len(obs)
geom_array = geom_array_type()
for i, line in enumerate(obs):
geom_array[i] = line._geom
product = lgeos.GEOSPolygonize(byref(geom_array), len(obs))
collection = geom_factory(product)
for g in collection.geoms:
clone = lgeos.GEOSGeom_clone(g._geom)
g = geom_factory(clone)
g._other_owned = False
yield g
def _coords(o):
if isinstance(o, Point):
return o.coords[0]
else:
return o
try:
n = len(_coords(ob[0]))
except TypeError:
raise ValueError(
"Input %s is the wrong shape for a LineString" % str(ob))
assert n == 2 or n == 3
# Create a coordinate sequence
if update_geom is not None:
cs = lgeos.GEOSGeom_getCoordSeq(update_geom)
if n != update_ndim:
raise ValueError(
"Wrong coordinate dimensions; this geometry has "
"dimensions: %d" % update_ndim)
else:
cs = lgeos.GEOSCoordSeq_create(m, n)
# add to coordinate sequence
for i in range(m):
coords = _coords(ob[i])
# Because of a bug in the GEOS C API,
# always set X before Y
lgeos.GEOSCoordSeq_setX(cs, i, coords[0])
lgeos.GEOSCoordSeq_setY(cs, i, coords[1])
if n == 3:
try:
def __repr__(self):
return '' % (
lgeos.geos_capi_version,)
@exceptEitherNull
def distance(self, other):
d = c_double()
retval = lgeos.GEOSDistance(self._geom, other._geom, byref(d))
return d.value