JSONToFeatures_conversion | issues with in_memory and memory

241
4
03-04-2021 12:43 PM
feralcatcolonist
New Contributor II

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

 

Reports that say that something hasn't happened are always interesting to me, because as we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don't know we don't know. And if one looks throughout the history of our country and other free countries, it is the latter category that tends to be the difficult ones. -----Excuse me, but is this an unknown unknown?-----
0 Kudos
4 Replies
DanPatterson
MVP Notable Contributor
if arcpy.Exists("json_output") #  ???
# do you mean
if arcpy.Exists(json_input)

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

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.

Reports that say that something hasn't happened are always interesting to me, because as we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don't know we don't know. And if one looks throughout the history of our country and other free countries, it is the latter category that tends to be the difficult ones. -----Excuse me, but is this an unknown unknown?-----
0 Kudos
DanPatterson
MVP Notable 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 II

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.

Reports that say that something hasn't happened are always interesting to me, because as we know, there are known knowns; there are things we know we know. We also know there are known unknowns; that is to say we know there are some things we do not know. But there are also unknown unknowns—the ones we don't know we don't know. And if one looks throughout the history of our country and other free countries, it is the latter category that tends to be the difficult ones. -----Excuse me, but is this an unknown unknown?-----
0 Kudos