help areashp

Title

areashp -- Calculate polygon areas in Shapefiles

Syntax

areashp shpfile [, options]

options

save(filename) Specify output CSV file path (default: shpfile_area.csv)

crs(string) Specify coordinate reference system (required). Can be EPSG code (e.g., EPSG:3857 or 3857), TIF file path, or SHP file path

Description

areashp calculates the area of all polygon and multipolygon features in a shapefile. The results are saved to a CSV file containing all original attribute fields plus an "Area" column.

Important: Area calculation requires a projected coordinate system for accuracy. The crs() option is required and allows you to specify the coordinate system:

• EPSG code: crs(EPSG:3857) or crs(3857)

• Reference TIF file: crs(reference.tif) - reads CRS from GeoTIFF file

• Reference SHP file: crs(reference.shp) - reads CRS from Shapefile

• The command projects the shapefile to the specified coordinate system for accurate area calculation

• The area unit is automatically determined from the CRS (typically square meters for projected systems)

Note: Geographic coordinate systems (e.g., WGS84 with degrees) cannot provide accurate area measurements. The command will always convert to a projected coordinate system to ensure accurate area calculations.

The output CSV file contains all original attribute fields from the shapefile, plus an "Area" column with the calculated area for each polygon feature. Non-polygon features (points, lines) are excluded from the output.

Options

save(filename) specifies the output CSV file path. If not specified, the output file will be named shpfile_area.csv in the same directory as the input shapefile.

Examples

Calculate polygon areas and save to a specific file:

. areashp "fuzhou.shp", save("fujian_areas.csv") crs(EPSG:3857)

Requirements

Runtime environment requirements:

• Java 17 or higher (automatically detected from Stata's Java configuration or system PATH)

• checkshp-0.1.0.jar file (JAR package needs to be built first; automatically searched in current directory, build/libs, or Stata's ado directory)

• All auxiliary files of the Shapefile (.shx, .dbf, .prj, etc.) must be in the same directory as the main file

Technical Details

The command uses GeoTools and JTS (Java Topology Suite) libraries to read shapefiles and calculate polygon areas. The crs() option is required and specifies the coordinate reference system to use. The command projects the shapefile to the specified coordinate system for accurate area calculations. The area calculation uses the JTS geometry area method, which handles both simple polygons and multipolygons correctly.

Author

Chunxia Chen

School of Management, Xiamen University

Email: triciachen6754@126.com

Also see

Online: checkshp, intershp, reprojshp