JSONToFeatures_conversion | issues with in_memory and memory

292
4
03-04-2021 12:43 PM
feralcatcolonist
New Contributor III

So I think that there might be several problems here. JSONToFeatures does not seem to want to output to the "memory" space but it will write to "in_memory"; however, after writing, it does not show up as a feature class using ListFeatureClasses-- --even though it appears as such using describe.

 

 

 

import arcpy

#rename to your path, and replace .txt with .json
json_input = r"WHATEVERPATH\test.json"
arcpy.env.overwriteOutput = True

try:
    arcpy.env.workspace = "memory"
    arcpy.JSONToFeatures_conversion(json_input, "json_output")
except Exception as e:
    print(f"There's this 000206 Error when running the {arcpy.env.workspace} workspace:\n\n{e}")
    arcpy.env.workspace = "in_memory"
    arcpy.JSONToFeatures_conversion(json_input, "json_output")
    print(f"But it seems to work fine running the {arcpy.env.workspace} workspace")

print(f"\n\tThis item exists: {arcpy.Exists('json_output')}")
json_in_memory = arcpy.Describe("json_output")
print(f"\tThis item is a: {json_in_memory.dataType}")
print(f"\tThis item is located at: {json_in_memory.catalogPath}")

list_fc = arcpy.ListFeatureClasses()
print(f"\n\tBut, when we check our current workspace {arcpy.env.workspace}, it returns no feature classes {list_fc}")

 

 

 

Using the Python Kernel from ArcGIS Pro 2.7.1

 


Likes an array of [cats, gardening, photography]
0 Kudos
4 Replies
DanPatterson
MVP Honored Contributor
if arcpy.Exists("json_output") #  ???
# do you mean
if arcpy.Exists(json_input)

... sort of retired...
0 Kudos
feralcatcolonist
New Contributor III

No, that was a convenience function that I threw in there to assist in running multiple times; I guess I could have set overwrite = True to avoid that confusion.


Likes an array of [cats, gardening, photography]
0 Kudos
DanPatterson
MVP Honored Contributor

well this has nothing to describe

json_in_memory = arcpy.Describe("json_output")

I would suggest dumping the try except block and do something about the non-existent variable (which is just a string)


... sort of retired...
0 Kudos
feralcatcolonist
New Contributor III

I'm treating that as a path to where that memory feature class is supposed to reside, with the env set these two are equivalent.

json_in_memory = arcpy.Describe("json_output")

json_in_memory = arcpy.Describe("in_memory\json_output")

I think the bigger issue here is that JSONToFeatures_conversion gets wonky when it is not writing to a "physical" space like a shapefile, GDB, or similar.


Likes an array of [cats, gardening, photography]
0 Kudos