Graphics Reference
In-Depth Information
self.add(info, 'tot_line_length',
int(calculator.measure(geometry)/1000))
elif geometry.type() == QGis.Polygon:
self.add(info, 'num_polygons', 1)
self.add(info, 'tot_poly_area',
int(calculator.measure(geometry)/1000000))
self.add(info, 'tot_poly_perimeter',
int(calculator.measurePerimeter(geometry)/1000))
As you can see, we're simply dividing the calculated lengths by a thousand to get the
length in kilometers, and dividing the calculated area by a million to get the area in square
kilometers.
The final thing we want to do is display those calculated statistics in a more friendly way.
To do this, replace the QMessageBox.information() call at the end of your can-
vasReleaseEvent() method with the following:
fields = [("num_multi",
"Number of multipart geometries", ""),
("num_points",
"Number of point geometries", ""),
("num_lines",
"Number of line geometries", ""),
("tot_line_length",
"Total length of line geometries",
"km"),
("num_polygons",
"Number of polygon geometries", ""),
("tot_poly_area",
"Total area of polygon geometries",
"square km"),
("tot_poly_perimeter",
"Total perimeter of polygon geometries",
"km")]
results = []
for field,label,suffix in fields:
if field in info:
results.append("%s = %s %s" %
Search WWH ::




Custom Search