Select to view content in your preferred language

ArcPro 2.7- Bug Cant write spatial enabled dataframe to disk

1622
5
12-17-2020 09:24 PM
Labels (2)
wwnde
by
Regular Contributor

Was quite exited to update to ArcPro 2.7 and now I am wailing.

This code ran well on ArcPro 2.6 until I rolled to 2.7

 

 

from arcgis.gis import GIS
import arcgis
from arcgis import features
from arcgis.geoanalytics import manage_data
from arcgis.features.manage_data import overlay_layers
from arcgis.features import GeoAccessor, GeoSeriesAccessor, FeatureLayer
import arcpy
import sys, os
import pandas as pd
import datetime as dt
from arcgis.features import FeatureLayerCollection
import http.client
import mimetypes
import json
import requests
from pandas import json_normalize
from arcgis import geometry 
from copy import deepcopy
from arcgis.features.manage_data import dissolve_boundaries


gis = GIS("url.maps.arcgis.com", "UserName", "Password)

item=gis.content.get('Feature_Layer Portal ID')
l=item.layers[0] 
df=l.query().sdf

#Create Temporary Geodatabase

if arcpy.Exists(r"C:\Centroid"):
   arcpy.Delete_management(r"C:\Centroid")
arcpy.CreateFolder_management(r"C:", "Centroid")

if arcpy.Exists(r"C:\Centroid"):
   arcpy.Delete_management(r"C:\Centroid\Centroid")
arcpy.CreateFolder_management(r"C:\Centroid", "Centroid")

arcpy.CreateFolder_management(r"C:","Centroid")
if arcpy.Exists(r"C:\Centroid\Centroid\KCentroids.gdb"):
   arcpy.Delete_management(r"C:\Centroid\Centroid\KCentroids.gdb")

arcpy.CreateFileGDB_management(r"C:\Centroid\Centroid","KCentroids")

#Write spatially enabled dataframe to disk

df.spatial.to_featureclass('C:\Centroid\Centroid\KCentroids.gdb\jana')

 

For reasons I cant explain df.spatial.to_featureclass can neither write feature class to geodatabase  nor shapefile to a folder. Has anyone experienced this? If not what could it be because update was successful 

I get the error

ValueError: invalid JSON data
0 Kudos
5 Replies
ThomasL
Regular Contributor

 

Try adding a "r" to the path maybe?

df.spatial.to_featureclass(r'C:\Centroid\Centroid\KCentroids.gdb\jana')

 

DanPatterson
MVP Esteemed Contributor

Good general suggestion, but it would only have an impact if it was one of the "evil" escape characters, like, t, a, b, and a load of others

print('C:\Centroid\Centroid\tCentroids.gdb\jana')
C:\Centroid\Centroid	Centroids.gdb\jana

... sort of retired...
0 Kudos
DanPatterson
MVP Esteemed Contributor

If that exact json worked in 2.6, then you might want to flag the github site because they could narrow down changes to the api better than we could.  You can examine the site under "issues" open or closed.  Or report an "issue"

Esri/arcgis-python-api: Documentation and samples for ArcGIS API for Python (github.com)


... sort of retired...
wwnde
by
Regular Contributor

Thanks, logged the issue https://github.com/Esri/arcgis-python-api/issues/890 . Will uninstall and reinstall 2.6 and see how I go

0 Kudos
wwnde
by
Regular Contributor

Resolved this issue by restricting myself to the ArcGIS API. I used this notebook and hence avoided writing to disc

0 Kudos