Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • checkshp: A Suite of Stata Commands for Robust Shapefile Processing (Validation, Reprojection, Area, Intersection)

    Hello everyone,

    I'd like to introduce a new suite of Stata commands called checkshp, designed for robust Shapefile processing. Thanks to Prof. Kit Baum.

    Code:
     ssc install checkshp
    This collection of commands brings advanced geospatial functionalities directly into your Stata workflow, covering geometric validation, cleaning, reprojection, polygon area calculation, and spatial intersection statistical analysis. The checkshp suite comprises four distinct commands, each addressing a crucial aspect of Shapefile management and analysis:
    • checkshp: validates geometric validity of Shapefiles, detects invalid features, and optionally removes invalid features to generate cleaned Shapefiles with a "_clean" suffix.
    • reprojshp: reprojects Shapefiles to a specified coordinate reference system (CRS) using EPSG codes, GeoTIFF files, or reference Shapefiles, and generates new files with a "_reproj" suffix.
    • areashp: calculates the area of all polygon and multipolygon features in a Shapefile and outputs results to a CSV file.
    • intershp: computes spatial intersection areas between two Shapefiles. It supports merge mode (deduplication of overlapping features), automatic clipping, and grouped statistics by specified fields.
    Here are some examples:

    Code:
    . local shp `"fuzhou.shp"'
    
    . local shp2 `"fuzhou_building.shp"' 
    
    . 
    
    . checkshp "`shp'", detail clean
    
    Working copy for delete operation: C:\Users\ccx\Desktop\checkshp\example\fuzhou_clean.shp
    
    Shapefile path: C:\Users\ccx\Desktop\checkshp\example\fuzhou_clean.shp
    
    Geometry field: the_geom
    
    Geometry type: MultiPolygon
    
    Feature count: 13
    
    Null geometries: 0
    
    Empty geometries: 0
    
    Invalid geometries: 0
    
    Invalid but auto-fixable geometries: 0
    
    Extent: [118.38209, 25.249862] -> [120.516189, 26.634377]
    
    Features removed via delete option: 0
    
    No features met the delete criteria; no changes were written.
    
    
    
    . 
    
    . reprojshp "`shp'", crs(EPSG:3857)
    
    Reprojected shapefile saved to: C:/Users/ccx/Desktop/checkshp/example/fuzhou_reproj.shp
    
    . 
    
    . areashp "`shp'",crs(EPSG:4534) save(temp.csv)
    
    === Polygon Area Calculation ===
    
    Shapefile: C:\Users\ccx\Desktop\checkshp\example\fuzhou.shp
    
    Total features: 13
    
    Polygon/MultiPolygon features: 13
    
    --- Area Calculation Settings ---
    
    Coordinate System (CRS): EPSG:CGCS2000 / 3-degree Gauss-Kruger CM 75E
    
    Area Unit: square meters
    
    Total area: 20269770156.438770 square meters
    
    CSV file saved to: C:\Users\ccx\Desktop\checkshp\example\temp.csv
    
    . 
    
    . intershp "`shp'" with("`shp2'"), crs(EPSG:4534) group(Floor) 
    
    
    --- Area Calculation Settings ---
    
    Coordinate System (CRS): EPSG:CGCS2000 / 3-degree Gauss-Kruger CM 75E
    
    Area Unit: square meters
    
    Total intersection area: 49321255.663992 square meters
    
    CSV file saved to: C:\Users\ccx\Desktop\checkshp\example\fuzhou_intersection_stats.csv
Working...
X