Tuesday, 7 April 2015

arcgis 10.2 - Buffering a PointGeometry in arcpy only returns a line?


I am trying to buffer a PointGeometry object in arcpy to a Polygon geometry object with ArcGis 10.2.


The PointGeometry object is in lat/lon WGS84 coordinates and as far as I understand, I can only use PointGeometry.buffer by specifying the buffer in the same coordinates. To specify the buffer in metres, I would need to use: arcpy.Buffer_analysis.


So I setup an empty geometry to do the buffer in like so:


spatialRef = u"GEOGCS['GCS_WGS_1984',DATUM['D_WGS_1984',SPHEROID['WGS_1984',6378137.0,298.257223563]],\
PRIMEM['Greenwich',0.0],UNIT['Degree',0.0174532925199433]];\
-450359962737.05 -450359962737.05 10000;-100000 10000;-100000 10000;0.001;0.001;0.001;IsHighPrecision"

pointGeom = arcpy.PointGeometry(arcpy.Point(-27.607361, 152.768311), spatialRef)

temPol = arcpy.Geometry()

pol = arcpy.Buffer_analysis(pointGeom, temPol, "50 meters")[0]

The resulting Polygon object however, is a long thin line, rather than the expected circular polygon.


Any ideas what I am doing wrong?



Answer



There are two things wrong here:



  1. The Point constructor takes arguments of X and Y, while you're providing Y (latitude) and X (longitude), resulting in an object above the north pole


  2. The XY precision you've defined in the spatialRef object is four decimal places (1/10000th of a degree), which is exceedingly coarse for a circle with a 50 meter radius -- an XY scale of 10,000 corresponds to roughly 11 meters (at the equator)


If you flip the lat and lon coordinates to lon,lat and add at least two places to your spatialRef (remembering to remove them from the origin -- change "-450359962737.05 -450359962737.05 10000" to "-4503599627.3705 -4503599627.3705 1000000" or simply "-400 -400 1000000"), you should get an appropriate polygon (which will not be circluar in an unprojected coordinate system, though it may seem so when close to the equator).


No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...