Friday 28 July 2017

arcgis desktop - arcpy handling of floating points


This arises from my own question How to handle coordinates accuracy in ArcGIS where I have tried to use the documentation entitled Using geometry objects with geoprocessing tools as a reference.


I have a table with coordinates in degrees:



enter image description here


I created event table and added it to the view with coordinates system 'GCS_NZGD_2000 WKID: 4167 Authority: EPSG'. I converted this single point to shapefile, defined it projection and computed coordinates of the point using 'Add Geometry Attributes' tool. This is resulting table with numbers as expected:


enter image description here


To replicate this in arcpy I've used this code:


corners =[[174.73,-36.76]]
p=[arcpy.PointGeometry(arcpy.Point(*coords)) for coords in corners]
arcpy.CopyFeatures_management(p, "d:/rubbish/points.shp")

I added output 'points.shp' to the view, defined projection and computed coordinates of the point using 'Add Geometry Attributes' tool. This is resulting table:


enter image description here



As one can see from the picture below the distance between 2 supposedly identical points is close to 10 meters:


enter image description here


However when I updated existing dataset with defined projection using


infc =r'd:\scratch\from_xy.shp'
outRows = arcpy.da.InsertCursor(infc,("SHAPE@","X"))
feat = (arcpy.Point(174.73,-36.76),0)
outRows.insertRow(feat)

It worked. Lessons:




  1. Don't use examples similar to the documentation entitled Using geometry objects with geoprocessing tools

  2. Define projection of dataset prior to any games with geometries.


Does the documentation entitled Using geometry objects with geoprocessing tools need to be revised?



Answer



As requested ... posting my comment here


Use a spatial reference object, which I think pointgeometry supports, check the help. If a defined coordinate system is not used single precision is used in the calculations. References to this phenomenon are documented on this site and on geonet and a comment isn't the place to put them. No SR... = ... inaccurate results – Dan Patterson 33 mins ago


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...