<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Error when using insert cursor and search cursor to output point feature in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305925#M68090</link>
    <description>&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 95, in execute
TypeError: cannot alter multipart geometry type&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I am getting the above error for my .pyt toolbox. The Toolbox takes a Polyline feature, finds the point between the start and end point of the polyline and is supposed to output a point feature class. I am not sure what is going wrong.&amp;nbsp;&lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;DIV&gt;## EDITS MADE BASED OFF COMMENTS, STILL THE SAME ERROR&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os


class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Create Door Centroids 2"
        self.alias = "Create Door Centroids 2"

        # List of tool classes associated with this toolbox
        self.tools = [Centroid]


class Centroid(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Create Door Centroids"
        self.description = "Create Door Centroids"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        door_layer = arcpy.Parameter(
            displayName="Door Feature Layer (LINE)",
            name="door_fc",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input"
        )
        door_layer.filter.list = ['LINE']

        centroid_layer = arcpy.Parameter(
            displayName="Door Centroid Feature Layer (Output)",
            name="doors_fc",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Output"
        )
        centroid_layer.filter.list = ['POINT']

        params = [door_layer, centroid_layer]
        return params

    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."""
        door_layer = parameters[0].valueAsText
        outFC = parameters[1].valueAsText

        spatial_reference = arcpy.Describe(door_layer).spatialReference

         # create output feature class
        out_name = os.path.basename(outFC)
        out_path = os.path.dirname(outFC)
        arcpy.management.CreateFeatureclass(out_path, out_name, "POLYLINE", None, "DISABLED", "DISABLED", spatial_reference)

        # add field
        arcpy.management.AddField(outFC, "floor_id", "TEXT")
        arcpy.management.AddField(outFC, "room_type", "TEXT")

        with arcpy.da.InsertCursor(outFC, [ "SHAPE@", "floor_id", "room_type"]) as icursor:
                with arcpy.da.SearchCursor(door_layer, [ "OID@", "SHAPE@","FIRST_floor_id", "FIRST_room_type",]) as scursor:
                    for row in scursor:
                        door_line = row[1]
                        point1 = door_line.firstPoint
                        point2 = door_line.lastPoint
                        x1 = point1.X
                        y1 = point2.Y
                        x2 = point2.X
                        y2 = point2.Y
                        newX = (x1+x2)/2
                        newY = (y1+y2)/2
                        pt = arcpy.Point(newX, newY)
                        arcpy.AddMessage(point1)
                        arcpy.AddMessage(newX)
                        arcpy.AddMessage(pt)
                        pt_geometry = arcpy.PointGeometry(pt, spatial_reference)
                        row_pt = (pt_geometry, row[2], row[3])
                        icursor.insertRow(row_pt)

        return &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 05 Jul 2023 20:38:58 GMT</pubDate>
    <dc:creator>OveringUMD</dc:creator>
    <dc:date>2023-07-05T20:38:58Z</dc:date>
    <item>
      <title>Error when using insert cursor and search cursor to output point feature</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305925#M68090</link>
      <description>&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;/DIV&gt;&lt;PRE&gt;&lt;SPAN class=""&gt;Traceback (most recent call last):
  File "&amp;lt;string&amp;gt;", line 95, in execute
TypeError: cannot alter multipart geometry type&lt;/SPAN&gt;&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;I am getting the above error for my .pyt toolbox. The Toolbox takes a Polyline feature, finds the point between the start and end point of the polyline and is supposed to output a point feature class. I am not sure what is going wrong.&amp;nbsp;&lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;DIV&gt;## EDITS MADE BASED OFF COMMENTS, STILL THE SAME ERROR&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;import arcpy
import os


class Toolbox(object):
    def __init__(self):
        """Define the toolbox (the name of the toolbox is the name of the
        .pyt file)."""
        self.label = "Create Door Centroids 2"
        self.alias = "Create Door Centroids 2"

        # List of tool classes associated with this toolbox
        self.tools = [Centroid]


class Centroid(object):
    def __init__(self):
        """Define the tool (tool name is the name of the class)."""
        self.label = "Create Door Centroids"
        self.description = "Create Door Centroids"
        self.canRunInBackground = False

    def getParameterInfo(self):
        """Define parameter definitions"""
        door_layer = arcpy.Parameter(
            displayName="Door Feature Layer (LINE)",
            name="door_fc",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Input"
        )
        door_layer.filter.list = ['LINE']

        centroid_layer = arcpy.Parameter(
            displayName="Door Centroid Feature Layer (Output)",
            name="doors_fc",
            datatype="GPFeatureLayer",
            parameterType="Required",
            direction="Output"
        )
        centroid_layer.filter.list = ['POINT']

        params = [door_layer, centroid_layer]
        return params

    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."""
        door_layer = parameters[0].valueAsText
        outFC = parameters[1].valueAsText

        spatial_reference = arcpy.Describe(door_layer).spatialReference

         # create output feature class
        out_name = os.path.basename(outFC)
        out_path = os.path.dirname(outFC)
        arcpy.management.CreateFeatureclass(out_path, out_name, "POLYLINE", None, "DISABLED", "DISABLED", spatial_reference)

        # add field
        arcpy.management.AddField(outFC, "floor_id", "TEXT")
        arcpy.management.AddField(outFC, "room_type", "TEXT")

        with arcpy.da.InsertCursor(outFC, [ "SHAPE@", "floor_id", "room_type"]) as icursor:
                with arcpy.da.SearchCursor(door_layer, [ "OID@", "SHAPE@","FIRST_floor_id", "FIRST_room_type",]) as scursor:
                    for row in scursor:
                        door_line = row[1]
                        point1 = door_line.firstPoint
                        point2 = door_line.lastPoint
                        x1 = point1.X
                        y1 = point2.Y
                        x2 = point2.X
                        y2 = point2.Y
                        newX = (x1+x2)/2
                        newY = (y1+y2)/2
                        pt = arcpy.Point(newX, newY)
                        arcpy.AddMessage(point1)
                        arcpy.AddMessage(newX)
                        arcpy.AddMessage(pt)
                        pt_geometry = arcpy.PointGeometry(pt, spatial_reference)
                        row_pt = (pt_geometry, row[2], row[3])
                        icursor.insertRow(row_pt)

        return &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 20:38:58 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305925#M68090</guid>
      <dc:creator>OveringUMD</dc:creator>
      <dc:date>2023-07-05T20:38:58Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using insert cursor and search cursor to output point feature</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305938#M68091</link>
      <description>&lt;P&gt;In your scursor loop you've got "row" as the index, but then you're redefining "row" at the bottom of the scursor loop. I think you want to assign a different variable there - something like:&lt;/P&gt;&lt;P&gt;"row_pt = ( row[0], pt_geometry, row[2], row[3])"&lt;/P&gt;&lt;P&gt;icursor.insertRow(row_pt)&lt;/P&gt;&lt;P&gt;Also, it looks like your row insertion is attempting to assign an OID to the inserted record - it seems to me that since the OID is assigned by Arc you may not be able to do that, though I may be wrong on that.&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 20:39:59 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305938#M68091</guid>
      <dc:creator>ChrisRingo</dc:creator>
      <dc:date>2023-07-05T20:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using insert cursor and search cursor to output point feature</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305943#M68092</link>
      <description>&lt;P&gt;Hi Chris, thanks for the suggestion. I made the changes (see updated post), but I am still getting the same error&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 20:40:09 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305943#M68092</guid>
      <dc:creator>OveringUMD</dc:creator>
      <dc:date>2023-07-05T20:40:09Z</dc:date>
    </item>
    <item>
      <title>Re: Error when using insert cursor and search cursor to output point feature</title>
      <link>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305963#M68093</link>
      <description>&lt;P&gt;Looks like you've created your outFC as POLYLINE (line 71), but you want to write point geometries to it?&lt;/P&gt;</description>
      <pubDate>Wed, 05 Jul 2023 22:13:44 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-when-using-insert-cursor-and-search-cursor/m-p/1305963#M68093</guid>
      <dc:creator>ChrisRingo</dc:creator>
      <dc:date>2023-07-05T22:13:44Z</dc:date>
    </item>
  </channel>
</rss>

