Select to view content in your preferred language

Join tables - Add profile names from table to Point feature

468
3
06-30-2022 04:44 AM
Maps-Berlin
Occasional Contributor

Hello everyone,

I have a table and a shapefile containing lining up points

The Shapefile contains all points in order from 1 to x without any additional metadata kinda like this

iDShape
1Point
2Point
......
XPoint

 

The other table contains infos about the Naming of Profiles which are made up of those points something like this:

NameiD fromiD to
Profile 1150
Profile 25190
.........
Profile Y2345523501

 

I am trying to join those features in a way that I add a column to my shapefile containing the info about the Profile names like so:

iDShapeProfile Name
1PointProfile 1
2PointProfile 1
.........
50PointProfile 1
51PointProfile 2
.........
90PointProfile 2
.........

 

I reckon there must be some way to join tables, but having to columns with start and end ID's is throwing me off. Does anyone have an idea?

Thank you

0 Kudos
3 Replies
Maps-Berlin
Occasional Contributor

I managed to do this in excel via some exporting and vlookup but if there is any build-in functionality, I would be thankful to know 😉 

Reinaldo_Cartagena
Regular Contributor

Hi

1) Use the attached python scripts to create a python toolbox:

2) You must add the Feature Class (point) and the Table to the content of ArcGIS Pro
3) Select the features to update
4) Run the python toolbox

Filegeodatabase annex, image of my desktop and python scripts

 

# -*- coding: utf-8 -*-

import arcpy
import arcgis

class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "ProfileName"
        self.alias = "Profile name"

        # List of tool classes associated with this toolbox
        self.tools = [UpdateProfile]


class UpdateProfile(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "UpdateProfile"
        self.description = "Update profile name"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
  
        # Input parameter: feature class
        param0 = arcpy.Parameter(
                 displayName="Feature class: Lining up points ",
                 name="in_features",
                 datatype="GPFeatureLayer",
                 parameterType="Required",
                 direction="Input")
        
        # Input parameter: Table        
        param1 = arcpy.Parameter(
                 displayName="Table: Naming of Profiles ",
                 name="in_records",
                 datatype="GPTableView",
                 parameterType="Required",
                 direction="Input")

        parameters = [param0, param1]
        
        return parameters

    def isLicensed(self):
        """Set whether tool is licensed to execute."""
        return True

    def updateParameters(self, parameters):
        """Modify the values and properties of parameters before internal
        validation is performed.  This method is called whenever a parameter
        has been changed."""
        return

    def updateMessages(self, parameters):
        """Modify the messages created by internal validation for each tool
        parameter.  This method is called after internal validation."""
        return

    def execute(self, parameters, messages):
        """The source code of the tool."""
   
        arcpy.AddMessage("Running task with following parameters")
        arcpy.AddMessage("1. Create the update cursor: Featue Class(Lining up points)")
        update_cursor = arcpy.UpdateCursor(parameters[0].valueAsText)
        arcpy.AddMessage("2. Create the search cursor: Table(Naming of Profiles")

        # Update the Point(profileName) based on Naming of Profiles
        for row in update_cursor:
            # search the Naming of Profiles
            for row_pf in arcpy.SearchCursor(parameters[1].valueAsText):
                if row.Id >= row_pf.IdFrom and row.Id <= row_pf.IdTo:
                   row.setValue("ProfileName", row_pf.Name)
            update_cursor.updateRow(row)
            arcpy.AddMessage("Id: "+str(row.Id)+" Profile: "+str(row.ProfileName))
            
        # Delete cursor and row objects
        del row, row_pf

        return

 

Reinaldo_Cartagena_0-1656630648587.png

 

Reinaldo.

0 Kudos
Maps-Berlin
Occasional Contributor

Hey thanks, I will try this out on the next dataset

0 Kudos