Hi all,
I'm using a Python code block to calculate the azimuths of 11 polylines within a single shapefile. When I run the code block the field calculator it works fine for 8 of the polylines but returns an incorrect result of '0' for 3 polylines. The geoprocessing results give the following reason:
WARNING 000405: No records within table
The polyline shapefile was aquired as a single shapefile data download, so I don't understand why 3 of the polyline features seem to have no records. They don't appear any different in the attribute table, which looks like this:
I doubt it's an error with my code block because I've used this code for many other datasets and not had a problem. Besides it is computing the correct results for the other polylines in this shapefile. But just in case, here is the code:
def GetAzimuthPolyline(shape):
radian = math.atan((shape.lastPoint.X - shape.firstPoint.X)/(shape.lastPoint.Y - shape.firstPoint.Y))
degrees = math.degrees(radian)
if degrees < 0:
return degrees + 360
else:
return degrees
The expression applied is:
Azimuth = GetAzimuthPolyline(!shape!)
Can anyone suggest a reason why I'm having this problem?
I'm using Arc 10.1 with the basic licence.
Thanks!
Have you looked at the 3 polylines? Do they have a zero length or do their start and end points match? What is their orientation?
Can they be multipart polylines?
The answers to your questions are: yes I have looked at them; they all have a length that looks correct; the start and end points don't match; they have different orientations (but none should produce azimuths of 0); they're definitely not multipart polylines.
What I've done is to re-download the data and ran the whole process again from the start. This appears to have solved the issue - I'm now getting correct azimuths for every line. Putting it down to a corrupt download for now, I'll keep working on it and get right back on here if the issue reappears!
Thanks again
Glad you could resolve your issue.