Select to view content in your preferred language

Creating Layers from files in memory

1404
4
Jump to solution
09-20-2021 09:37 AM
mattkramer
Frequent Contributor

Hello,

I was wondering if it was possible to create an "in_memory" or a "memory" feature layer from a downloaded zipped shapefile, without saving that zip file to the disk.  I am hoping to download multiple zip files from an ftp site and compile them into one final deliverable with only the final shapefile or feature class being written to disk.

 

Thanks, 

0 Kudos
1 Solution

Accepted Solutions
BlakeTerhune
MVP Regular Contributor

Could you use tempfile.mkdtemp() to make a temporary directory to unzip the shapefile and then clean it up when finished?

View solution in original post

4 Replies
BlakeTerhune
MVP Regular Contributor

Could you use tempfile.mkdtemp() to make a temporary directory to unzip the shapefile and then clean it up when finished?

mattkramer
Frequent Contributor

I was able to get this to work, I ended up using:

 

with TemporaryDirectory() as TempDownloadLocation:

            Download files using TempDownloadLocation

 

 

This format so once the code within the "with" statement was done, the temporary folder gets cleaned up automatically.

 

Thank you!


Luke_Pinner
MVP Regular Contributor

If you're using ArcGIS Pro 2.8+ you could install geopandas (in a cloned env). You can read from a zipfile URL directly into a geodataframe, append more geodataframes, and then write out to file

 

import geopandas as gpd

a_url = 'https://github.com/Toblerity/Fiona/raw/master/tests/data/coutwildrnp.zip'
gdf = gpd.read_file(a_url)

another_url = 'https://github.com/Toblerity/Fiona/raw/master/tests/data/coutwildrnp.zip'
gdf.append(gpd.read_file(another_url))

gdf.to_file('test.shp')

 

 

mattkramer
Frequent Contributor

Since I will be packaging this into a tool for other users to use, I decided to not go this route.  I don't think I can get some non programming folk to install geopandas.  Thank you though!

0 Kudos