GEE: Filter the boundaries of the desired administrative districts (based on attribute data and hand-drawn point/polygon methods)

Filter the data of the specified attribute information after importing the vector layer

After the vector layer is introduced, gee users often choose a small piece of the vector layer for research (for example, the vector layer of China's provinces is introduced, but the research area only involves Anhui Province). This will use Filter function, filter out Anhui Province from the Chinese vector layer.
Of course, the simpler method is to filter out Anhui Province from ArcGIS or other software, export it, and then import it into Geemap, but this is time-consuming and labor-intensive.
Generally, users have two needs: ① Select a small area
from a large area as the experimental area; ② Select multiple small areas from a large area as the experimental area

Attribute table information of Hengyang City:

(Here, take the selection of Hengnan County from Hengyang City, Hunan Province as an example)
insert image description here

1. Select a small area from the large area as the experimental area

1. The first method:

Use the .filterMetadata('PYNAME','equals','Hengnan Xian') command:
it refers to the vector area whose metadata PYNAME is equal to Hengnan Xian.
Of course, you can also use other attribute information to filter, just change the field name in the function

var HengYangShi= ee.FeatureCollection(HY);
var HengnanXian= HengYangShi.filterMetadata('PYNAME','equals','Hengnan Xian');

Among them, HY is the vector layer of Hengyang City introduced.

2. The second method:

Query the position of the point in Hengnan County in advance, and introduce a point in Hengnan County,

var Roi_HengnanXian = ee.Geometry.Point(114,30)

Or draw a point in Hengnan County by hand in Geemap
insert image description here
insert image description here
, and then use the following command (the point is included in the polygon) to filter the vector area of ​​Hengnan County from Hengyang City.

//用point筛选HengYangShi
var HY = table.filterBounds(Roi_HengnanXian).geometry();

The result is shown in the figure below
insert image description here

3. Other methods

If using the first method will save a lot of work, there are other methods besides the above two methods.

2. Select multiple small areas from a large area as the experimental area

1. Use attribute information to filter multiple areas

insert image description here
The table in the figure below is the Hengyang vector map imported in the figure above

var HengYangShi = ee.FeatureCollection(table);
var Name_List       = ee.List( ['Hengdong Xian','Hengyang Xian','Qidong Xian','Hengnan Xian'] );
var Inlist_Filter   = ee.Filter.inList( 'PYNAME', Name_List);
var List_Features   = HengYangShi.filter( Inlist_Filter );
Map.addLayer(List_Features)

Filter the vector region in the PYNAME field containing all the elements in the list by the name list built.
The result is shown in the figure,
insert image description here

2. Draw a polygonal area by hand

As shown in the figure below, first draw a polygonal area by hand.
insert image description here
At this time, a hand-painted polygon appears in the resource bar
insert image description here
, and then use .filterBounds() to filter the area where the large area intersects with the hand-painted polygon as a test area

var HY = table.filterBounds(geometry).geometry();
Map.addLayer(HY)

insert image description here

3. Other methods

Of course, there are other screening methods, including using geospatial variables to perform operations such as Boolean operations, mathematical operations, and sorting.


.filterMetadata() usage notes

filterMetadata(name, operator, value)
Shortcut for filtering collections by metadata.
This operation is equivalent to .filter(ee.Filter.metadata(…)).
Returns the filtered collection.
Parameters:
this:collection (Collection):
The Collection instance.
name (String): The name of the property to filter.
operator (String): The name of the comparison operator.
Other possible values: "equals", "less_than", "greater_than", "not_equals", "not_less_than", "not_greater_than", "starts_with", "ends_with", "not_starts_with", "not_ends_with", "contains"
,
" not_contains”.
value (Object): The value to compare.
Returns: Collection


.inList() usage instructions

ee.Filter.inList(leftField, rightValue, rightField, leftValue)
Filter the metadata contained in the pre-constructed list.
Returns the constructed filter.
Parameters:
leftField (String, optional):
The selector for the left operand. If leftValue is specified, it should not be specified.
rightValue (List|Object, optional):
The value of the right operand. Should not be specified if rightField is specified.
The value of the right operand. If rightField is specified, it should not be specified
rightField (String, optional):
selector for the right operand. If rightValue is specified,
leftValue (List|Object, optional):
the value of the left operand should not be specified. If leftField is specified, it should not be specified.
Returns: Filter

Guess you like

Origin blog.csdn.net/qq_35591253/article/details/108960130