Calculating angles using ArcGIS Desktop 10.2

19938
32
Jump to solution
01-21-2016 11:17 AM
BrianVann
New Contributor II

I need to find angles of streets where they intersect with roadways covering the entire state. Does anyone have a method and/or tools in mind?

0 Kudos
32 Replies
WesMiller
Regular Contributor III

Put the below at the top of the script

import arcpy

0 Kudos
JeremyMullins4
New Contributor III

Wes,

I mentioned in my comment that I tried that and it fixed the first error. However, the second error came up afterwords. I tried changing the paths from 'in_memory' to a file geodatabase and it gave me the same error. I looked through the script provided by ArcGIS for Intersect in the location provided in the error, and I didn't see any syntax issues (obviously, why would there be if it worked for Darren and others...)

I see where in line 289 it gives me an error, but I'm not sure why. Here is what the script says:

from arcpy.geoprocessing._base import gp, gp_fixargs

    from arcpy.arcobjects.arcobjectconversion import convertArcObjectToPythonObject

    try:

        retval = convertArcObjectToPythonObject(gp.SpatialJoin_analysis(*gp_fixargs((target_features, join_features, out_feature_class, join_operation, join_type, field_mapping, match_option, search_radius, distance_field_name), True)))

        return retval

    except Exception, e:

        raise e

I'm trying to figure out why it raised e. I am only using a single polyline feature class to perform this analysis, but I didn't see that as an issue with the Intersect tool. I made sure to replace my lines to the path to the file geodatabase (although I have a feeling it may need to be a shapefile to access the .dbf file???)

0 Kudos
DarrenWiens2
MVP Honored Contributor

Maybe we'll see something if you post the script up to the point where it throws the error.

JeremyMullins4
New Contributor III

Darren - you're absolutely right. I should have post that. Apologies. Here it is:

import arcpy

import os

fc = "C:\Users\jmullins\Desktop\GIS Data\Customer Data\Washington County FL\Washington County FL Data\WashingtonCountyFL.gdb\GEO\StreetCenterline" 

sr = arcpy.Describe(fc).spatialReference 

radius = 50 

out_fc = r'in_memory\points' 

int_pt = r'in_memory\int_pt' 

arcpy.Intersect_analysis(fc,int_pt,output_type='POINT')

0 Kudos
DanPatterson_Retired
MVP Emeritus

fc = r"c: etc 

  • you need raw notation
  • and you really need to use a much shorter path without spaces.  the max length is 260 characters (filename is different) but yours is really long
  • are rest of the lines used?

I didn't get past there

JeremyMullins4
New Contributor III

Thanks so much to everybody for all your help. I was able to make it work! It was two things:

1. Dan - you were absolutely spot-on with the file path. I moved the geodatabase up and made it work. For this tool, I may simply export to a shapefile in a higher-level folder and then reimport back into the original geodatabase. Or I may just have to reorganize all my data, which is probably a good thing considering the issues here.

2. Since this wasn't a shapefile and was a feature class, I made sure to change any tool looking for 'FID' to look for 'OBJECTID', and it worked like a charm. Thanks so much for all the help.

One last question: is there a way to iterate this so that it overwrites files with the same name? I want this to become automated so that a customer could run this script (as part of a much larger model) on a regular basis whenever they want without having to concern themselves with errors about how a shapefile or feature class already exists. If not, I'm sure I can put a 'Delete' option in the model to delete the files afterwards.

Thanks again.

0 Kudos
WesMiller
Regular Contributor III

arcpy.OverwriteOutput = True

JeremyMullins4
New Contributor III

Thanks Wes - makes sense. Where would I put this line of code? After every instance where an arcpy method is called?

0 Kudos
WesMiller
Regular Contributor III

Put it at the top of your script and it will persist. Or to delete a file see below.

import os
svFile = "some file name"
if (os.path.exists(svFile)):
    os.unlink(svFile)
DanPatterson_Retired
MVP Emeritus

use OIDFieldname all the time, applies to tables as well...saves the hastle for mix of FID and OBJECTID

OIDFieldName = arcpy.Describe(inFeatureClass).OIDFieldName