本文整理汇总了Python中shapely.geometry.base.geom_factory函数的典型用法代码示例。如果您正苦于以下问题:Python geom_factory函数的具体用法?Python geom_factory怎么用?Python geom_factory使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了geom_factory函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: polygonize_full
def polygonize_full(self, lines):
"""Creates polygons from a source of lines, returning the polygons
and leftover geometries.
The source may be a MultiLineString, a sequence of LineString objects,
or a sequence of objects than can be adapted to LineStrings.
Returns a tuple of objects: (polygons, dangles, cut edges, invalid ring
lines). Each are a geometry collection.
Dangles are edges which have one or both ends which are not incident on
another edge endpoint. Cut edges are connected at both ends but do not
form part of polygon. Invalid ring lines form rings which are invalid
(bowties, etc).
"""
source = getattr(lines, "geoms", None) or lines
try:
source = iter(source)
except TypeError:
source = [source]
finally:
obs = [self.shapeup(l) for l in source]
L = len(obs)
subs = (c_void_p * L)()
for i, g in enumerate(obs):
subs[i] = g._geom
collection = lgeos.GEOSGeom_createCollection(5, subs, L)
dangles = c_void_p()
cuts = c_void_p()
invalids = c_void_p()
product = lgeos.GEOSPolygonize_full(collection, byref(dangles), byref(cuts), byref(invalids))
return (geom_factory(product), geom_factory(dangles), geom_factory(cuts), geom_factory(invalids))
开发者ID:gepcel,项目名称:Shapely,代码行数:32,代码来源:ops.py
示例2: polygonize
def polygonize(iterator):
"""Creates polygons from a list of LineString objects.
"""
lines = [shapeup(ob) for ob in iterator]
geom_array_type = c_void_p * len(lines)
geom_array = geom_array_type()
for i, line in enumerate(lines):
geom_array[i] = line._geom
product = lgeos.GEOSPolygonize(byref(geom_array), len(lines))
collection = geom_factory(product)
for g in collection.geoms:
clone = lgeos.GEOSGeom_clone(g._geom)
g = geom_factory(clone)
g._owned = False
yield g
开发者ID:52North,项目名称:glaps,代码行数:15,代码来源:ops.py
示例3: clip_by_rect
def clip_by_rect(geom, xmin, ymin, xmax, ymax):
"""Returns the portion of a geometry within a rectangle
The geometry is clipped in a fast but possibly dirty way. The output is
not guaranteed to be valid. No exceptions will be raised for topological
errors.
Parameters
----------
geom : geometry
The geometry to be clipped
xmin : float
Minimum x value of the rectangle
ymin : float
Minimum y value of the rectangle
xmax : float
Maximum x value of the rectangle
ymax : float
Maximum y value of the rectangle
Notes
-----
Requires GEOS >= 3.5.0
New in 1.7.
"""
if geom.is_empty:
return geom
result = geom_factory(lgeos.methods['clip_by_rect'](geom._geom, xmin, ymin, xmax, ymax))
return result
开发者ID:mwtoews,项目名称:Shapely,代码行数:29,代码来源:ops.py
示例4: parallel_offset
def parallel_offset(
self, distance, side='right',
resolution=16, join_style=JOIN_STYLE.round, mitre_limit=5.0):
"""Returns a LineString or MultiLineString geometry at a distance from
the object on its right or its left side.
The side parameter may be 'left' or 'right' (default is 'right'). The
resolution of the buffer around each vertex of the object increases by
increasing the resolution keyword parameter or third positional
parameter. If the distance parameter is negative the side is inverted,
e.g. distance=5.0, side='left' is the same as distance=-5.0,
side='right'.
The join style is for outside corners between line segments. Accepted
values are JOIN_STYLE.round (1), JOIN_STYLE.mitre (2), and
JOIN_STYLE.bevel (3).
The mitre ratio limit is used for very sharp corners. It is the ratio
of the distance from the corner to the end of the mitred offset corner.
When two line segments meet at a sharp angle, a miter join will extend
far beyond the original geometry. To prevent unreasonable geometry, the
mitre limit allows controlling the maximum length of the join corner.
Corners with a ratio which exceed the limit will be beveled."""
if mitre_limit == 0.0:
raise ValueError(
'Cannot compute offset from zero-length line segment')
try:
return geom_factory(self.impl['parallel_offset'](
self, distance, resolution, join_style, mitre_limit, side))
except OSError:
raise TopologicalError()
开发者ID:tpot1,项目名称:3rdyearproj,代码行数:32,代码来源:linestring.py
示例5: dumps
def dumps(ob, hex=False, srid=None, **kw):
"""Dump a WKB representation of a geometry to a byte string, or a
hex-encoded string if ``hex=True``.
Parameters
----------
ob : geometry
The geometry to export to well-known binary (WKB) representation
hex : bool
If true, export the WKB as a hexidecimal string. The default is to
return a binary string/bytes object.
srid : int
Spatial reference system ID to include in the output. The default value
means no SRID is included.
**kw : kwargs
See available keyword output settings in ``shapely.geos.WKBWriter``."""
if srid is not None:
# clone the object and set the SRID before dumping
geom = lgeos.GEOSGeom_clone(ob._geom)
lgeos.GEOSSetSRID(geom, srid)
ob = geom_factory(geom)
kw["include_srid"] = True
writer = WKBWriter(lgeos, **kw)
if hex:
return writer.write_hex(ob)
else:
return writer.write(ob)
开发者ID:Toblerity,项目名称:Shapely,代码行数:27,代码来源:wkb.py
示例6: loads
def loads(data):
"""Load a geometry from a WKT string."""
from shapely.geometry.base import geom_factory
geom = lgeos.GEOSGeomFromWKT(c_char_p(data.encode('utf-8')))
if not geom:
raise ReadingError("Could not create geometry because of errors while reading input.")
return geom_factory(geom)
开发者ID:machristie,项目名称:shapely-py3k,代码行数:7,代码来源:wkt.py
示例7: parallel_offset
def parallel_offset(self, distance, side, resolution=16, join_style=1, mitre_limit=1.0):
"""Returns a LineString or MultiLineString geometry at a distance from
the object on its right or its left side.
Distance must be a positive float value. The side parameter may be
'left' or 'right'. The resolution of the buffer around each vertex of
the object increases by increasing the resolution keyword parameter or
third positional parameter.
The join style is for outside corners between line segments. Accepted
values are 1 => ROUND, 2 => MITRE, 3 => BEVEL.
The mitre ratio limit is used for very sharp corners. It is the ratio
of the distance from the corner to the end of the mitred offset corner.
When two line segments meet at a sharp angle, a miter join will extend
far beyond the original geometry. To prevent unreasonable geometry, the
mitre limit allows controlling the maximum length of the join corner.
Corners with a ratio which exceed the limit will be beveled."""
try:
return geom_factory(
self.impl["parallel_offset"](self, distance, resolution, join_style, mitre_limit, bool(side == "left"))
)
except WindowsError:
raise TopologicalError()
开发者ID:netconstructor,项目名称:shapely,代码行数:26,代码来源:linestring.py
示例8: snap
def snap(g1, g2, tolerance):
"""Snap one geometry to another with a given tolerance
Vertices of the first geometry are snapped to vertices of the second
geometry. The resulting snapped geometry is returned. The input geometries
are not modified.
Parameters
----------
g1 : geometry
The first geometry
g2 : geometry
The second geometry
tolerence : float
The snapping tolerance
Example
-------
>>> square = Polygon([(1,1), (2, 1), (2, 2), (1, 2), (1, 1)])
>>> line = LineString([(0,0), (0.8, 0.8), (1.8, 0.95), (2.6, 0.5)])
>>> result = snap(line, square, 0.5)
>>> result.wkt
'LINESTRING (0 0, 1 1, 2 1, 2.6 0.5)'
"""
return(geom_factory(lgeos.methods['snap'](g1._geom, g2._geom, tolerance)))
开发者ID:aronbierbaum,项目名称:shapely,代码行数:25,代码来源:ops.py
示例9: loads
def loads(data):
"""Load a geometry from a WKT string."""
geom = lgeos.GEOSGeomFromWKT(c_char_p(data))
if not geom:
raise ReadingError, \
"Could not create geometry because of errors while reading input."
return geom_factory(geom)
开发者ID:52North,项目名称:glaps,代码行数:7,代码来源:wkt.py
示例10: linemerge
def linemerge(shape):
""" Returns a geometry with lines merged using GEOSLineMerge.
"""
if shape.type != 'MultiLineString':
return shape
# copied from shapely.ops.linemerge at http://github.com/sgillies/shapely
result = lgeos.GEOSLineMerge(shape._geom)
return geom_factory(result)
开发者ID:blackmad,项目名称:Bloch,代码行数:9,代码来源:__init__.py
示例11: polygonize
def polygonize(self, lines):
"""Creates polygons from a source of lines
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
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._owned = False
yield g
开发者ID:mikeocool,项目名称:shapely,代码行数:19,代码来源:ops.py
示例12: read
def read(self, text):
"""Returns geometry from WKT"""
if sys.version_info[0] >= 3:
text = text.encode('ascii')
geom = self._lgeos.GEOSWKTReader_read(self._reader, c_char_p(text))
if not geom:
raise ReadingError("Could not create geometry because of errors "
"while reading input.")
# avoid circular import dependency
from shapely.geometry.base import geom_factory
return geom_factory(geom)
开发者ID:Bmcalpine,项目名称:Shapely,代码行数:11,代码来源:geos.py
示例13: unary_union
def unary_union(self, geoms):
"""Returns the union of a sequence of geometries
This is the most efficient method of dissolving many polygons.
"""
L = len(geoms)
subs = (c_void_p * L)()
for i, g in enumerate(geoms):
subs[i] = g._geom
collection = lgeos.GEOSGeom_createCollection(6, subs, L)
return geom_factory(lgeos.GEOSUnaryUnion(collection))
开发者ID:mikeocool,项目名称:shapely,代码行数:11,代码来源:ops.py
示例14: unary_union
def unary_union(self, geoms):
"""Returns the union of a sequence of geometries
This method replaces :meth:`cascaded_union` as the
prefered method for dissolving many polygons.
"""
L = len(geoms)
subs = (c_void_p * L)()
for i, g in enumerate(geoms):
subs[i] = g._geom
collection = lgeos.GEOSGeom_createCollection(6, subs, L)
return geom_factory(lgeos.methods['unary_union'](collection))
开发者ID:demiurg,项目名称:Shapely,代码行数:13,代码来源:ops.py
示例15: read
def read(self, text):
"""Returns geometry from WKT"""
if not isinstance(text, text_types):
raise TypeError("Only str is accepted.")
if sys.version_info[0] >= 3:
text = text.encode()
c_string = c_char_p(text)
geom = self._lgeos.GEOSWKTReader_read(self._reader, c_string)
if not geom:
raise WKTReadingError(
"Could not create geometry because of errors "
"while reading input.")
# avoid circular import dependency
from shapely.geometry.base import geom_factory
return geom_factory(geom)
开发者ID:Toblerity,项目名称:Shapely,代码行数:15,代码来源:geos.py
示例16: cascaded_union
def cascaded_union(self, geoms):
"""Returns the union of a sequence of geometries
This is the most efficient method of dissolving many polygons.
"""
try:
L = len(geoms)
except TypeError:
geoms = [geoms]
L = 1
subs = (c_void_p * L)()
for i, g in enumerate(geoms):
subs[i] = g._geom
collection = lgeos.GEOSGeom_createCollection(6, subs, L)
return geom_factory(lgeos.methods["cascaded_union"](collection))
开发者ID:gepcel,项目名称:Shapely,代码行数:15,代码来源:ops.py
示例17: triangulate
def triangulate(geom, tolerance=0.0, edges=False):
"""Creates the Delaunay triangulation and returns a list of geometries
The source may be any geometry type. All vertices of the geometry will be
used as the points of the triangulation.
From the GEOS documentation:
tolerance is the snapping tolerance used to improve the robustness of
the triangulation computation. A tolerance of 0.0 specifies that no
snapping will take place.
If edges is False, a list of Polygons (triangles) will be returned.
Otherwise the list of LineString edges is returned.
"""
func = lgeos.methods["delaunay_triangulation"]
gc = geom_factory(func(geom._geom, tolerance, int(edges)))
return [g for g in gc.geoms]
开发者ID:gepcel,项目名称:Shapely,代码行数:18,代码来源:ops.py
示例18: linemerge
def linemerge(self, lines):
"""Merges all connected lines from a source
The source may be a MultiLineString, a sequence of LineString objects,
or a sequence of objects than can be adapted to LineStrings. Returns a
LineString or MultiLineString when lines are not contiguous.
"""
source = None
if hasattr(lines, "type") and lines.type == "MultiLineString":
source = lines
elif hasattr(lines, "__iter__"):
try:
source = asMultiLineString([ls.coords for ls in lines])
except AttributeError:
source = asMultiLineString(lines)
if source is None:
raise ValueError("Cannot linemerge %s" % lines)
result = lgeos.GEOSLineMerge(source._geom)
return geom_factory(result)
开发者ID:gepcel,项目名称:Shapely,代码行数:19,代码来源:ops.py
示例19: shared_paths
def shared_paths(g1, g2):
"""Find paths shared between the two given lineal geometries
Returns a GeometryCollection with two elements:
- First element is a MultiLineString containing shared paths with the
same direction for both inputs.
- Second element is a MultiLineString containing shared paths with the
opposite direction for the two inputs.
Parameters
----------
g1 : geometry
The first geometry
g2 : geometry
The second geometry
"""
if not isinstance(g1, LineString):
raise TypeError("First geometry must be a LineString")
if not isinstance(g2, LineString):
raise TypeError("Second geometry must be a LineString")
return(geom_factory(lgeos.methods['shared_paths'](g1._geom, g2._geom)))
开发者ID:aashish24,项目名称:Shapely,代码行数:21,代码来源:ops.py
示例20: single_sided_buffer
def single_sided_buffer(self, distance, leftSide, resolution=16, joinStyle=1, mitreLimit=1.0):
"""Returns a LineString or MultiLineString geometry at a distance from the object
on its right or its left side.
Distance must be positive. The side is given by the leftSide parameter.
True => LEFT, False => RIGHT
The resolution of the buffer around each vertex of the object increases
by increasing the resolution keyword parameter or third positional parameter.
The join style is for outside corners between line segments.
Values are 1 => ROUND, 2 => MITRE, 3 => BEVEL.
The mitre ratio limit is used for very sharp corners.
It is the ratio of the distance from the corner to the end of the mitred offset
corner. When two line segments meet at a sharp angle, a miter join will extend
far beyond the original geometry. To prevent unreasonable geometry, the mitre
limit allows controlling the maximum length of the join corner.
Corners with a ratio which exceed the limit will be beveled.
"""
try:
return geom_factory(self.impl['single_sided_buffer'](self, distance, resolution, joinStyle, mitreLimit, leftSide))
except WindowsError:
raise TopologicalError()
开发者ID:BertrandGervais,项目名称:shapely,代码行数:21,代码来源:linestring.py
注:本文中的shapely.geometry.base.geom_factory函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论