ThinkGeo.com    |     Documentation    |     Premium Support

Shapefiles not updating

Hello,

I’m developing a WPF app that displays several shapefiles.
during our normal course of business, we need to update the shapefiles that are in use to a new version that has the same name.

When loading the new files, not all of the new features are displayed. I assume this has to do with caching.
Is there a way to disable this, or a directory I need to clear out for the files to be properly displayed?

Thanks,

Aaron

Hi Aaron,

I created a sample according to your description, and I found an issue like you mentioned: after updating the shapefile, and zoom to new extent, the map did render new features, but when zoom back to previous extents, it would still render the old features.

Did you ran into the same issue? Here’s my sample, could you take a look and update the code if I missed anything?

Shapefiles_sample.zip (114.5 KB)

Thanks,
Leo

Hello Leo,

This is very similar to what I was seeing yes.

In my particular case, I never saw the new shapes even when zooming in or out.

To give you an idea of what I’m doing…

I created a basic line shapefile to be displayed on the map.
When loading the shapefile in code I create a spatial index as my files rarely ever have them.
Add the shapefile to the map and load.

Then…

I Modify the existing shape file and copy it into my data directory. Because the files I create/modify don’t have an index file associated with them, the older index file is not updated.

When I re-run the program, the code to create the index files still runs, but I don’t know if it actually re-creates it if they already exist.

The modified features in the shape file are not displayed at all.

I did find that if I delete and recreate the index files the new features are displayed.
If I just have to delete the index file and recreated it after adding the new shapefile that’s fine, I just need to know that that is the case.

I’ll see if I can come up with a basic example detailing what I’m doing.

Regards,

Aaron

Hello Leo,

I’ve attached a sample app. Please see the ReadMe file for details.Shapefile_Not_Updting.zip (17.1 KB)

Hi Aaron,

Thanks for your sample and README, I can recreate your issue.

I found my sample would work after removing the following code, but there’s no cache relevant code in your sample.
lo.TileCache = new FileRasterTileCache();

May I know where did you get your shapefiles? What tool did you use to create it?

Thanks,
Leo

Hi Aaron,

I made some changes with the sample:

  1. remove “lo.TileCache = new FileRasterTileCache();”

  2. close the shapefilelayer and open it after updating the shapefile, the refresh the overlay

As you can see the gif, the features can be rendered correctly.

shapefile_updating_sample.zip (13.6 KB)

Thanks,
Leo