I built up a polygon layer from a road network for finding roundabouts using the compactness factor of a polygon. Then I have to intersect the extracted roundabout polygons with the road network so that I can find the composing links. This process can take ages to be done using for-loops for each roundabout and intersecting it with all links.
I am wondering if there is a way that I can add the composing links' ID to polygon in the very first step with out intersecting them.
Current algorithm takes three following steps:
- FeatureToPolygon function in ArcPy to create the polygons.
- Iterating over each polygon and computing the compactness,
- And if it's over the threshold then select links which "SHARE_A_LINE_SEGMENT_WITH" the possible roundabout (the polygon in hand with compactness higher than threshold).
The dataset has more than 250000 line features but the number of detected roundabouts are depending on the threshold. it should not be more than 1000.
There is an optional argument about attributes. The ArcGIS (or ArcPy) instruction says not to use it though.
I tried the following code but I get an error.
polyoutputaddress = outputaddress+output_polygon_name arcpy.FeatureToPolygon_management(inputaddress,polyoutputaddress,"", "NO_ATTRIBUTES", "") targetFeatures = polyoutputaddress joinFeatures = inputaddress outfc = outputaddress+"fieldmapping"+output_polygon_name fieldmappings = arcpy.FieldMappings() fieldmappings.addTable(targetFeatures) fieldmappings.addTable(joinFeatures) inputFIDIndex = fieldmappings.findFieldMapIndex("JOIN_FID") inputfieldmap = fieldmappings.getFieldMap(inputFIDIndex) inputfieldmap print inputFIDIndex inputfieldmap.mergeRule = 'Join' inputfieldmap.joinDelimiter = ',' fieldmappings.replaceFieldMap(inputFIDIndex, inputfieldmap) arcpy.SpatialJoin_analysis(targetFeatures, joinFeatures, outfc, "#", "#", fieldmappings,"SHARE_A_LINE_SEGMENT_WITH")
here is the error: arcgisscripting.ExecuteError: ERROR 001156: Failed on input OID 0, could not write value '-1,-1,-1' to output field JOIN_FID Failed to execute (SpatialJoin).
as I checked this is because the FID field is numeric, but Join rule should be used for text values.
Any work around this problem?