Review of the `read_shapefile` and `kl_divergence` notebooks
noahbouchier opened this issue · comments
As the first evidence of code that will help to form the output of my Google Summer of Code project - I'd be appreciative of any feedback on the read_shapefile
and kl_divergence
notebooks.
Some of the explanatory text is quite beefy, so feel free to skim that!
Please note - the kl_divergence
notebook has just been updated to include use and explanation of the scipy.spatial.distance_matrix
function
Please note - today's (gitmoji-inspired) update raises an issue within read_shapefile.ipynb.
The issue is within the final code block - In[16] - where the following line is returning an error:
leicester_oa_eth_shp.to_file("../leicester/data/leicester_ethnicity.gpkg", driver = "GPKG")
The crux of the error appears to be the following:
DriverError: sqlite3_open(../leicester/data/leicester_ethnicity.gpkg) failed: unable to open database file
Any help would be greatly appreciated - my searching seems to only identify this problem within other pieces of software, which make the solution hard to translate
Odd! Is there a file existing there when you open it in Finder?
If there are issues, it's OK to use a shape file for now.
Hey!
Unfortunately adding the layer argument still returns the same issue.
There isn't a file in that location locally - I supposed that the to.file
would create the file, as I've experienced previously with the shape files. But that did cross my mind when reading the error.
Is it worth creating a GeoPackage to then update? If so, how's best to do that?
Do the above three lines work?
Yes - they create a 324KB file on my desktop that I've been able to successfully read back in under a different object name
@noahbouchier worked through the notebook on my local machine. You need to specify the full path when using .to_file(...)
.
Remove the .. and use the full path.
I got the same error as you when trying to save with '../'. Once I put in the full path I was able to save the GPKG.
Example:
# Save the new file as a shapefile, titled 'leicester_ethnicity'
leicester_oa_eth_shp.to_file("C:/Users/USER/Desktop/leicester_ethnicity.gpkg", driver = "GPKG")
@jeffcsauer thanks so much for your help! Your solution helped me to identify the problem - stemming from my oversight.
The file path to_file
was attempting to write to ("../leicester/data/leicester_ethnicity.gpkg"
) was incorrect, and related to a previous iteration of the workbook.
Within the GitHub repository, the correct file path is:
"../Example Data - Leicester, UK/leicester_ethnicity.gpkg"
When I use this, the GeoPackage file is created exactly as it should be, like a dream.
Thanks for your help, and apologies for the error that created the problem
no prob! the error raised when the path is wrong are not the most informative... glad you figured it out!