I'm trying to get an JSON API response with latitude and longitude keys into a Spatial DataFrame so that I can create a hosted feature service from it. Frankly, I'm quite out of practice with Python and I feel like I'm just learning it all over again. I don't want to use ArcPy to accomplish this even though I know it has the JSONToFeatures_conversion tool or in an advanced notebook.
The SpatialDataFrame route is not a requirement. It just seemed the most obvious to me. The goal is to be able to create a new Hosted Feature Service from the JSON Response which looks like:
[{
"Points": [{
"SiteId": 521,
"Latitude": 41.496978,
"Longitude": -95.451919,
"Address1": "10 East Street",
"Address2": null,
"AddressId": 0,
"AddressTypeId": 0,
"City": "Shelby",
"Comments": null,
"County": null,
"Name": "Site 426",
"StoreUrl": "http://myloves426.com",
"SpecialInstructions": null,
"State": "IA",
"Zip": "51570",
"ExitNumber": "34",
"Highway": "I-80",
"PhoneNumber": "(712) 207-2441",
"MapPinId": "e1ff88a9cdba42009a68a6bdbe86b71a",
"MapPinZIndex": 99999999,
"FacilityId": 5712
}, {
"SiteId": 978,
"Latitude": 42.652564,
"Longitude": -88.542025,
"Address1": "100 E Commerce Ct",
"Address2": null,
"AddressId": 0,
"AddressTypeId": 0,
"City": "Elkhorn",
"Comments": null,
"County": null,
"Name": "Site 752",
"StoreUrl": "http://myloves752.com",
"SpecialInstructions": null,
"State": "WI",
"Zip": "53121",
"ExitNumber": "25",
"Highway": "I-43",
"PhoneNumber": "(262) 723-8888",
"MapPinId": "e1ff88a9cdba42009a68a6bdbe86b71a",
"MapPinZIndex": 99999999,
"FacilityId": 6485
}],
"FuelPrices": null,
"StateAbbreviation": null,
"CustomFields": null
}]
<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>So far, I've been able to get it into a standard pandas df using:
<SPAN class="keyword token">import</SPAN> pandas <SPAN class="keyword token">as</SPAN> pd
<SPAN class="keyword token">import</SPAN> requests
<SPAN class="keyword token">import</SPAN> json
points <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://www.loves.com/api/sitecore/StoreSearch/SearchStores"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN>
df <SPAN class="operator token">=</SPAN> pd<SPAN class="punctuation token">.</SPAN>DataFrame<SPAN class="punctuation token">(</SPAN>points<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token">#print(df)</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>
However, I don't know where to go from here in terms of turning that response into a hosted feature service based on the latitude and longitude keys given in the response - I do not want to geocode here as I already have the coordinates.
I've also tried using FeatureSet.from_dict method in the Python API, which I presume I should be able to turn into a Hosted Feature Service with relative ease, but I can't get the features loaded into a Featureset from the dictionary for some reason. Here's the code I'm working with currently for that approach:
<SPAN class="keyword token">import</SPAN> requests
<SPAN class="keyword token">import</SPAN> json
<SPAN class="keyword token">import</SPAN> arcgis
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> getpass <SPAN class="keyword token">import</SPAN> getpass
portal <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://johns.maps.arcgis.com"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"john.m.dye"</SPAN><SPAN class="punctuation token">,</SPAN> getpass<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
portal<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>me
lovesLocator <SPAN class="operator token">=</SPAN> <SPAN class="string token">"https://www.loves.com/api/sitecore/StoreSearch/SearchStores"</SPAN>
response <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN>lovesLocator<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN>
type<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># dict</SPAN>
fs <SPAN class="operator token">=</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features<SPAN class="punctuation token">.</SPAN>FeatureSet<SPAN class="punctuation token">.</SPAN>from_dict<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>fs<SPAN class="punctuation token">)</SPAN>
<SPAN class="comment token"># {"features": [], "fields": []}</SPAN><SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>[update 2/8/2020]
I was able to solve my initial problem this morning thank's to PerAkeMattias comment on a separate but similar question.
It basically, I needed to just use the SpatialDataFrame.from_xy method to create a Spatial Dataframe, passing in my Latitude and Longitude fields from my pandas DataFrame to get my locations plotted. From there, I expected to be able to use the SpatialDataFrame.to_featurelayer method to publish it, but I'm running into a TypeError and I'm not sure why.
<SPAN class="keyword token">import</SPAN> requests
<SPAN class="keyword token">import</SPAN> json
<SPAN class="keyword token">import</SPAN> arcgis
<SPAN class="keyword token">from</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>gis <SPAN class="keyword token">import</SPAN> GIS
<SPAN class="keyword token">from</SPAN> getpass <SPAN class="keyword token">import</SPAN> getpass
<SPAN class="keyword token">import</SPAN> pandas <SPAN class="keyword token">as</SPAN> pd
portal <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://johns.maps.arcgis.com"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"john.m.dye"</SPAN><SPAN class="punctuation token">,</SPAN> getpass<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">)</SPAN>
portal<SPAN class="punctuation token">.</SPAN>users<SPAN class="punctuation token">.</SPAN>me
response <SPAN class="operator token">=</SPAN> json<SPAN class="punctuation token">.</SPAN>loads<SPAN class="punctuation token">(</SPAN>requests<SPAN class="punctuation token">.</SPAN>get<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"https://www.loves.com/api/sitecore/StoreSearch/SearchStores"</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>text<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="string token">"Points"</SPAN><SPAN class="punctuation token">]</SPAN>
df <SPAN class="operator token">=</SPAN> pd<SPAN class="punctuation token">.</SPAN>DataFrame<SPAN class="punctuation token">(</SPAN>response<SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">)</SPAN>
sdf <SPAN class="operator token">=</SPAN> arcgis<SPAN class="punctuation token">.</SPAN>features<SPAN class="punctuation token">.</SPAN>SpatialDataFrame<SPAN class="punctuation token">.</SPAN>from_xy<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Longitude"</SPAN><SPAN class="punctuation token">,</SPAN> <SPAN class="string token">"Latitude"</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="operator token">=</SPAN><SPAN class="number token">4326</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="keyword token">print</SPAN><SPAN class="punctuation token">(</SPAN>sdf<SPAN class="punctuation token">)</SPAN>
m1 <SPAN class="operator token">=</SPAN> GIS<SPAN class="punctuation token">(</SPAN><SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">.</SPAN>map<SPAN class="punctuation token">(</SPAN><SPAN class="string token">'United States'</SPAN><SPAN class="punctuation token">)</SPAN>
m1<SPAN class="punctuation token">.</SPAN>zoom <SPAN class="operator token">=</SPAN> <SPAN class="number token">4</SPAN>
m1<SPAN class="punctuation token">.</SPAN>center <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="number token">39</SPAN><SPAN class="punctuation token">,</SPAN><SPAN class="operator token">-</SPAN><SPAN class="number token">98</SPAN><SPAN class="punctuation token">]</SPAN>
sdf<SPAN class="punctuation token">.</SPAN>plot<SPAN class="punctuation token">(</SPAN>kind<SPAN class="operator token">=</SPAN><SPAN class="string token">'map'</SPAN><SPAN class="punctuation token">,</SPAN> map_widget<SPAN class="operator token">=</SPAN> m1<SPAN class="punctuation token">)</SPAN>
m1
sdf<SPAN class="punctuation token">.</SPAN>to_featurelayer<SPAN class="punctuation token">(</SPAN>title<SPAN class="operator token">=</SPAN><SPAN class="string token">"lovesTest"</SPAN><SPAN class="punctuation token">,</SPAN> gis<SPAN class="operator token">=</SPAN>portal<SPAN class="punctuation token">,</SPAN> tags<SPAN class="operator token">=</SPAN><SPAN class="string token">"test, loves"</SPAN><SPAN class="punctuation token">)</SPAN>
Unfortunately, I'm seeing a TypeError returned and I'm not sure why:
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN>
TypeError Traceback <SPAN class="punctuation token">(</SPAN>most recent call last<SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token"><</SPAN>ipython<SPAN class="operator token">-</SPAN>input<SPAN class="number token">-10</SPAN><SPAN class="operator token">-</SPAN>bbe2612cd7ab<SPAN class="operator token">></SPAN> <SPAN class="keyword token">in</SPAN> <SPAN class="operator token"><</SPAN>module<SPAN class="operator token">></SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1</SPAN> sdf<SPAN class="punctuation token">.</SPAN>to_featurelayer<SPAN class="punctuation token">(</SPAN>title<SPAN class="operator token">=</SPAN><SPAN class="string token">"lovesTest"</SPAN><SPAN class="punctuation token">,</SPAN> gis<SPAN class="operator token">=</SPAN>portal<SPAN class="punctuation token">,</SPAN> tags<SPAN class="operator token">=</SPAN><SPAN class="string token">"test, loves"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">/</SPAN>anaconda3<SPAN class="operator token">/</SPAN>lib<SPAN class="operator token">/</SPAN>python3<SPAN class="number token">.7</SPAN><SPAN class="operator token">/</SPAN>site<SPAN class="operator token">-</SPAN>packages<SPAN class="operator token">/</SPAN>arcgis<SPAN class="operator token">/</SPAN>features<SPAN class="operator token">/</SPAN>_data<SPAN class="operator token">/</SPAN>geodataset<SPAN class="operator token">/</SPAN>geodataframe<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> to_featurelayer<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> title<SPAN class="punctuation token">,</SPAN> gis<SPAN class="punctuation token">,</SPAN> tags<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1727</SPAN> <SPAN class="keyword token">raise</SPAN> ValueError<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"GIS object must be provided"</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1728</SPAN> content <SPAN class="operator token">=</SPAN> gis<SPAN class="punctuation token">.</SPAN>content
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1729</SPAN> <SPAN class="keyword token">return</SPAN> content<SPAN class="punctuation token">.</SPAN>import_data<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> title<SPAN class="operator token">=</SPAN>title<SPAN class="punctuation token">,</SPAN> tags<SPAN class="operator token">=</SPAN>tags<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1730</SPAN> <SPAN class="comment token">#----------------------------------------------------------------------</SPAN>
<SPAN class="number token">1731</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">set_geometry</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> col<SPAN class="punctuation token">,</SPAN> drop<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">,</SPAN> inplace<SPAN class="operator token">=</SPAN><SPAN class="token boolean">False</SPAN><SPAN class="punctuation token">,</SPAN> sr<SPAN class="operator token">=</SPAN>None<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token">/</SPAN>anaconda3<SPAN class="operator token">/</SPAN>lib<SPAN class="operator token">/</SPAN>python3<SPAN class="number token">.7</SPAN><SPAN class="operator token">/</SPAN>site<SPAN class="operator token">-</SPAN>packages<SPAN class="operator token">/</SPAN>arcgis<SPAN class="operator token">/</SPAN>gis<SPAN class="operator token">/</SPAN>__init__<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> import_data<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> df<SPAN class="punctuation token">,</SPAN> address_fields<SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">**</SPAN>kwargs<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">3666</SPAN> <SPAN class="keyword token">if</SPAN> isinstance<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">,</SPAN> SpatialDataFrame<SPAN class="punctuation token">)</SPAN> <SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">3667</SPAN> ds <SPAN class="operator token">=</SPAN> df<SPAN class="punctuation token">.</SPAN>to_featureclass<SPAN class="punctuation token">(</SPAN>out_location<SPAN class="operator token">=</SPAN>temp_dir<SPAN class="punctuation token">,</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">3668</SPAN> out_name<SPAN class="operator token">=</SPAN>name<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">3669</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">3670</SPAN> ds <SPAN class="operator token">=</SPAN> df<SPAN class="punctuation token">.</SPAN>spatial<SPAN class="punctuation token">.</SPAN>to_featureclass<SPAN class="punctuation token">(</SPAN>
<SPAN class="operator token">/</SPAN>anaconda3<SPAN class="operator token">/</SPAN>lib<SPAN class="operator token">/</SPAN>python3<SPAN class="number token">.7</SPAN><SPAN class="operator token">/</SPAN>site<SPAN class="operator token">-</SPAN>packages<SPAN class="operator token">/</SPAN>arcgis<SPAN class="operator token">/</SPAN>features<SPAN class="operator token">/</SPAN>_data<SPAN class="operator token">/</SPAN>geodataset<SPAN class="operator token">/</SPAN>geodataframe<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> to_featureclass<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> out_location<SPAN class="punctuation token">,</SPAN> out_name<SPAN class="punctuation token">,</SPAN> overwrite<SPAN class="punctuation token">,</SPAN> skip_invalid<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1407</SPAN> out_location<SPAN class="operator token">=</SPAN>out_location<SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">1408</SPAN> out_name<SPAN class="operator token">=</SPAN>out_name<SPAN class="punctuation token">,</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1409</SPAN> overwrite<SPAN class="operator token">=</SPAN>overwrite<SPAN class="punctuation token">,</SPAN> skip_invalid<SPAN class="operator token">=</SPAN>skip_invalid<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1410</SPAN> <SPAN class="comment token">#----------------------------------------------------------------------</SPAN>
<SPAN class="number token">1411</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">to_hdf</SPAN><SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> path_or_buf<SPAN class="punctuation token">,</SPAN> key<SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">**</SPAN>kwargs<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token">/</SPAN>anaconda3<SPAN class="operator token">/</SPAN>lib<SPAN class="operator token">/</SPAN>python3<SPAN class="number token">.7</SPAN><SPAN class="operator token">/</SPAN>site<SPAN class="operator token">-</SPAN>packages<SPAN class="operator token">/</SPAN>arcgis<SPAN class="operator token">/</SPAN>features<SPAN class="operator token">/</SPAN>_data<SPAN class="operator token">/</SPAN>geodataset<SPAN class="operator token">/</SPAN>io<SPAN class="operator token">/</SPAN>fileops<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> to_featureclass<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">,</SPAN> out_name<SPAN class="punctuation token">,</SPAN> out_location<SPAN class="punctuation token">,</SPAN> overwrite<SPAN class="punctuation token">,</SPAN> out_sr<SPAN class="punctuation token">,</SPAN> skip_invalid<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">599</SPAN> <SPAN class="keyword token">return</SPAN> _pyshp_to_shapefile<SPAN class="punctuation token">(</SPAN>df<SPAN class="operator token">=</SPAN>df<SPAN class="punctuation token">,</SPAN>
<SPAN class="number token">600</SPAN> out_path<SPAN class="operator token">=</SPAN>out_location<SPAN class="punctuation token">,</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">601</SPAN> out_name<SPAN class="operator token">=</SPAN>out_name<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">602</SPAN> <SPAN class="keyword token">else</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">603</SPAN> <SPAN class="keyword token">raise</SPAN> Exception<SPAN class="punctuation token">(</SPAN><SPAN class="string token">"Cannot Export the data without ArcPy or PyShp modules. "</SPAN><SPAN class="operator token">+</SPAN> \
<SPAN class="operator token">/</SPAN>anaconda3<SPAN class="operator token">/</SPAN>lib<SPAN class="operator token">/</SPAN>python3<SPAN class="number token">.7</SPAN><SPAN class="operator token">/</SPAN>site<SPAN class="operator token">-</SPAN>packages<SPAN class="operator token">/</SPAN>arcgis<SPAN class="operator token">/</SPAN>features<SPAN class="operator token">/</SPAN>_data<SPAN class="operator token">/</SPAN>geodataset<SPAN class="operator token">/</SPAN>io<SPAN class="operator token">/</SPAN>fileops<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> _pyshp_to_shapefile<SPAN class="punctuation token">(</SPAN>df<SPAN class="punctuation token">,</SPAN> out_path<SPAN class="punctuation token">,</SPAN> out_name<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">93</SPAN> <SPAN class="keyword token">if</SPAN> idx <SPAN class="operator token">></SPAN> <SPAN class="operator token">-</SPAN><SPAN class="number token">1</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">94</SPAN> geom_type <SPAN class="operator token">=</SPAN> df<SPAN class="punctuation token">.</SPAN>loc<SPAN class="punctuation token">[</SPAN>idx<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">[</SPAN>geom_field<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">.</SPAN>type
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">95</SPAN> shpfile <SPAN class="operator token">=</SPAN> shapefile<SPAN class="punctuation token">.</SPAN>Writer<SPAN class="punctuation token">(</SPAN>GEOMTYPELOOKUP<SPAN class="punctuation token">[</SPAN>geom_type<SPAN class="punctuation token">]</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">96</SPAN> shpfile<SPAN class="punctuation token">.</SPAN>autoBalance <SPAN class="operator token">=</SPAN> <SPAN class="number token">1</SPAN>
<SPAN class="number token">97</SPAN> row_cols <SPAN class="operator token">=</SPAN> <SPAN class="punctuation token">[</SPAN><SPAN class="punctuation token">]</SPAN>
<SPAN class="operator token">/</SPAN>anaconda3<SPAN class="operator token">/</SPAN>lib<SPAN class="operator token">/</SPAN>python3<SPAN class="number token">.7</SPAN><SPAN class="operator token">/</SPAN>site<SPAN class="operator token">-</SPAN>packages<SPAN class="operator token">/</SPAN>shapefile<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> __init__<SPAN class="punctuation token">(</SPAN>self<SPAN class="punctuation token">,</SPAN> target<SPAN class="punctuation token">,</SPAN> shapeType<SPAN class="punctuation token">,</SPAN> autoBalance<SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">**</SPAN>kwargs<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1015</SPAN> self<SPAN class="punctuation token">.</SPAN>shp <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>shx <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>dbf <SPAN class="operator token">=</SPAN> None
<SPAN class="number token">1016</SPAN> <SPAN class="keyword token">if</SPAN> target<SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">1017</SPAN> self<SPAN class="punctuation token">.</SPAN>shp <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>__getFileObj<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>target<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'.shp'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1018</SPAN> self<SPAN class="punctuation token">.</SPAN>shx <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>__getFileObj<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>target<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'.shx'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">1019</SPAN> self<SPAN class="punctuation token">.</SPAN>dbf <SPAN class="operator token">=</SPAN> self<SPAN class="punctuation token">.</SPAN>__getFileObj<SPAN class="punctuation token">(</SPAN>os<SPAN class="punctuation token">.</SPAN>path<SPAN class="punctuation token">.</SPAN>splitext<SPAN class="punctuation token">(</SPAN>target<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">[</SPAN><SPAN class="number token">0</SPAN><SPAN class="punctuation token">]</SPAN> <SPAN class="operator token">+</SPAN> <SPAN class="string token">'.dbf'</SPAN><SPAN class="punctuation token">)</SPAN>
<SPAN class="operator token">/</SPAN>anaconda3<SPAN class="operator token">/</SPAN>lib<SPAN class="operator token">/</SPAN>python3<SPAN class="number token">.7</SPAN><SPAN class="operator token">/</SPAN>posixpath<SPAN class="punctuation token">.</SPAN>py <SPAN class="keyword token">in</SPAN> splitext<SPAN class="punctuation token">(</SPAN>p<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">120</SPAN>
<SPAN class="number token">121</SPAN> <SPAN class="keyword token">def</SPAN> <SPAN class="token function">splitext</SPAN><SPAN class="punctuation token">(</SPAN>p<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="operator token">-</SPAN><SPAN class="operator token">-</SPAN><SPAN class="operator token">></SPAN> <SPAN class="number token">122</SPAN> p <SPAN class="operator token">=</SPAN> os<SPAN class="punctuation token">.</SPAN>fspath<SPAN class="punctuation token">(</SPAN>p<SPAN class="punctuation token">)</SPAN>
<SPAN class="number token">123</SPAN> <SPAN class="keyword token">if</SPAN> isinstance<SPAN class="punctuation token">(</SPAN>p<SPAN class="punctuation token">,</SPAN> bytes<SPAN class="punctuation token">)</SPAN><SPAN class="punctuation token">:</SPAN>
<SPAN class="number token">124</SPAN> sep <SPAN class="operator token">=</SPAN> b<SPAN class="string token">'/'</SPAN>
TypeError<SPAN class="punctuation token">:</SPAN> expected str<SPAN class="punctuation token">,</SPAN> bytes <SPAN class="operator token">or</SPAN> os<SPAN class="punctuation token">.</SPAN>PathLike object<SPAN class="punctuation token">,</SPAN> <SPAN class="operator token">not</SPAN> int<SPAN class="line-numbers-rows"><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN><SPAN></SPAN></SPAN>Any help is appreciated.