本文整理汇总了Python中shapely.geometry.Point方法的典型用法代码示例。如果您正苦于以下问题:Python geometry.Point方法的具体用法?Python geometry.Point怎么用?Python geometry.Point使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类shapely.geometry
的用法示例。
在下文中一共展示了geometry.Point方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: saveimageWithMask
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def saveimageWithMask(img, outname, mask_poly):
dstimg = copy.deepcopy(img)
for mask in mask_poly:
bound = mask.bounds
if (len(bound) < 4):
continue
xmin, ymin, xmax, ymax = bound[0], bound[1], bound[2], bound[3]
for x in range(int(xmin), int(xmax)):
for y in range(int(ymin), int(ymax)):
point = shgeo.Point(x, y)
if point.within(mask):
#print('withing')
dstimg[int(y)][int(x)] = 0
cv2.imwrite(outname, dstimg)
示例2: removeIgnoredPointsRects
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def removeIgnoredPointsRects(rects,polyList):
ridxs = list(range(len(rects)))
for ridx in range(len(rects)):
points = rects[ridx]["annopoints"][0]["point"]
pidxs = list(range(len(points)))
for pidx in range(len(points)):
pt = geometry.Point(points[pidx]["x"][0], points[pidx]["y"][0])
bIgnore = False
for poidx in range(len(polyList)):
poly = polyList[poidx]
if (poly.contains(pt)):
bIgnore = True
break
if (bIgnore):
pidxs.remove(pidx)
points = [points[pidx] for pidx in pidxs]
if (len(points) > 0):
rects[ridx]["annopoints"][0]["point"] = points
else:
ridxs.remove(ridx)
rects = [rects[ridx] for ridx in ridxs]
return rects
示例3: removeIgnoredPoints
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def removeIgnoredPoints(gtFramesAll,prFramesAll):
imgidxs = []
for imgidx in range(len(gtFramesAll)):
if ("ignore_regions" in gtFramesAll[imgidx].keys() and
len(gtFramesAll[imgidx]["ignore_regions"]) > 0):
regions = gtFramesAll[imgidx]["ignore_regions"]
polyList = []
for ridx in range(len(regions)):
points = regions[ridx]["point"]
pointList = []
for pidx in range(len(points)):
pt = geometry.Point(points[pidx]["x"][0], points[pidx]["y"][0])
pointList += [pt]
poly = geometry.Polygon([[p.x, p.y] for p in pointList])
polyList += [poly]
rects = prFramesAll[imgidx]["annorect"]
prFramesAll[imgidx]["annorect"] = removeIgnoredPointsRects(rects,polyList)
rects = gtFramesAll[imgidx]["annorect"]
gtFramesAll[imgidx]["annorect"] = removeIgnoredPointsRects(rects,polyList)
return gtFramesAll, prFramesAll
示例4: test_vector_concurrent
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def test_vector_concurrent():
def _work(i):
point, = r1.iter_data(None)
return point
ds = buzz.Dataset(max_active=4)
meta = dict(
type='point',
)
p = mp.pool.ThreadPool(4)
with ds.acreate_vector('/tmp/v1.shp', **meta).delete as r1:
pt = sg.Point([42, 45])
r1.insert_data(pt)
r1.deactivate()
points = list(p.map(_work, range(1000)))
assert all(p == pt for p in points)
assert (ds._back.idle_count(), ds._back.used_count(), ds.active_count) == (4, 0, 4)
assert (ds._back.idle_count(r1._back.uid), ds._back.used_count(r1._back.uid), r1.active_count, r1.active) == (4, 0, 4, True)
p.terminate()
示例5: test_points
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def test_points(fps1px):
"""Test points at fps.E's points of interest"""
fps = fps1px
assert fpeq(
fps.E,
fps.AI.intersection(sg.Point(*fps.E.c)),
fps.AI.intersection(sg.Point(*fps.E.t)),
fps.AI.intersection(sg.Point(*fps.E.l)),
fps.AI.intersection(sg.Point(*fps.E.tl)),
)
assert fpeq(
fps.I,
fps.AI.intersection(sg.Point(*fps.E.br)),
)
assert fpeq(
fps.H,
fps.AI.intersection(sg.Point(*fps.E.bl)),
fps.AI.intersection(sg.Point(*fps.E.b)),
)
assert fpeq(
fps.F,
fps.AI.intersection(sg.Point(*fps.E.tr)),
fps.AI.intersection(sg.Point(*fps.E.r)),
)
示例6: _any_geom_to_shapely
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def _any_geom_to_shapely(geom):
"""Any geom to shapely object. Points should have homogeneous dimensions size."""
if isinstance(geom, (sg.LineString, sg.Point, sg.Polygon, sg.MultiPolygon)):
return geom
if isinstance(geom, dict):
return sg.shape(geom['geometry'])
if isinstance(geom, collections.Container):
geom = np.asarray(geom)
if geom.ndim == 1:
return sg.Point(geom.tolist())
elif geom.ndim == 2:
return sg.LineString(geom.tolist())
elif geom.ndim == 3:
return sg.Polygon(*geom.tolist())
elif geom.ndim == 4:
return sg.MultiPolygon([
sg.Polygon(*poly)
for poly in geom.tolist()
])
assert False
示例7: get_autocomplete
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def get_autocomplete(
query: QueryParams = Depends(QueryParams), extra: ExtraParams = Body(ExtraParams())
):
async def get_intentions():
if not query.nlu or query.lang not in nlu_allowed_languages:
return None
focus = None
if query.lon and query.lat:
focus = Point(query.lon, query.lat)
return await nlu_client.get_intentions(text=query.q, lang=query.lang, focus=focus)
autocomplete_response, intentions = await asyncio.gather(
bragi_client.autocomplete(query, extra), get_intentions()
)
if intentions is not None:
autocomplete_response["intentions"] = intentions
return autocomplete_response
示例8: convert_pix_lstring_to_geo
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def convert_pix_lstring_to_geo(wkt_lstring, im_file):
'''Convert linestring in pixel coords to geo coords'''
shape = wkt_lstring # shapely.wkt.loads(lstring)
x_pixs, y_pixs = shape.coords.xy
coords_latlon = []
coords_utm = []
for (x, y) in zip(x_pixs, y_pixs):
lon, lat = apls_utils.pixelToGeoCoord(x, y, im_file)
[utm_east, utm_north, utm_zone, utm_letter] = utm.from_latlon(lat, lon)
coords_utm.append([utm_east, utm_north])
coords_latlon.append([lon, lat])
lstring_latlon = LineString([Point(z) for z in coords_latlon])
lstring_utm = LineString([Point(z) for z in coords_utm])
return lstring_latlon, lstring_utm, utm_zone, utm_letter
###############################################################################
示例9: make_record
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def make_record(properties: Dict[str, type], load_num: str, tree_row: Dict[str, str], point: Dict[str, str]):
"""
shp 파일에 입력할 수목 정보 생성
:return:
"""
# 레코드 기본 구조
record = {'properties': {"탐방로": load_num}, 'geometry': None}
# 수목 정보 입력
for key, value in zip(tree_row.keys(), tree_row.values()):
atr_type = properties[key]
# 속성 타입이 int인데 속성값이 ''일 경우 0으로 입력
record['properties'][key] = atr_type(value) if value or atr_type is str else 0
# 위치정보 입력
record['properties']['경도'] = point['경도']
record['properties']['위도'] = point['위도']
record['properties']['고도'] = point['고도']
record['geometry'] = mapping(Point(point['경도'], point['위도']))
return record
示例10: test_filter_heads
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def test_filter_heads(self):
f = get_demo_file('glacier.svg')
coords = read_svgcoords(f)
polygon = shpg.Polygon(coords)
hidx = np.array([3, 9, 80, 92, 108, 116, 170, len(coords)-12])
heads = [shpg.Point(*c) for c in coords[hidx]]
heads_height = np.array([200, 210, 1000., 900, 1200, 1400, 1300, 250])
radius = 25
_heads, _ = centerlines._filter_heads(heads, heads_height, radius,
polygon)
_headsi, _ = centerlines._filter_heads(heads[::-1],
heads_height[::-1],
radius, polygon)
self.assertEqual(_heads, _headsi[::-1])
self.assertEqual(_heads, [heads[h] for h in [2, 5, 6, 7]])
示例11: _projection_point
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def _projection_point(centerline, point):
"""Projects a point on a line and returns the closest integer point
guaranteed to be on the line, and guaranteed to be far enough from the
head and tail.
Parameters
----------
centerline : Centerline instance
point : Shapely Point geometry
Returns
-------
(flow_point, ind_closest): Shapely Point and indice in the line
"""
prdis = centerline.line.project(point, normalized=False)
ind_closest = np.argmin(np.abs(centerline.dis_on_line - prdis)).item()
flow_point = shpg.Point(centerline.line.coords[int(ind_closest)])
return flow_point
示例12: main
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def main(filename="output.png", img_width=2000, img_height=2000, palette=random.choice(palettes.PALETTES), count=50):
ims = cairo.ImageSurface(cairo.FORMAT_ARGB32, img_width, img_height)
ims.set_fallback_resolution(300.0, 300.0)
ctx = cairo.Context(ims)
# Background
ctx.rectangle(0, 0, img_width, img_height)
ctx.set_source_rgb(*palettes.hex_to_tuple(palette['background']))
ctx.fill()
existing_shapes = Point([(0, 0), (0, 0)])
for i in range(count):
print("Making disc {}".format(i))
existing_shapes = sphere(ctx, random.choice(palette['colors']), img_width, img_height, existing_shapes)
ims.write_to_png(filename)
示例13: main
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def main(filename="output.png", img_width=2000, img_height=2000, palette=random.choice(palettes.PALETTES), count=50):
ims = cairo.ImageSurface(cairo.FORMAT_ARGB32, img_width, img_height)
ims.set_fallback_resolution(300.0, 300.0)
ctx = cairo.Context(ims)
# Background
ctx.rectangle(0, 0, img_width, img_height)
ctx.set_source_rgb(*palettes.hex_to_tuple(palette['background']))
ctx.fill()
existing_shapes = Point([(0, 0), (0, 0)])
for i in range(count):
print("Making sphere {}".format(i))
existing_shapes = sphere(ctx, random.choice(palette['colors']), img_width, img_height, existing_shapes)
ims.write_to_png(filename)
示例14: main
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def main(filename="output.png", img_width=IMG_WIDTH, img_height=IMG_HEIGHT, palette=random.choice(palettes.PALETTES), count=50, line_width=80):
ims = cairo.ImageSurface(cairo.FORMAT_ARGB32, img_width, img_height)
ims.set_fallback_resolution(300.0, 300.0)
ctx = cairo.Context(ims)
# Background
ctx.rectangle(0, 0, img_width, img_height)
ctx.set_source_rgb(*palettes.hex_to_tuple(palette['background']))
ctx.fill()
existing_shapes = Point([(0, 0), (0, 0)])
for i in range(count):
print("Making bar {}".format(i))
existing_shapes = bar(ctx, random.choice(
palette['colors']), line_width, img_width, img_height, existing_shapes)
ims.write_to_png(filename)
示例15: nearest_neighbor_within
# 需要导入模块: from shapely import geometry [as 别名]
# 或者: from shapely.geometry import Point [as 别名]
def nearest_neighbor_within(others, point, max_distance):
"""Find nearest point among others up to a maximum distance.
Args:
others: a list of Points or a MultiPoint
point: a Point
max_distance: maximum distance to search for the nearest neighbor
Returns:
A shapely Point if one is within max_distance, None otherwise
"""
search_region = point.buffer(max_distance)
interesting_points = search_region.intersection(MultiPoint(others))
if not interesting_points:
closest_point = None
elif isinstance(interesting_points, Point):
closest_point = interesting_points
else:
distances = [point.distance(ip) for ip in interesting_points
if point.distance(ip) > 0]
closest_point = interesting_points[distances.index(min(distances))]
return closest_point