Thanks to Kit Baum, geoinpoly is now available from SSC.
geoinpoly finds, for geographic locations in memory, polygons from a shapefile that spatially overlay the points. This is a point-in-polygon operation, also known as a spatial join in GIS (geographic information system) terminology.
geoinpoly uses a ray casting algorithm to determine if a point falls inside a polygon. The point's longitude determines the ray used (i.e. meridian or line of longitude that passes by the point's location). geoinpoly assumes that polygon segments represent lines of constant bearing (also referred to as rhumb lines or loxodromes). To precisely calculate the latitude at which a polygon segment intersects the meridian, geoinpoly transforms all geographic coordinates to (x-coor, y-coor) using an ellipsoid Mercator projection. This projection has the property of representing lines of constant bearing as straight lines on the projected plane.
geoinpoly results should match exactly those produced by GIS software. A test dataset of 573,100 points spread over the state of Texas and its neighbors was matched to U.S. states using a U.S. Census Cartographic Boundary shapefile of all U.S. states using both geoinpoly and ArcGIS. The results were identical.
geoinpoly incorporates the same divide and conquer strategy used in geonear (from SSC) to significantly reduce the number of polygon segments that need to be counted. On my computer, geoinpoly takes about 30 seconds to process the 573K test dataset; using ArcGIS to perform the equivalent spatial join took 3 1/2 minutes (not really a fair performance test because I ran the ArcGIS test on a remote desktop server).
To install geoinpoly, type in Stata's command window
geoinpoly finds, for geographic locations in memory, polygons from a shapefile that spatially overlay the points. This is a point-in-polygon operation, also known as a spatial join in GIS (geographic information system) terminology.
geoinpoly uses a ray casting algorithm to determine if a point falls inside a polygon. The point's longitude determines the ray used (i.e. meridian or line of longitude that passes by the point's location). geoinpoly assumes that polygon segments represent lines of constant bearing (also referred to as rhumb lines or loxodromes). To precisely calculate the latitude at which a polygon segment intersects the meridian, geoinpoly transforms all geographic coordinates to (x-coor, y-coor) using an ellipsoid Mercator projection. This projection has the property of representing lines of constant bearing as straight lines on the projected plane.
geoinpoly results should match exactly those produced by GIS software. A test dataset of 573,100 points spread over the state of Texas and its neighbors was matched to U.S. states using a U.S. Census Cartographic Boundary shapefile of all U.S. states using both geoinpoly and ArcGIS. The results were identical.
geoinpoly incorporates the same divide and conquer strategy used in geonear (from SSC) to significantly reduce the number of polygon segments that need to be counted. On my computer, geoinpoly takes about 30 seconds to process the 573K test dataset; using ArcGIS to perform the equivalent spatial join took 3 1/2 minutes (not really a fair performance test because I ran the ArcGIS test on a remote desktop server).
To install geoinpoly, type in Stata's command window
Code:
ssc install geoinpoly
Comment