I recently ran into an issue while grabbing some data from a PostGIS database and outputting to FileGDB via arc.write
. Several of the exported polygons had a negative area value. As a result, the "Select By Location" tool in ArcMap (10.6.1 in this case) would not select any polygons with a negative area.
library(sf)
#> Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
library(arcgisbinding)
#> *** Please call arc.check_product() to define a desktop license.
arc.check_product()
#> product: ArcGIS Pro ( 12.3.2.15850 )
#> license: Advanced
#> version: 1.0.1.232
poly_wkt <- "MULTIPOLYGON (((417290.4 3835221, 417291 3835224, 417308.9 3835361, 417309.3 3835364, 417330.8 3835579, 417330.8 3835599, 417326.6 3835619, 417318.5 3835638, 417306.8 3835654, 417235 3835737, 417221.7 3835750, 417206.2 3835760, 417189.1 3835767, 417171 3835771, 417152.6 3835771, 417134.3 3835768, 417117 3835762, 417101 3835752, 417058.9 3835722, 416710.1 3835692, 416702 3835691, 416275.4 3835619, 416255.5 3835614, 416237.2 3835604, 416221.2 3835591, 416208.2 3835575, 416107.8 3835421, 416098.7 3835404, 416093.2 3835384, 416091.6 3835365, 416094 3835345, 416100.1 3835326, 416109.9 3835309, 416122.9 3835294, 416138.6 3835282, 416156.4 3835273, 416175.6 3835268, 416410.6 3835230, 416811.9 3834851, 416876.4 3834603, 416883.2 3834584, 416893.6 3834567, 416907.2 3834553, 416923.3 3834541, 417041.6 3834473, 417058.3 3834466, 417076.2 3834461, 417094.7 3834460, 417113 3834462, 417130.5 3834468, 417328.6 3834552, 417619.8 3834432, 417637 3834426, 417654.9 3834424, 417672.8 3834425, 417862.9 3834454, 417879.6 3834458, 417951.5 3834482, 418093.6 3834387, 418098.1 3834384, 418291.7 3834269, 418309.2 3834261, 418327.8 3834257, 418347.1 3834256, 418366.2 3834258, 418384.4 3834265, 418401 3834274, 418415.5 3834287, 418427.3 3834302, 418436 3834319, 418441.1 3834338, 418442.7 3834357, 418440.5 3834376, 418434.7 3834395, 418189.4 3834971, 418116.4 3835210, 418081.2 3835351, 418074.8 3835369, 418065 3835386, 418052.3 3835400, 418037.1 3835412, 418019.9 3835421, 418001.4 3835426, 417982.3 3835427, 417963.3 3835425, 417870.8 3835405, 417866 3835404, 417755.8 3835375, 417754.4 3835374, 417658.9 3835347, 417529 3835310, 417525.1 3835309, 417390.3 3835265, 417380.5 3835261, 417290.4 3835221)), ((420559.2 3835138, 420548.8 3835160, 420533.4 3835179, 420362.3 3835342, 420340.4 3835358, 420266.5 3835398, 420243.8 3835407, 420108.7 3835441, 420099.7 3835443, 419858.3 3835481, 419840.7 3835482, 419823.2 3835480, 419697.1 3835455, 419678 3835449, 419660.3 3835439, 419645 3835426, 419632.5 3835411, 419568.5 3835311, 419562.5 3835300, 419495.9 3835161, 419489.2 3835142, 419486.2 3835123, 419487.1 3835103, 419491.8 3835084, 419500.2 3835066, 419540.8 3834998, 419552.2 3834983, 419566.4 3834970, 419582.8 3834960, 419600.9 3834953, 419620 3834950, 419639.3 3834950, 419658.1 3834955, 419675.8 3834962, 419873 3835074, 419941.7 3835085, 420042.2 3835006, 420053.4 3834998, 420284 3834863, 420303.8 3834854, 420325 3834850, 420512.3 3834832, 420532.1 3834832, 420551.5 3834836, 420569.8 3834844, 420586.1 3834855, 420600 3834869, 420610.8 3834886, 420618 3834904, 420621.5 3834924, 420621.1 3834944, 420616.8 3834963, 420559.2 3835138)), ((418861.2 3835143, 418852.2 3835139, 418844.1 3835135, 418837 3835128, 418831.2 3835121, 418826.8 3835113, 418824.2 3835103, 418823.3 3835094, 418823.3 3835047, 418823.9 3835039, 418825.9 3835032, 418860.3 3834928, 418875.5 3834820, 418810.4 3834797, 418799.4 3834792, 418730.8 3834747, 418547.6 3834663, 418538.8 3834657, 418531.2 3834650, 418525.2 3834642, 418521 3834633, 418518.8 3834623, 418518.8 3834612, 418520.8 3834602, 418524.9 3834593, 418530.8 3834584, 418538.3 3834577, 418627.9 3834509, 418635.7 3834504, 418644.2 3834501, 418653.2 3834499, 418662.3 3834499, 418671.3 3834501, 418896.4 3834562, 418933.6 3834529, 418942.3 3834523, 418952.1 3834519, 418962.5 3834517, 418973.1 3834517, 418983.4 3834520, 419162.7 3834585, 419171.4 3834589, 419179.2 3834594, 419185.8 3834602, 419190.8 3834610, 419194.1 3834619, 419195.7 3834628, 419206.4 3834801, 419206 3834811, 419203.4 3834821, 419198.8 3834830, 419001.6 3835142, 418995.2 3835150, 418987.1 3835157, 418977.9 3835162, 418967.9 3835165, 418957.5 3835166, 418947.2 3835164, 418861.2 3835143)))"
poly <- st_as_sfc(poly_wkt, crs = 26912)
st_area(poly)
#> 2531992 [m^2]
arc.write(paste0("test_poly.gdb/", "test_poly"), poly) # yields -2531992.2 m2
arc.write("test_poly.shp", poly) # yields -2531992.2 m2
st_write(poly, "test_poly_from_sf.shp") # yields 2531992.2 m2
#> Writing layer `test_poly_from_sf' to data source `test_poly_from_sf.shp' using driver `ESRI Shapefile'
#> features: 1
#> fields: 0
#> geometry type: Multi Polygon
Negative areas can be fixed by running the "Repair Geometry" tool, but this was an unexpected result from arc.write
. I wonder if this package could modified to either: