Select to view content in your preferred language

"where shapefile in use?"

597
8
01-30-2024 08:33 AM
AntónioRuiFernandes
New Contributor

Hey guys.

I have a shapefile in a folder on my desktop and I'm afraid of deleting it.

Is there any way to know in which ArcGis project we are using a particular shapefile?

Thank you all.

0 Kudos
8 Replies
jcarlson
MVP Esteemed Contributor

There might be a way in ArcPy to loop through a series of projects and print off any data sources that are looking for a ".shp", but that's a bit outside of my expertise. I think you'll want the arcpy.mp module:

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/layer-class.htm

- Josh Carlson
Kendall County GIS
AntónioRuiFernandes
New Contributor

Thanks @jcarlson. I'll follow your tip.

0 Kudos
BobBooth1
Esri Contributor

I'm all for a Python solution.

There are some sample snippets in this help topic:

https://pro.arcgis.com/en/pro-app/latest/arcpy/mapping/updatingandfixingdatasources.htm

There is an old sample for inventorying a folder of ArcMap (.mxd) maps and reporting their data sources, but it would need to adapted to work with ArcGIS Pro projects. You could borrow the document iteration and CSV report writing logic from there.

https://www.arcgis.com/home/item.html?id=18c19ec00acb4d568c27bc20a72bfdc8

Another approach would be to zip up that folder (or move it to an archive drive) and keep it around for a while. If you find you need it, put it where it makes sense and fix the layer.

BobBooth1
Esri Contributor

Something like this should work:

import arcpy
import os

def find_files(folder_path, file_extension):
    file_list = []
    for root, dirs, files in os.walk(folder_path):
        for file in files:
            if file.endswith(file_extension):
                file_list.append(os.path.join(root, file))
    return file_list

# Example usage
folder_path = 'C:\\Users\\my_user_name\\Documents\\ArcGIS\\Projects\\'
file_extension = '.aprx'
found_projects = find_files(folder_path, file_extension)
#print(found_projects)
for a_project in found_projects:
    aprx = arcpy.mp.ArcGISProject(a_project)
    the_maps = aprx.listMaps()
    for a_map in the_maps:
        layers = a_map.listLayers()
        for layer in layers:
            try:
                print(layer.dataSource)
                # Check if he shapefile is used in this layer
                if layer.dataSource == 'your_path_to_shapefile':
                    print("The data source is here!")
            except:
                print("problem, dataSource may not be supported")
AntónioRuiFernandes
New Contributor

Thanks for your help, @BobBooth1 👍

0 Kudos
MarcBordelon
New Contributor II
A shape file (with all its files) will not tell you where its used. You will have to open your projects and see where that shp file has been used or remember what project you used it in. You can open your files that are in a folder and search it out. Those are the only ways to show where its been used. 
0 Kudos
AntónioRuiFernandes
New Contributor

Hi @MarcBordelon!

I know this is the most obvious, safest and probably the only solution.

My question was to know if anyone knows of another procedure that might have the same result.

The best thing is to have everything well organized, which I didn't have.

Thanks for your tip.

0 Kudos
RandyKreuziger1
Occasional Contributor

You might consider creating an archive file geodatabase and convert it to a feature class.  Add some metadata about where it was originally stored so that you can restore it later if necessary.  If you already have multiple copies elsewhere just ignore what I wrote.

0 Kudos