1

When I try and run the Average Nearest Neighbour test on my Shapefile I get the error:

KeyError: u'M'
Failed to Execute (AverageNearestNeighbour)

On a "normal" Shapefile this works fine. However I'm trying to use a Shapefile created originally from a CSV with X, Y coordinates. So the overall workflow I have followed is:

  • Check format, spacing etc of CSV file. No spaces. Coordinates provided as Eastings and Northings. Made Eastings and Northings into Number format.
  • In ArcGIS 10.1 - File>Add Data>Add XY Data.
  • Add the CSV file using Easting and Northing as the X and Y fields. Coordinate system is the same. Click okay.
  • Right click on the file created >Data>Export Data and save as Shapefile.
  • Open the Shapefile in ArcGIS, go to Spatial Statistics>Analyzing Patterns>Average Nearest Neighbour, select the new shapefile, click generate report, click okay...and then the error message comes up.

I can't figure out what I'm doing wrong, does anyone have any ideas?

I'm struggling to find out what that error actually means. I've tried deleting all the unnecessary fields from the CSV file (dates etc) in case that was confusing things, but no luck.

I am a relative beginner.

There are 13,600 fields, which I thought might be the problem. But I tried with a vastly reduced number of rows - down to 800 - but it made no difference.

  • The u'M' looks to be related to Python Unicode support so I think you will find that one or more field values have been populated by doing something like copy/pasting from Word into the CSV file. – PolyGeo Feb 8 '15 at 3:44
  • I thought I'd try a simple resolution first - since PolyGeo's answer made me realise I didn't know much about the formatting of the CSV file (not my file originally), I copied and pasted the relevant columns only, i.e. just Easting and Northing, into a new CSV. And it worked! (I then ran into a different, non-related error, but got results eventually). Thanks for the assistance. – earthwriter Feb 10 '15 at 5:04
1

in agreement with PolyGeo - you mentioned 'Made Eastings and Northings into Number format', which leads me to believe most (all?) of the columns are actually text, simply formatted to look like numbers. In some datasets, 'M' can mean 'missing data', which would also account for but a text field and the error. you could try to add a new column to hold a new Z value - be sure to add as a float or double (in case you have decimal values) rather than a text field. then right click at the top of the new column and use field calculator to set your new field equal to your original Z values. i'm going off memory, but i think any numbers will be moved into the new field, while any text ('M') will be set as zero. This probably still isn't optimal (you may not want to interpolate zeros) - but it's a start to see if this is the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.