Meteoinfolab Script Example: Inpolygon

Source: Internet
Author: User

The Inpollygon function is used to determine whether the data with coordinates (x/y) is in one or a set of polygons (Polygon), and the returned result is a value of 1 if the polygon is made, otherwise the value is-1. The following example shows the use of a shape file and the Inpolygon function to generate this 0, 1 data. Need to download the latest Meteoinfo version (1.2.6R1): http://yun.baidu.com/share/link?shareid=669776748&uk=51062435

1, generate a lattice point data (2-dimensional array), you can use the Zeros function:
A = Zeros ((50,80), dtype= ' int ')
The resulting array A is a 2-dimensional array of 50*80 with a value of 0.

2. Generate the coordinates of the lattice data (x/y), the Arange1 function generates a 1-dimensional array, and three parameters are the starting value, the number, and the step size, respectively.

3. Read the shape file and return a layer M_china.

4. Use the Inpolygon function of array A to generate a new array b,b the value of the points within the polygon is 1, the other is-1.

5, change the B-1 to 0.

6. Use the Savegrid method of array B to save array B and its coordinate information in a surfer ASCII grid format file.

7, drawing, this is to test it. The 1 in array B is indicated by a red dot, and 0 is shown with a gray dot.

Script Program:

#Create a 50*80 2D arrayA = Zeros ((50,80), dtype='int')#Create x/y vectorx = Arange1 (60, 80, 1) y= Arange1 (10, 50, 1)#Read shape FileM_china = Shaperead ('d:/temp/map/china.shp')#Inpolygon function, In:1, out:-1b =A.inpolygon (x, y, M_china)#Change-1 to 0B[b==-1] =0#Save to a surfer ASCII grid data filefn ='D:/temp/test/sdata.dat'B.savegrid (x, Y, fn)#Plotaxesm () geoshow (M_china) SS= Makesymbolspec (' Point', {'value'70A'Color':'Lightgray','size': 2,'Edge': False}, {'value': 1,'Color':'Red','size': 2,'Edge': False}) Layer= Scatterm (x, y, B, Symbolspec=ss)

Meteoinfolab Script Example: Inpolygon

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.