本文整理汇总了Python中shapely.wkt.load_wkt函数的典型用法代码示例。如果您正苦于以下问题:Python load_wkt函数的具体用法?Python load_wkt怎么用?Python load_wkt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_wkt函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_scale
def test_scale(self):
ls = load_wkt('LINESTRING(240 400 10, 240 300 30, 300 300 20)')
# test defaults of 1.0
sls = transform.scale(ls)
self.assertTrue(sls.equals(ls))
# different scaling in different dimensions
sls = transform.scale(ls, 2, 3, 0.5)
els = load_wkt('LINESTRING(210 500 5, 210 200 15, 330 200 10)')
self.assertTrue(sls.equals(els))
# Do explicit 3D check of coordinate values
for a, b in zip(sls.coords, els.coords):
for ap, bp in zip(a, b):
self.assertEqual(ap, bp)
# retest with named parameters for the same result
sls = transform.scale(geom=ls, xfact=2, yfact=3, zfact=0.5,
origin='center')
self.assertTrue(sls.equals(els))
## other `origin` parameters
# around the centroid
sls = transform.scale(ls, 2, 3, 0.5, origin='centroid')
els = load_wkt('LINESTRING(228.75 537.5, 228.75 237.5, 348.75 237.5)')
self.assertTrue(sls.equals(els))
# around the second coordinate tuple
sls = transform.scale(ls, 2, 3, 0.5, origin=ls.coords[1])
els = load_wkt('LINESTRING(240 600, 240 300, 360 300)')
self.assertTrue(sls.equals(els))
# around some other 3D Point of origin
sls = transform.scale(ls, 2, 3, 0.5, origin=Point(100, 200, 1000))
els = load_wkt('LINESTRING(380 800 505, 380 500 515, 500 500 510)')
self.assertTrue(sls.equals(els))
# Do explicit 3D check of coordinate values
for a, b in zip(sls.coords, els.coords):
for ap, bp in zip(a, b):
self.assertEqual(ap, bp)
示例2: test_affine_geom_types
def test_affine_geom_types(self):
# identity matrices, which should result with no transformation
matrix2d = (1, 0,
0, 1,
0, 0)
matrix3d = (1, 0, 0,
0, 1, 0,
0, 0, 1,
0, 0, 0)
# empty in, empty out
empty2d = load_wkt('MULTIPOLYGON EMPTY')
self.assertTrue(affinity.affine_transform(empty2d, matrix2d).is_empty)
def test_geom(g2, g3=None):
self.assertFalse(g2.has_z)
a2 = affinity.affine_transform(g2, matrix2d)
self.assertFalse(a2.has_z)
self.assertTrue(g2.equals(a2))
if g3 is not None:
self.assertTrue(g3.has_z)
a3 = affinity.affine_transform(g3, matrix3d)
self.assertTrue(a3.has_z)
self.assertTrue(g3.equals(a3))
return
pt2d = load_wkt('POINT(12.3 45.6)')
pt3d = load_wkt('POINT(12.3 45.6 7.89)')
test_geom(pt2d, pt3d)
ls2d = load_wkt('LINESTRING(0.9 3.4, 0.7 2, 2.5 2.7)')
ls3d = load_wkt('LINESTRING(0.9 3.4 3.3, 0.7 2 2.3, 2.5 2.7 5.5)')
test_geom(ls2d, ls3d)
test_geom(load_wkt('POLYGON((0.9 2.3, 0.5 1.1, 2.4 0.8, 0.9 2.3), '
'(1.1 1.7, 0.9 1.3, 1.4 1.2, 1.1 1.7), '
'(1.6 1.3, 1.7 1, 1.9 1.1, 1.6 1.3))'))
test_geom(load_wkt(
'MULTIPOINT ((-300 300), (700 300), (-800 -1100), (200 -300))'))
test_geom(load_wkt(
'MULTILINESTRING((0 0, -0.7 -0.7, 0.6 -1), '
'(-0.5 0.5, 0.7 0.6, 0 -0.6))'))
test_geom(load_wkt(
'MULTIPOLYGON(((900 4300, -1100 -400, 900 -800, 900 4300)), '
'((1200 4300, 2300 4400, 1900 1000, 1200 4300)))'))
# GeometryCollection fails, since it does not have a good constructor
gc = load_wkt('GEOMETRYCOLLECTION(POINT(20 70),'
' POLYGON((60 70, 13 35, 60 -30, 60 70)),'
' LINESTRING(60 70, 50 100, 80 100))')
self.assertRaises(TypeError, test_geom, gc) # TODO: fix this
示例3: findCenters
def findCenters(newickFile, switchLo, switchHi, lossLo, lossHi):
"""This function takes as input a .newick file in the form
<filename>.newick, and low and high values for costscape for both
switches and losses. It returns a list of the centroids of each region in
the costscape associated with the given .newick file."""
hostTree, parasiteTree, phi = newickFormatReader(newickFile)
CVlist = reconcile.reconcile(parasiteTree, hostTree, phi, switchLo,
switchHi, lossLo, lossHi)
coordList = plotcosts.plotcosts(CVlist, lossLo, lossHi, switchLo,
switchHi, "", False, False)
polygonList = getNewCoordList(newickFile, switchLo, switchHi, lossLo,
lossHi)
pointList = []
for i in range(len(polygonList)):
point = polygonList[i]
numCommas = point.count(",")
if numCommas > 1:
# polygon case
region = load_wkt(point)
pointList.append(region.centroid.wkt)
elif numCommas == 1:
# line case
x1 = coordList[i][0][0]
y1 = coordList[i][0][1]
x2 = coordList[i][1][0]
y2 = coordList[i][1][1]
midx = (x1 + x2) * 1.0 / 2
midy = (y1 + y2) * 1.0 / 2
pointList.append("POINT ({} {})".format(str(midx), str(midy)))
else:
# point case
pointList.append("POINT {}".format(str(coordList[i][0])))
return pointList
示例4: create_from_wkt
def create_from_wkt(self, wkt, item_type, ingest_source, **attributes):
'''
Create a single vector in the vector service
Args:
wkt (str): wkt representation of the geometry
item_type (str): item_type of the vector
ingest_source (str): source of the vector
attributes: a set of key-value pairs of attributes
Returns:
id (str): string identifier of the vector created
'''
# verify the "depth" of the attributes is single layer
geojson = load_wkt(wkt).__geo_interface__
vector = {
'type': "Feature",
'geometry': geojson,
'properties': {
'item_type': item_type,
'ingest_source': ingest_source,
'attributes': attributes
}
}
return self.create(vector)[0]
示例5: standardize_polygons_str
def standardize_polygons_str(data_str):
"""Given a POLYGON string, standardize the coordinates to a 1x1 grid.
Input : data_str (taken from above)
Output: tuple of polygon objects
"""
# find all of the polygons in the letter (for instance an A
# needs to be constructed from 2 polygons)
path_strs = re.findall("\(\(([^\)]+?)\)\)", data_str.strip())
# convert the data into a numpy array
polygons_data = []
for path_str in path_strs:
data = np.array([
tuple(map(float, x.split())) for x in path_str.strip().split(",")])
polygons_data.append(data)
# standardize the coordinates
min_coords = np.vstack(data.min(0) for data in polygons_data).min(0)
max_coords = np.vstack(data.max(0) for data in polygons_data).max(0)
for data in polygons_data:
data[:, ] -= min_coords
data[:, ] /= (max_coords - min_coords)
polygons = []
for data in polygons_data:
polygons.append(load_wkt(
"POLYGON((%s))" % ",".join(" ".join(map(str, x)) for x in data)))
return tuple(polygons)
示例6: test_translate
def test_translate(self):
ls = load_wkt('LINESTRING(240 400 10, 240 300 30, 300 300 20)')
# test default offset of 0.0
tls = transform.translate(ls)
self.assertTrue(tls.equals(ls))
# test all offsets
tls = transform.translate(ls, 100, 400, -10)
els = load_wkt('LINESTRING(340 800 0, 340 700 20, 400 700 10)')
self.assertTrue(tls.equals(els))
# Do explicit 3D check of coordinate values
for a, b in zip(tls.coords, els.coords):
for ap, bp in zip(a, b):
self.assertEqual(ap, bp)
# retest with named parameters for the same result
tls = transform.translate(geom=ls, xoff=100, yoff=400, zoff=-10)
self.assertTrue(tls.equals(els))
示例7: _load_geometry
def _load_geometry(self, wkb_or_wkt):
try:
return load_wkb(wkb_or_wkt)
except:
try:
return load_wkt(wkb_or_wkt)
except:
return None
示例8: test_affine_2d
def test_affine_2d(self):
g = load_wkt('LINESTRING(2.4 4.1, 2.4 3, 3 3)')
# custom scale and translate
expected2d = load_wkt('LINESTRING(-0.2 14.35, -0.2 11.6, 1 11.6)')
matrix2d = (2, 0,
0, 2.5,
-5, 4.1)
a2 = transform.affine(g, matrix2d)
self.assertTrue(a2.almost_equals(expected2d))
self.assertFalse(a2.has_z)
# Make sure a 3D matrix does not make a 3D shape from a 2D input
matrix3d = (2, 0, 0,
0, 2.5, 0,
0, 0, 10,
-5, 4.1, 100)
a3 = transform.affine(g, matrix3d)
self.assertTrue(a3.almost_equals(expected2d))
self.assertFalse(a3.has_z)
示例9: test_affine_params
def test_affine_params(self):
g = load_wkt('LINESTRING(2.4 4.1, 2.4 3, 3 3)')
self.assertRaises(
TypeError, affinity.affine_transform, g, None)
self.assertRaises(
TypeError, affinity.affine_transform, g, '123456')
self.assertRaises(ValueError, affinity.affine_transform, g,
[1, 2, 3, 4, 5, 6, 7, 8, 9])
self.assertRaises(AttributeError, affinity.affine_transform, None,
[1, 2, 3, 4, 5, 6])
示例10: _load_geometry
def _load_geometry(self, geometry_spec):
if isinstance(geometry_spec, BaseGeometry):
return geometry_spec
try:
return load_wkb(geometry_spec)
except:
try:
return load_wkt(geometry_spec)
except:
return None
示例11: test_rotate
def test_rotate(self):
ls = load_wkt('LINESTRING(240 400, 240 300, 300 300)')
# counter-clockwise degrees
rls = transform.rotate(ls, 90)
els = load_wkt('LINESTRING(220 320, 320 320, 320 380)')
self.assertTrue(rls.equals(els))
# retest with named parameters for the same result
rls = transform.rotate(geom=ls, angle=90, origin='center')
self.assertTrue(rls.equals(els))
# clockwise radians
rls = transform.rotate(ls, -pi/2, use_radians=True)
els = load_wkt('LINESTRING(320 380, 220 380, 220 320)')
self.assertTrue(rls.equals(els))
## other `origin` parameters
# around the centroid
rls = transform.rotate(ls, 90, origin='centroid')
els = load_wkt('LINESTRING(182.5 320, 282.5 320, 282.5 380)')
self.assertTrue(rls.equals(els))
# around the second coordinate tuple
rls = transform.rotate(ls, 90, origin=ls.coords[1])
els = load_wkt('LINESTRING(140 300, 240 300, 240 360)')
self.assertTrue(rls.equals(els))
# around the absolute Point of origin
rls = transform.rotate(ls, 90, origin=Point(0,0))
els = load_wkt('LINESTRING(-400 240, -300 240, -300 300)')
self.assertTrue(rls.equals(els))
示例12: test_seed_with_geom
def test_seed_with_geom(self):
if not load_wkt: raise SkipTest('no shapely installed')
# box from 10 10 to 80 80 with small spike/corner to -10 60 (upper left)
geom = load_wkt("POLYGON((10 10, 10 50, -10 60, 10 80, 80 80, 80 10, 10 10))")
task = self.make_geom_task(geom, SRS(4326), [0, 1, 2, 3, 4])
seeder = TileWalker(task, self.seed_pool, handle_uncached=True)
seeder.walk()
eq_(len(self.seed_pool.seeded_tiles), 5)
eq_(self.seed_pool.seeded_tiles[0], set([(0, 0)]))
eq_(self.seed_pool.seeded_tiles[1], set([(0, 0), (1, 0)]))
eq_(self.seed_pool.seeded_tiles[2], set([(1, 1), (2, 1)]))
eq_(self.seed_pool.seeded_tiles[3], set([(4, 2), (5, 2), (4, 3), (5, 3), (3, 3)]))
eq_(len(self.seed_pool.seeded_tiles[4]), 4*4+2)
示例13: test_scalerotatetranslate
def test_scalerotatetranslate(self):
ls = load_wkt('LINESTRING(240 400 10, 240 300 30, 300 300 20)')
# test defaults
tls = transform.translate(ls)
self.assertTrue(tls.equals(ls))
# test all three
tls = transform.scalerotatetranslate(ls, 2, 3, 0.5, 30,
100, 400, -10)
els = load_wkt('LINESTRING(243.03847577293368 849.9038105676659 -5, '\
'393.0384757729336200 590.0961894323343100 5, '\
'496.9615242270662600 650.0961894323343100 0)')
self.assertTrue(tls.almost_equals(els))
# Do explicit 3D check of coordinate values
for a, b in zip(tls.coords, els.coords):
for ap, bp in zip(a, b):
self.assertEqual(ap, bp)
# recheck with named parameters
tls = transform.scalerotatetranslate(geom=ls, xfact=2, yfact=3,
zfact=0.5, angle=30,
xoff=100, yoff=400, zoff=-10,
origin='center', use_radians=False)
self.assertTrue(tls.almost_equals(els))
# test scale and rotate in radians
tls = transform.scalerotatetranslate(ls, 2, 3, 0.5, pi/6,
use_radians=True)
els = load_wkt('LINESTRING(143.03847577293368 449.90381056766591, '\
'293.0384757729336200 190.0961894323343100, '\
'396.9615242270662600 250.0961894323343100)')
self.assertTrue(tls.almost_equals(els))
# test offsets only
tls = transform.scalerotatetranslate(ls, xoff=100, yoff=400, zoff=-10)
els = load_wkt('LINESTRING(340 800, 340 700, 400 700)')
self.assertTrue(tls.almost_equals(els))
# Do explicit 3D check of coordinate values
for a, b in zip(tls.coords, els.coords):
for ap, bp in zip(a, b):
self.assertEqual(ap, bp)
示例14: _load_geometry
def _load_geometry(self, geometry_spec):
if isinstance(geometry_spec, BaseGeometry):
return geometry_spec
if isinstance(geometry_spec, dict):
return SimpleShape(geometry_spec['coordinates'],
geometry_spec["type"])
try:
return load_wkb(geometry_spec)
except Exception:
try:
return load_wkt(geometry_spec)
except Exception:
return None
示例15: test_affine_3d
def test_affine_3d(self):
g2 = load_wkt('LINESTRING(2.4 4.1, 2.4 3, 3 3)')
g3 = load_wkt('LINESTRING(2.4 4.1 100.2, 2.4 3 132.8, 3 3 128.6)')
# custom scale and translate
matrix2d = (2, 0,
0, 2.5,
-5, 4.1)
matrix3d = (2, 0, 0,
0, 2.5, 0,
0, 0, 0.3048,
-5, 4.1, 100)
# Combinations of 2D and 3D geometries and matrices
a22 = transform.affine(g2, matrix2d)
a23 = transform.affine(g2, matrix3d)
a32 = transform.affine(g3, matrix2d)
a33 = transform.affine(g3, matrix3d)
# Check dimensions
self.assertFalse(a22.has_z)
self.assertFalse(a23.has_z)
self.assertTrue(a32.has_z)
self.assertTrue(a33.has_z)
# 2D equality checks
expected2d = load_wkt('LINESTRING(-0.2 14.35, -0.2 11.6, 1 11.6)')
expected3d = load_wkt('LINESTRING(-0.2 14.35 130.54096, '\
'-0.2 11.6 140.47744, 1 11.6 139.19728)')
expected32 = load_wkt('LINESTRING(-0.2 14.35 100.2, '\
'-0.2 11.6 132.8, 1 11.6 128.6)')
self.assertTrue(a22.almost_equals(expected2d))
self.assertTrue(a23.almost_equals(expected2d))
# Do explicit 3D check of coordinate values
for a, e in zip(a32.coords, expected32.coords):
for ap, ep in zip(a, e):
self.assertAlmostEqual(ap, ep)
for a, e in zip(a33.coords, expected3d.coords):
for ap, ep in zip(a, e):
self.assertAlmostEqual(ap, ep)