Here is my question:
- the 2-d numpy array data represent some property of each grid space
- the shapefile as the administrative division of the study area(like a city).
For example:
http://i4.tietuku.com/84ea2afa5841517a.png
The whole area has 40x40 grids network, and I want to extract the data inside the purple area. In other words , I want to mask the data outside the administrative boundary into np.nan.
My early attempt
I label the grid number and select the specific array data into np.nan.
http://i4.tietuku.com/523df4783bea00e2.png
value[0,:] = np.nan
value[1,:] = np.nan
.
.
.
.
Can Someone show me a easier method to achieve the target?
Add
Found an answer here which can plot the raster data into shapefile, but the data itself doesn't change.
Update -2016-01-16
I have already solved this problem inspired by some answers.
Someone which are interested on this target, check this two posts which I have asked:
1. Testing point with in/out of a vector shapefile
2. How to use set clipped path for Basemap polygon
The key step was to test the point within/out of the shapefile which I have already transform into shapely.polygon.