本文整理汇总了Python中django.contrib.gis.geos.LineString.intersection方法的典型用法代码示例。如果您正苦于以下问题:Python LineString.intersection方法的具体用法?Python LineString.intersection怎么用?Python LineString.intersection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.gis.geos.LineString
的用法示例。
在下文中一共展示了LineString.intersection方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from django.contrib.gis.geos import LineString [as 别名]
# 或者: from django.contrib.gis.geos.LineString import intersection [as 别名]
def post(self, request, *args, **kwargs):
if request.is_ajax:
cur_shp_id = kwargs['pk']
cur_shp = Shapefile.objects.get(id=cur_shp_id)
# check if the statistic has already been calculated
if cur_shp.stat_ditch_area is True:
pass
else:
cur_shp_geom = cur_shp.helperditchesnumber_set.all()
for feature in cur_shp_geom:
# the list that will contains compound's area perimeter pts
area_points_list = []
# [A] get convex hull and its centroid
feat_convex_hull = feature.poly.convex_hull
feat_centroid = feat_convex_hull.centroid
# [B] feature's hull farthest point from centroid
max_point = Point(
feat_convex_hull.extent[2],
feat_convex_hull.extent[3],
srid=3857)
radius = max_point.distance(feat_centroid)
# get vertexes in a circle (center=centroid), every n angle
vertexes_list = get_round_vertex(1, radius,
feat_centroid.x,
feat_centroid.y,
3857)
# for each point in vertex list
for point in vertexes_list:
# create new line between point and centroid
line = LineString(feat_centroid, point, srid=3857)
# line intersects geometry: get point nearest to centroid
try:
intersection_line = line.intersection(feature.poly)
except GEOSException:
pass
if intersection_line.num_coords == 0: # no intersection
pass
# intersection in 1 point
elif intersection_line.num_coords == 1:
area_points_list.append(Point(
intersection_line.coords[0]))
# intersection in 2 or more points
elif intersection_line.num_coords >= 2:
nearest_point = [None, 10000000]
# intersection generates a MultiLineString (> 2 pts)
if intersection_line.geom_type == 'MultiLineString':
for multiline_tuple in intersection_line.tuple:
for coords_tuple in multiline_tuple:
nearest_point = check_nearest_point(
coords_tuple, 3857,
feat_centroid,
nearest_point)
area_points_list.append(nearest_point[0].tuple)
# intersection generates a LineString (2 pts)
else:
for coords_tuple in intersection_line.tuple:
nearest_point = check_nearest_point(
coords_tuple, 3857,
feat_centroid,
nearest_point)
area_points_list.append(nearest_point[0].tuple)
# close polygon, get projected area and save
area_points_list.append(area_points_list[0])
internal_area_polygon = Polygon(area_points_list, srid=3857)
proj_area_polygon = internal_area_polygon
proj_area_polygon.transform(cur_shp.proj)
if feature.type == 'compound':
# recognize open/closed compound
tr = settings.GEOSTAT_SETTINGS['open_compound_treshold']
closed_limit = 360 - ((tr * 360) / 100)
if area_points_list.__len__() > closed_limit:
structure_open = False
else:
structure_open = True
else:
structure_open = None
internal_area_feature = HelperCompoundsArea(
shapefile_id=cur_shp_id,
feature=feature,
poly=internal_area_polygon,
perimeter=internal_area_polygon.length,
storedarea=proj_area_polygon.area,
type=feature.type,
open=structure_open
)
internal_area_feature.save()
cur_shp.stat_ditch_area = True
#.........这里部分代码省略.........