Skip to content

Filtration

giprozem edited this page Jun 9, 2023 · 3 revisions

Filtering is carried out in accordance with the selected data from the form.

code exemple:

form: FormGroup = new FormGroup({
    region: new FormControl<number | null>(null),
    district: new FormControl<string | null>({ value: null, disabled: true      }),
    example: new FormControl<string | null>({ value: null, disabled: true }),
    type: new FormControl<string | number | null>(null),
    culture: new FormControl<string | number | null>(null),
    productivity: new FormControl<number | null>(null),
    year: new FormControl<number | null>(null, Validators.required),
    code_soato: new FormControl<string | null>(null, Validators.required),
    ink: new FormControl<string | null>(null, Validators.required),
});

Filtering extends to the following code sections:

1. GeoJSON filtering:

There is a request to the server depending on the valueland_type which
changes in the form of filtering.

code exemple:

let polygons: GeoJSON;

polygons = await this.api.map.getPolygonsInScreen({
  latLngBounds: mapBounds,
  land_type: landType.id,
});


this.mapData.geoJson.options.snapIgnore = true;
this.mapData.geoJson.options.pmIgnore = true;
this.mapData.geoJson.options.style = {
   fillOpacity: 0,
   weight: 0.4,
};


this.mapData.geoJson.addData(polygons);

2. Layers from GeoServer:

Method in which data from GeoServer is filtered depending on values in the form of filtering. All this is filtered using CQL.

code exemple:

private buildWmsCQLFilter() {
    if (in != null) {
      this.wmsCQLFilter = '';
    Filtering by region
      if (in.region) {
        if (this.wmsCQLFilter.length > 0) {
          this.wmsCQLFilter += '&&';
        }
        this.wmsCQLFilter += 'rgn=' + in.region;
      }
      Filtering by districts
      if (in.district) {
        if (this.wmsCQLFilter.length > 0) {
          this.wmsCQLFilter += '&&';
        }
        this.wmsCQLFilter += 'dst=' + in.district;
      }
      Filtering by cantons
      if (in.example) {
        if (this.wmsCQLFilter.length > 0) {
          this.wmsCQLFilter += '&&';
        }
        this.wmsCQLFilter += 'cntn=' + in.example;
      }
      Filtering by culture
      if (in.culture) {
        const val = in.culture;
        if (this.wmsCQLFilter.length > 0) {
          this.wmsCQLFilter += '&&';
        }
        if (typeof val === 'string' && val.split(',').length > 1) {
          this.wmsCQLFilter += val
            .split(',')
              etc ………

3. Map scaling and positioning depending on data filters:

code exemple:

    async handleDistrictChange(value: string | null) {
        const contonVal = this.form.get('example');
        if (value != null) {


        const district = (await this.api.dictionary.getDistricts({
            id: value,
            polygon: true,
        })) as IDistrict[];


        Depending on the district data, the map is positioned within
        coordinates district[0]?.polygon.
        this.mapInstance.fitBounds(geoJson(district[0]?.polygon).getBounds());
    
        ...
    }


    async handleRegionChange(value: string | null) {
        const districtVal = this.form.get('district');
        const region = this.regions.find((r) => r.id == Number(value));
        region &&


        Depending on the region data, the map is positioned within
        coordinates region?.polygon.
        this.mapInstance.fitBounds(geoJson(region?.polygon).getBounds(), {
            maxZoom: 12,
        });


        ...
    }

3. Pasture and arable land statistics (area of ​​productivity and crops)

Pasture.

code exemple:

private async getPastureStatisticsProductivity( 
   query: IContourStatisticsProductivityQuery
): Promise<void> {
    Here, the request mode is checked and, depending on the condition, is  
    added property AI (Artificial Intelligence).
    if (this.isWmsAiActive) query.eat = this.isWmsAiActive;
    try {
    let res: IContourStatisticsProductivity;
    res = await     
    There is a request depending onIContourStatisticsProductivityQuery  
    which is formed based on the values ​​of the filtering form.
    this.api.statistics.getContourStatisticsProductivity(query);
    }
}

Arable land.

code exemple:

private async getCultureStatisticsProductivity(
    query: ICulutreStatisticsQuery
): Promise<void> {
    Here, the request mode is checked and, depending on the condition, is 
    added property AI (Artificial Intelligence).
    if (this.is msI Active) query.eat = this.isWmsAiActive;


    try {
    There is a request depending onICulutreStatisticsQuery 
    which is formed based on the values ​​of the filtering form.
    const res = await this.api.statistics.getCultureStatistics(query);


    ...
}

Clone this wiki locally