1

I want to create a memory layer with points in ArcGIS with Python Toolbox. I found an in_memory function. Here is the question: Why this command works in Python Console in ArcGIS, but not in Python Toolbox?

arcpy.CreateFeatureclass_management('in_memory','memory_layer', "POINT")

Not works, I mean no errors and no effects. Function:

x = arcpy.CreateFeatureclass_management('in_memory','memory_layer', "POINT")
arcpy.AddMessage(str(x))

Returns in_memory\memory_layer

Any ideas?

# -*- coding: utf-8 -*-
import arcpy
import os

class Toolbox(object):
    def __init__(self):
        self.label = "YY"
        self.alias = ""
        self.tools = [XX]


class XX(object):
    def __init__(self):
        self.label = "XX"
        self.description = "YY"
        self.canRunInBackground = False

    def getParameterInfo(self):
        parameters = []

        x = arcpy.Parameter(
            displayName="X",
            name="x",
            datatype="String",
            parameterType="Required",
            direction="Input")
        parameters.append(x)

        y = arcpy.Parameter(
            displayName="Y",
            name="y",
            datatype="String",
            parameterType="Required",
            direction="Input")
        parameters.append(y)

        return parameters

    def isLicensed(self):
        return True

    def updateParameters(self, parameters):
        return

    def updateMessages(self, parameters):
        return

    def execute(self, parameters, messages):
        x = float(parameters[0].valueAsText)
        y = float(parameters[1].valueAsText)
        newpoint = arcpy.PointGeometry(arcpy.Point(x,y), arcpy.SpatialReference(4326))
        a = newpoint.firstPoint.X
        b = newpoint.firstPoint.Y
        arcpy.env.overwriteOutput=True
        arcpy.env.workspace = "in_memory"
        x = arcpy.CreateFeatureclass_management('in_memory','memory_layer', "POINT")
        arcpy.AddMessage(str(x))

Console log:

Executing: XX 10 10 Start Time: Fri Apr 22 11:37:26 2016 Running script XX... in_memory\memory_layer Completed script XX... Succeeded at Fri Apr 22 11:37:26 2016 (Elapsed Time: 0,09 seconds)

  • 1
    Welcome to GIS:SE @x9663605! Perhaps you need to change your workspace directory? E.g. import arcpy, arcpy.env.workspace = "path/to/directory" – Joseph Apr 22 '16 at 10:16
  • Please elaborate on Not works, I mean no errors and no effects – Alex Tereshenkov Apr 22 '16 at 10:36
  • Have you got background geoprocessing enabled? Have you set canRunInBackground=False in your toolbox? – user2856 Apr 22 '16 at 11:01
  • @Joseph : Should I add this line for only memory layer? – x9663605 Apr 22 '16 at 11:40
  • @Luke : Yes, I have it. – x9663605 Apr 22 '16 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.