Measure the Area of Geographic Polygons
Calculate the Area of a Polygon
Write a MySQL query to calculate the area of polygons stored in the GeoData table using ST_Area.
Solution:
-- Calculate and display the area of each polygon stored in the 'area' column of the GeoData table.
SELECT
-- Select the 'name' column to display the name of the geographic entity.
name,
-- Use the ST_Area function to calculate the area of the 'area' column (a POLYGON).
-- The result is aliased as 'areaSize' for clarity.
ST_Area(area) AS areaSize
-- Retrieve data from the GeoData table.
FROM GeoData;
Explanation:
- Purpose of the Query:
- The goal is to compute the area (in square units) of the stored polygons.
- This demonstrates the use of ST_Area for spatial measurement.
- Key Components:
- ST_Area(area) : Calculates the area of the polygon.
- AS areaSize : Provides an alias for the calculated value.
- Real-World Application:
- Important for land management, planning, and resource allocation.
Notes:
- The calculated area is dependent on the coordinate system used.
For more Practice: Solve these Related Problems:
- Write a MySQL query to calculate and display the area of each polygon in the "GeoData" table using ST_Area.
- Write a MySQL query to compute the area for polygons in the "MapAreas" table and filter out those with an area less than 5000 square units.
- Write a MySQL query to select the name and area of each region from "Regions" using ST_Area, ordering the results by area in descending order.
- Write a MySQL query to calculate the total area of all polygons in the "LandParcels" table using ST_Area and aggregate functions.
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
Previous MySQL Exercise: Find Polygons That Intersect a Given Area.
Next MySQL Exercise: Calculate the Perimeter of a Polygon.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
- Weekly Trends and Language Statistics
- Weekly Trends and Language Statistics