# How update existing layer from DB?

**URL:** <https://mapwindow.discourse.group/t/how-update-existing-layer-from-db/223>\
**Category:** MapWinGIS\
**Created:** [August 12, 2019, 3:49pm UTC](https://mapwindow.discourse.group/t/how-update-existing-layer-from-db/223 "2019-08-12T15:49:58Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![HenrikKartin](https://avatars.discourse-cdn.com/v4/letter/h/c89c15/32.png) [@HenrikKartin](https://mapwindow.discourse.group/u/HenrikKartin)\
**Post date:** [August 12, 2019, 3:49pm UTC](https://mapwindow.discourse.group/t/how-update-existing-layer-from-db/223/1 "2019-08-12T15:49:58Z")

</div>

I’m relatively new to MapWinGIS. So this may be a simple question.

I’m using axMap.AddLayerFromDatabase to add a layer to my map with a query. And it works like a charm.

Now I want to change this existing layer to show the result of another query from the same table in the DB. In other words I just need to modify the query and re-run.

In reality I’m working on a ViewPort-function that activates every time the map bounds change.

But for simplicity let’s work with this example: Let’s say that I query a DB table containing world continents to show only Australia.  
Then I select anothor continent - Europe - from a list in my window.  
Now I want the same layer to remove Australia and show Europe instead.

How do I do this?

I have tried to use axMap.ReSourceLayer and it removes my first selection alright, but it does not update the layer with new data. Even when I issue a axMap.ReDraw.

Note: I’m working with large quantiies of data (billions of rows). That’s why I need the selection to be done from the DB instead of loading data to RAM a use the internal quering tool.

Regards,

Henrik

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [August 25, 2019, 1:44am UTC](https://mapwindow.discourse.group/t/how-update-existing-layer-from-db/223/2 "2019-08-25T01:44:24Z")

</div>

Perhaps this is too simplistic, but could you just remove the existing layer and add a new layer based on the new query?

---

<div class="post-metadata">

**Author:** ![HenrikKartin](https://avatars.discourse-cdn.com/v4/letter/h/c89c15/32.png) [@HenrikKartin](https://mapwindow.discourse.group/u/HenrikKartin)\
**Post date:** [September 10, 2019, 2:15pm UTC](https://mapwindow.discourse.group/t/how-update-existing-layer-from-db/223/3 "2019-09-10T14:15:48Z")

</div>

At first I choose to remove and add the layer again.  
But it turns out that there is a RedefineQuery() method on the Layer.  
That does the trick.

---

<div class="post-metadata">

**Author:** ![jerryfaust](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/jerryfaust/32/378_2.png) [@jerryfaust](https://mapwindow.discourse.group/u/jerryfaust)\
**Post date:** [September 10, 2019, 7:05pm UTC](https://mapwindow.discourse.group/t/how-update-existing-layer-from-db/223/4 "2019-09-10T19:05:39Z")

</div>

Excellent. Thanks for sharing the solution.

---

<div class="post-metadata">

**Author:** ![pmeems](https://yyz2.discourse-cdn.com/free1/user_avatar/mapwindow.discourse.group/pmeems/32/9_2.png) [@pmeems](https://mapwindow.discourse.group/u/pmeems)\
**Post date:** [January 5, 2022, 3:08pm UTC](https://mapwindow.discourse.group/t/how-update-existing-layer-from-db/223/5 "2022-01-05T15:08:51Z")

</div>


