本文整理汇总了Python中shapely.wkt.load_wkt函数的典型用法代码示例。如果您正苦于以下问题:Python load_wkt函数的具体用法?Python load_wkt怎么用?Python load_wkt使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了load_wkt函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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)
开发者ID:tarsh,项目名称:shapely,代码行数:34,代码来源:test_transform.py
示例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
开发者ID:SiggyF,项目名称:Shapely,代码行数:49,代码来源:test_affinity.py
示例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
开发者ID:dmsm,项目名称:CompBioSummer2015,代码行数:35,代码来源:costscapeScore.py
示例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]
开发者ID:DigitalGlobe,项目名称:gbdxtools,代码行数:27,代码来源:vectors.py
示例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)
开发者ID:annashcherbina,项目名称:dragonn,代码行数:30,代码来源:plot.py
示例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))
开发者ID:tarsh,项目名称:shapely,代码行数:16,代码来源:test_transform.py
示例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
开发者ID:JulieGoldberg,项目名称:mapbox-vector-tile,代码行数:8,代码来源:encoder.py
示例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)
开发者ID:tarsh,项目名称:shapely,代码行数:18,代码来源:test_transform.py
示例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])
开发者ID:Bmcalpine,项目名称:Shapely,代码行数:10,代码来源:test_affinity.py
示例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
开发者ID:geometalab,项目名称:Vector-Tiles-Reader-QGIS-Plugin,代码行数:11,代码来源:encoder.py
示例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))
开发者ID:tarsh,项目名称:shapely,代码行数:26,代码来源:test_transform.py
示例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)
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:14,代码来源:test_seed.py
示例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)
开发者ID:tarsh,项目名称:shapely,代码行数:37,代码来源:test_transform.py
示例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
开发者ID:ptpt,项目名称:mapbox-vector-tile,代码行数:15,代码来源:encoder.py
示例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)
开发者ID:tarsh,项目名称:shapely,代码行数:36,代码来源:test_transform.py
示例16: test_skew
def test_skew(self):
ls = load_wkt('LINESTRING(240 400 10, 240 300 30, 300 300 20)')
# test default shear angles of 0.0
sls = transform.skew(ls)
self.assertTrue(sls.equals(ls))
# different shearing in x- and y-directions
sls = transform.skew(ls, 15, -30)
els = load_wkt('LINESTRING (253.39745962155615 417.3205080756888, '\
'226.60254037844385 317.3205080756888, '\
'286.60254037844385 282.67949192431126)')
self.assertTrue(sls.almost_equals(els))
# retest with radians for the same result
sls = transform.skew(ls, pi/12, -pi/6, use_radians=True)
self.assertTrue(sls.almost_equals(els))
# retest with named parameters for the same result
sls = transform.skew(geom=ls, xs=15, ys=-30,
origin='center', use_radians=False)
self.assertTrue(sls.almost_equals(els))
## other `origin` parameters
# around the centroid
sls = transform.skew(ls, 15, -30, origin='centroid')
els = load_wkt('LINESTRING(258.42150697963973 406.49519052838332, '\
'231.6265877365273980 306.4951905283833185, '\
'291.6265877365274264 271.8541743770057337)')
self.assertTrue(sls.almost_equals(els))
# around the second coordinate tuple
sls = transform.skew(ls, 15, -30, origin=ls.coords[1])
els = load_wkt('LINESTRING(266.7949192431123038 400, 240 300, '\
'300 265.3589838486224153)')
self.assertTrue(sls.almost_equals(els))
# around the absolute Point of origin
sls = transform.skew(ls, 15, -30, origin=Point(0,0))
els = load_wkt('LINESTRING(347.179676972449101 261.435935394489832, '\
'320.3847577293367976 161.4359353944898317, '\
'380.3847577293367976 126.7949192431122754)')
self.assertTrue(sls.almost_equals(els))
开发者ID:tarsh,项目名称:shapely,代码行数:36,代码来源:test_transform.py
示例17: _loadGeometry
def _loadGeometry(self, geometrySpec):
"""
A private method to convert a (E)WKB or (E)WKT to a Shapely geometry.
"""
if type(geometrySpec) is str and geometrySpec.startswith('POLYGON Z'):
try:
geometry = load_wkt(geometrySpec)
except Exception:
geometry = None
else:
try:
geometry = load_wkb(geometrySpec)
except Exception:
geometry = None
if geometry is None:
raise ValueError('Failed to convert WKT or WKB to a Shapely geometry')
return geometry
开发者ID:loicgasser,项目名称:quantized-mesh-tile,代码行数:19,代码来源:topology.py
示例18: test_seed_with_res_list
def test_seed_with_res_list(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))")
self.grid = TileGrid(SRS(4326), bbox=[-180, -90, 180, 90],
res=[360/256, 360/720, 360/2000, 360/5000, 360/8000])
self.tile_mgr = TileManager(self.grid, MockCache(), [self.source], 'png')
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.grid.grid_sizes[1], (3, 2))
eq_(self.seed_pool.seeded_tiles[1], set([(1, 0), (1, 1), (2, 0), (2, 1)]))
eq_(self.grid.grid_sizes[2], (8, 4))
eq_(self.seed_pool.seeded_tiles[2], set([(4, 2), (5, 2), (4, 3), (5, 3), (3, 3)]))
eq_(self.grid.grid_sizes[3], (20, 10))
eq_(len(self.seed_pool.seeded_tiles[3]), 5*5+2)
开发者ID:Anderson0026,项目名称:mapproxy,代码行数:20,代码来源:test_seed.py
示例19: aggregate_query
def aggregate_query(self, searchAreaWkt, agg_def, query=None, start_date=None, end_date=None, count=10, index=default_index):
"""Aggregates results of a query into buckets defined by the 'agg_def' parameter. The aggregations are
represented by dicts containing a 'name' key and a 'terms' key holding a list of the aggregation buckets.
Each bucket element is a dict containing a 'term' key containing the term used for this bucket, a 'count' key
containing the count of items that match this bucket, and an 'aggregations' key containing any child
aggregations.
Args:
searchAreaWkt (str): wkt representation of the geometry
agg_def (str or AggregationDef): the aggregation definitions
query (str): a valid Elasticsearch query string to constrain the items going into the aggregation
start_date (str): either an ISO-8601 date string or a 'now' expression (e.g. "now-6d" or just "now")
end_date (str): either an ISO-8601 date string or a 'now' expression (e.g. "now-6d" or just "now")
count (int): the number of buckets to include in the aggregations (the top N will be returned)
index (str): the index (or alias or wildcard index expression) to run aggregations against, set to None for the entire set of vector indexes
Returns:
results (list): A (usually single-element) list of dict objects containing the aggregation results.
"""
geojson = load_wkt(searchAreaWkt).__geo_interface__
aggs_str = str(agg_def) # could be string or AggregationDef
params = {
"count": count,
"aggs": aggs_str
}
if query:
params['query'] = query
if start_date:
params['start_date'] = start_date
if end_date:
params['end_date'] = end_date
url = self.aggregations_by_index_url % index if index else self.aggregations_url
r = self.gbdx_connection.post(url, params=params, json=geojson)
r.raise_for_status()
return r.json(object_pairs_hook=OrderedDict)['aggregations']
开发者ID:DigitalGlobe,项目名称:gbdxtools,代码行数:41,代码来源:vectors.py
示例20: test_point_on_boundary
def test_point_on_boundary():
"""Point on boundary"""
geom1 = load_wkt("POINT (15 10)")
geom2 = clip_by_rect(geom1, 10, 10, 20, 20)
assert dump_wkt(geom2, rounding_precision=0) == "GEOMETRYCOLLECTION EMPTY"
开发者ID:Toblerity,项目名称:Shapely,代码行数:5,代码来源:test_clip_by_rect.py
注:本文中的shapely.wkt.load_wkt函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论