def convert_polygons_to_centroids(V): """Convert polygon vector data to point vector data Input V: Vector layer with polygon data Output Vector layer with point data and the same attributes as V """ msg = "Input data %s must be polygon vector data" % V assert V.is_polygon_data, msg geometry = V.get_geometry() N = len(V) # Calculate centroids for each polygon centroids = [] for i in range(N): c = calculate_polygon_centroid(geometry[i]) centroids.append(c) # Create new point vector layer with same attributes and return V = Vector( data=V.get_data(), projection=V.get_projection(), geometry=centroids, name="%s_centroid_data" % V.get_name(), keywords=V.get_keywords(), ) return V
def convert_polygons_to_centroids(V): """Convert polygon vector data to point vector data Input V: Vector layer with polygon data Output Vector layer with point data and the same attributes as V """ msg = 'Input data %s must be polygon vector data' % V assert V.is_polygon_data, msg geometry = V.get_geometry() N = len(V) # Calculate centroids for each polygon centroids = [] for i in range(N): c = calculate_polygon_centroid(geometry[i]) centroids.append(c) # Create new point vector layer with same attributes and return V = Vector(data=V.get_data(), projection=V.get_projection(), geometry=centroids, name='%s_centroid_data' % V.get_name(), keywords=V.get_keywords()) return V