当前位置: 首页>>代码示例>>Python>>正文


Python Polygon.distance方法代码示例

本文整理汇总了Python中shapely.geometry.Polygon.distance方法的典型用法代码示例。如果您正苦于以下问题:Python Polygon.distance方法的具体用法?Python Polygon.distance怎么用?Python Polygon.distance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在shapely.geometry.Polygon的用法示例。


在下文中一共展示了Polygon.distance方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: iter_chars_on_line

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import distance [as 别名]
def iter_chars_on_line(chars, line, start_len, step=0.6):
    '''
    Yields single character geometries placed on line.

    :param chars: iterable generated by ``generate_char_geoms``
    :param line: :class:`shapely.geometry.LineString`
    :param start_len: length or start position on line as int or float
    :param step: distance a character is moved on line at each iteration
        (decrease for more accuracy and increase for faster rendering)

    :yields: character geometries as :class:`shapely.geometry.MultiLineString`
    '''

    # make sure first character is not rendered directly at the edge of the line
    cur_len = max(start_len, 1)
    # geometry containing path of all rotated characters
    text_geom = Polygon()
    for paths, width, spacing in chars:
        cur_len += spacing
        last_rad = None
        for _ in xrange(30):
            # get current position on line
            pos = line.interpolate(cur_len)
            # get radians of gradient
            rad = linestring_char_radians(line, cur_len, width)
            #: only rotate if radians changed
            if rad != last_rad:
                rot_coords = tuple(tuple(rotate_coords(geom, rad))
                    for geom in paths)
            last_rad = rad
            # move rotated char to current position
            rot = MultiPolygon(tuple(
                Polygon(tuple(translate_coords(c, pos.x, pos.y)))
                for c in rot_coords
            ))
            # check whether distance to previous characters is long enough
            if (
                text_geom.distance(rot) >= spacing
                or text_geom.geom_type == 'GeometryCollection'
            ):
                text_geom = text_geom.union(rot)
                cur_len += width
                yield rot
                break
            cur_len += step
开发者ID:ahojnnes,项目名称:mapython,代码行数:47,代码来源:utils.py

示例2: zip

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import distance [as 别名]
for park_bureau,bureau_color in zip(park_bureaus, bureau_colors):
    park_json_file = open(park_bureau + '.geojson')
    park_json_data = load(park_json_file)

    park_features = park_json_data['features']

    for park_feature in park_features:
        coordinates = chain.from_iterable(park_feature['geometry']['coordinates'])

        park_polygon = Polygon(map(tuple, coordinates))

        min_distance = sys.maxsize
        min_name = ""
        for amtrak_station in amtrak_stations:
            distance = park_polygon.distance(amtrak_station['coordinates'])

            if distance < min_distance:
                min_distance = distance
                min_name = amtrak_station['station_name']

	if park_feature['properties']['NAME1'] is not None :
		park_name = park_feature['properties']['NAME1']
	else :
		park_name = ""

	park_feature['properties'] = {}
	
	park_feature['properties']['description'] = park_name + "<br>"
        park_feature['properties']['description'] += "Closest Station: " + min_name + "<br>"
	    
开发者ID:bobschriver,项目名称:amtrak-nationalparks,代码行数:31,代码来源:calculate-distance.py

示例3: zip

# 需要导入模块: from shapely.geometry import Polygon [as 别名]
# 或者: from shapely.geometry.Polygon import distance [as 别名]
wr.field('x',fieldType='N',size=20,decimal=3)
wr.field('y',fieldType='N',size=20,decimal=3)
for [x,y] in valid_points:
    wr.poly([[[x,y]]],shapeType=shapefile.POINT)
    wr.record([x,y])
wr.save('shapes\\nexrad_points')    


#--write a nearest-neighbor nexrad shapefile
wr = shapefile.writer_like(shapename_nex)
wr.field('group',fieldType='N',size=2,decimal=0)
pmap = {}
for shape,poly,record in zip(nexrad_shapes,nexrad_polygons,nexrad_records):
    imin,dist = None,1.0e+30
    for i,v in enumerate(valid_Points):
        d = poly.distance(v)
        if d < dist:
            dist = d
            imin = i
    if imin in pmap.keys():
        pmap[imin].append(record[0])
    else:
        pmap[imin] = [record[0]]            
    wr.poly([shape.points],shapeType=shape.shapeType)
    record.append(imin)
    wr.record(record)
wr.save('shapes\\nexrad_groups')

#--add the grouping to the grid shapefile
wr = shapefile.writer_like(shapename_grid)
wr.field('nex_group',fieldType='N',size=3,decimal=0)
开发者ID:jtwhite79,项目名称:my_python_junk,代码行数:33,代码来源:MD_CWM_pest_setup_nexrad_pixel_params.py


注:本文中的shapely.geometry.Polygon.distance方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。