9 Replies Latest reply on Jun 4, 2012 2:26 PM by monodh

    Linear attribute data isolation for join with polygons

    monodh
      Hello ,

      I have some polygons representative of roadway sections and I have some line data representative of roadway condition and classification. I am looking for a way to join attributes from the line data to the polygon data, however at times there are multiple line segments within a polygon- each with different attributes - and I would like to join only the attributes (condition and classification attributes) of the longest line segment that falls within each polygon.

      I have tried many functions of the spatial join, but when I choose the merge rule ???maximum??? on the shape length field of the line data it does not seem to bring the associated attributes??! (Only the longest shape lengths are joined, and the other two attribute fields seem random, or are joined based on their merge rule not that of the shape length field)  I have tried spatial joins and then just regular table joins and I have tried intersection tools???. No luck yet on getting the correct information.

      If anybody has any ideas on this please let me know,

      Thanks in advance :) 
      Hailey
        • Re: Linear attribute data isolation for join with polygons
          nahmed-esristaff
          As an if-then condition has to be met, I'm afraid you cannot do it through tool dialog.

          Most probably you'll need to write a python script manipulating the fieldmap object based on the if condition. Which version of ArcGIS you are using?

          For 9.3 and 9.3.1 the help link is:
          http://webhelp.esri.com/arcgisdesktop/9.3/index.cfm?TopicName=FieldMappings_properties

          For 10.0:
          Fieldmap object: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/FieldMap/000v00000081000000/
          Fieldmappings object: http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#/FieldMappings/000v0000008q000000/
          • Re: Linear attribute data isolation for join with polygons
            monodh
            Oh dear! I am using v10, but I havent done anything like that yet, so I better start reading....
            Thanks for your advice :)
            • Re: Linear attribute data isolation for join with polygons
              nahmed-esristaff
              Here is a non-scriptin way. You can create a Model in ModelBuilder by chaining the processes.

              To learn about how to use the Field Mapping control review this topic:
              http://help.arcgis.com/en/arcgisdesktop/10.0/help/index.html#//00210000000s000000


              Target features: sections (polygons)
              Join features: roads (lines)

              Step 1:
              Add a field (type double) named Length to the roads feature class to store the shape length values.

              Step 2:
              Right-click on the newly added field and select Field Calculator ... select Shape_Length from the Fields group. Hit Ok.

              Step 3:
              Run spatial join - in the tool dialog set parameter values as follows:

              Target: sections
              Join: roads
              JOIN_ONE_TO_ONE
              Chose match option of your interest (say, CONTAINS)
              Output feature class: spj_1

              In the fieldmap, delete all shape-related fields (Shape_area, shape_length etc). Add a new output field of type Double and name it ShpLength. Set a merge rule of Maximum. Right-click on ShpLength and select Add Input Field. Select roads.Length field from the available fields.

              Run the tool

              Step 4:
              Re-run spatial join by double-clicking on the result node (Results window). Give a different name to the output and change only these parameter values:

              JOIN_ONE_TO_MANY
              Change the ShpLenght fieldmap's merge rule to First.
              Output feature class: spj_2 (must be different from the first output)

              Run the tool.

              Step 5:
              Run Join Field tool as follows:

              Input table: spj_1
              Input Join Field: ShpLength
              Join Table: spj_2
              Output Join Field: ShpLength
              Join Fields: JOIN_FID

              Step 6:
              Run Join Field again. This time use parameter values as follows:

              Input Table: spj_1
              Input Join Field: JOIN_FID
              Join Table: roads
              Output Join Field: OBJECTID (or whatever the name of the OID field)

              Join Fields: Condition and Classification
              • Re: Linear attribute data isolation for join with polygons
                monodh
                Wow! That worked well for me, THANK YOU SO MUCH!!!
                Really appreciate your help :)
                • Re: Linear attribute data isolation for join with polygons
                  monodh
                  Hello NobbirAhmed,

                  As you were so knowledgeable on my previous question, I was just wondering if you happen to know anything about changing the field mapping rules slightly? I noticed that the mode rule will choose the highest numeric value when there is a tie, however is there anyway for me to change it, or use a combination of rules to say "choose the mode (most frequent occuring value) and if there is a tie then choose the lowest numeric value" ...
                  Please let me know if you have any insight?!

                  Thank you!!!
                  Hailey
                  • Re: Linear attribute data isolation for join with polygons
                    nahmed-esristaff
                    I noticed that the mode rule will choose the highest numeric value when there is a tie


                    I think it is the opposite. I've just tested. I have 3 mode values (2, 3, 7) with equal frienquencies (14). When I set Mode as merge rule - the output gets 2 (the lowest value). Which version of ArcGIS you are using?

                    .. use a combination of rules to say "choose the mode (most frequent occuring value) and if there is a tie then choose the lowest numeric value" ...


                    I guess we are out of luck this time (unless someone comes up with a good answer). We need to use Python to get things done. I'll get back if I can find a good solution.
                    • Re: Linear attribute data isolation for join with polygons
                      monodh
                      Oh, I think your right, this is what the help page says:

                      "�?�Mode�??Use the value with the highest frequency (most common). If there is more than one value with the highest frequency (i.e., a tie), then the list of Mode values will be sorted (smallest first for numeric, alphabetical for text), and the first one will be used."

                      So in that case, I was mixed up, I actually need a rule that looks at all the values and first chooses the value that repeats itself the most, and if that is not possible then it chooses the highest value. So for your example, it would choose 7 (from 2,3,7)

                      Hhmmm, let me know if you think of a work around?!

                      Thanks again for alll your help :)
                      • Re: Linear attribute data isolation for join with polygons
                        nahmed-esristaff
                        I have a workaround in Python but we need to test it to make sure it works. Email me nahmed@esri.com and I'll send you instructions so that you can try with your data. If the solution is workable we'll then upload the script/instructions to this thread.
                        • Re: Linear attribute data isolation for join with polygons
                          monodh
                          Hi Nobbir,

                          Thank you so much! The python script did the trick!
                          I have attached the zip file for others to use :)

                          For users: make sure you first run a spatial join with the one-to-one option, and construct one field map with the mode merge rule, and then re-run the spatial join, but only change the option for the one-to-many and its output name. Afterwards, connect to the script tool, and use the first spatial join in the fist parameter and the second spatial join in the second parameter and then in the third parameter use the field you used with the mode merge rule. And it will update the first spatial join feature class.

                          Thanks again!
                          Hailey