From 8c6078149d3c1ff1e0b17bf76cb792ef33d5b6e0 Mon Sep 17 00:00:00 2001 From: Milad Rafiei <166007313+MiladRafiei@users.noreply.github.com> Date: Sun, 22 Sep 2024 14:44:02 +0330 Subject: [PATCH 1/4] Create 2024-09-24-geospatial-techno.md --- _posts/2024-09-24-geospatial-techno.md | 145 +++++++++++++++++++++++++ 1 file changed, 145 insertions(+) create mode 100644 _posts/2024-09-24-geospatial-techno.md diff --git a/_posts/2024-09-24-geospatial-techno.md b/_posts/2024-09-24-geospatial-techno.md new file mode 100644 index 000000000..396a78324 --- /dev/null +++ b/_posts/2024-09-24-geospatial-techno.md @@ -0,0 +1,145 @@ +--- +author: Milad Rafiei +layout: post +title: Using Spatial Operators in GeoServer Filters +date: 2024-09-24 +categories: +- Tutorials +--- + +[GeoSpatial Techno](https://www.youtube.com/@geospatialtechno) is a startup focused on geospatial information that is providing e-learning courses to enhance the knowledge of geospatial information users, students, and other startups. The main approach of this startup is providing quality, valid specialized training in the field of geospatial information. + +( [YouTube](https://www.youtube.com/@geospatialtechno) +| [LinkedIn](https://www.linkedin.com/in/geospatialtechno) +| [Facebook](https://www.facebook.com/geospatialtechno) +| [X](https://twitter.com/geospatialtechn) +) + +---- + +### Spatial Operators in GeoServer Filters +In this session, we want to talk about the **Spatial operators in GeoServer** in detail. If you want to access the complete tutorial, click on the [link](https://www.youtube.com/watch?v=mYD0sCNiczE&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL). + +[![](https://img.youtube.com/vi/mYD0sCNiczE/0.jpg)](https://www.youtube.com/watch?v=mYD0sCNiczE&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL) + +## Introduction +GeoServer supports various spatial operators that filter geospatial data based on their location or spatial relationships with other features. These operators are commonly used with other filter expressions to create complex queries. These queries are useful for extracting specific subsets of data from a larger dataset. + +The spatial operators are Topological, Distance, and Bounding Box operators. We'll explain them in more detail below. + +**Note.** This video was recorded on GeoServer 2.22.4, which is not the most up-to-date version. Currently, versions 2.24.x and 2.25.x are supported. To ensure you have the latest release, please visit this [link](https://geoserver.org/download/) and avoid using older versions of GeoServer. + +## Topological operators +In GeoServer, topological operators are used for spatial analysis and processing of geographic data. These operators perform geometric operations that preserve the spatial relationship or topology between geometric features. Some common topological operators in GeoServer include: Intersects, Within, Contains, etc. + +### Intersects +The **Intersects** filter in GeoServer is used to query spatial data based on the intersection of two geometry objects. For example, you can use this operator to extract all features that intersect with a specified Point, Line, or Polygon. + +Here are some examples of how you can use this filter in an XML request to filter the `States` layer by the `State_Name` attribute: + +- Navigate to the **Demos** page, then select **Demo requests**. +- From the Request section, select the **WFS_getFeatureIntersects1.0.xml** request. +- The address will be filled in automatically, in the URL section. +- Now, we will explain some elements: + - The first thirteen lines include explanations in the form of comments. + - Line 14 describes the XML version and the `getFeatureIntersects` operation of the WFS service being used. + - Line 15 specifies the default output format for the WFS service as `GML2`. Additionally, GeoServer supports several other commonly used formats such as "gml3, shapefile, geojson, and csv." + - Lines 16 to 22 define the start of the XML request and declare the namespaces used in the request. + - Line 23 specifies the type name of the feature to be queried. In this case, it requests features of the `topp:states`. + - Lines 25 to 30 define the filter criteria for the query. On these lines, we use the **Intersects** filter, to retrieve all states that intersects with a Point defined by latitude and longitude. + +- Press the **Submit** button. + +**Note.** For GeoServer 2.25.2 the Demo Request page has been improved to show response Headers, and provide the option to pretty print XML output. + +### Within +This operator is used to retrieve features that are completely within the specified geometry. For example, you can use this operator to extract all features that are within a polygon. + +Here's an example of how you can define a `Within` filter in XML. As an example of using this filter in a WFS getFeature request, use the following block codes to replace lines 24 to 31: + + + + the_geom + + + + -90.73,29.85 -90.73,35.92 -80.76,35.92 -80.76,29.85 -90.73,29.85 + + + + + + +Press the **Submit** button. As you can see, the result includes two states named `Alabama` and `Georgia`. + +### Contains +This operator is used to filter data that is completely contained within a given geometry. For example, you can use this operator to extract all features that are completely contained within a polygon that represents a state boundary. + +Here's an example of how you can define a `Contains` operator in XML: + + + + the_geom + + -89.35,31.46 -89.35,32.11 -89.49,32.23 -90.21,32.23 + + + + +Press the **Submit** button. As you can see, the state that contains the given geometry is `Mississippi`. + +You will need to adjust the filter and shape to match your data and SRS. Assuming you have a data source with a geometry column named the_geom that uses the EPSG:4326 coordinate system. + +## Distance operators +In GeoServer, Distance operators like "DWithin" and "Beyond" filters, are used to filter and retrieve features based on their spatial relationship and proximity to a given geometry or location. These operators can be used in WFS requests and are useful for performing spatial analysis and finding nearby features. + +### DWithin +The 'DWithin' or 'Distance Within' filter, will return records that are located within a specific distance of a defined point, much like a buffer. As well as the point geometry, you must specify the value of the distance from this point and the unit of measure. The units for the DWithin are: Feet, meters, kilometers and miles. + +Here's an example of how to use the `DWithin` filter in a GeoServer XML configuration file. To find all the features that are within `10000` meters of a given point in a layer called "sf:archsites", the following WFS request can be used. + + + + + + the_geom + + 593250,4923867 + + 10000 + + + + + +This will return all the features in "sf:archsites" layer, that are within 10000 meters of the given point. +Remember that, the EPSG code mentioned in line 11 is very important because it serves as a reference point for importing coordinates and distance values. + +Press the **Submit** button. + +## Bounding Box operators +The Bounding Box operator is used to filter data based on a specified bounding box. A bounding box is a rectangular region defined by its lower left and upper right coordinates: minx, miny, maxx, and maxy. For example, you can use this operator to extract all features that are located or partially located inside a box of coordinates. + +As an example of using this operator, select the **WFS_getFeatureBBOX1.0.xml** from the Request section. Now the filters block code is as follows: + + + + the_geom + + -75.102613,40.212597 -72.361859,41.512517 + + + + +In this case, we just get the `STATE_NAME` and `PERSONS` attribute. +Using the range specified in the code specifies the features that are completely or partially located in this area. +The result includes four states named `New York`, `Pennsylvania`, `Connecticut`, and `New Jersey` as you see on the screen. + +---- + +In this session, we took a brief journey through the "Spatial operators in GeoServer". If you want to access the complete tutorial, click on the [link](https://www.youtube.com/watch?v=mYD0sCNiczE&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL). \ No newline at end of file From 69eb9b1d2652d12506726f0094e63ecbd48fa771 Mon Sep 17 00:00:00 2001 From: Milad Rafiei <166007313+MiladRafiei@users.noreply.github.com> Date: Sun, 22 Dec 2024 00:34:35 +0330 Subject: [PATCH 2/4] Create 2024-12-25-geospatial-techno.md Logical filtering --- _posts/2024-12-25-geospatial-techno.md | 195 +++++++++++++++++++++++++ 1 file changed, 195 insertions(+) create mode 100644 _posts/2024-12-25-geospatial-techno.md diff --git a/_posts/2024-12-25-geospatial-techno.md b/_posts/2024-12-25-geospatial-techno.md new file mode 100644 index 000000000..2d0bafe09 --- /dev/null +++ b/_posts/2024-12-25-geospatial-techno.md @@ -0,0 +1,195 @@ +--- +author: Milad Rafiei +layout: post +title: Using Logical Operators in GeoServer Filters +date: 2024-12-24 +categories: +- Tutorials +--- + +[GeoSpatial Techno](https://www.youtube.com/@geospatialtechno) is a startup focused on geospatial information that is providing e-learning courses to enhance the knowledge of geospatial information users, students, and other startups. The main approach of this startup is providing quality, valid specialized training in the field of geospatial information. + +( [YouTube](https://www.youtube.com/@geospatialtechno) +| [LinkedIn](https://www.linkedin.com/in/geospatialtechno) +| [Facebook](https://www.facebook.com/geospatialtechno) +| [X](https://twitter.com/geospatialtechn) +) + +---- + +### Using Logical Operators in GeoServer Filters +In this session, we want to talk about the **Using logical operators to combine multiple filters** in GeoServer. If you want to access the complete tutorial, click on the [link](https://www.youtube.com/watch?v=_9bTXVGqlcA&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL). + +[![](https://img.youtube.com/vi/_9bTXVGqlcA/0.jpg)](https://www.youtube.com/watch?v=_9bTXVGqlcA&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL) + +## Introduction +Logical operators in Web Feature Service (WFS) filtering are essential for combining multiple conditions within GeoServer. These operators enable users to construct complex queries, facilitating data retrieval from the WFS service. The primary logical operators include **AND**, **OR**, and **NOT**. + +**Note.** This video was recorded on GeoServer 2.22.4, which is not the most up-to-date version. Currently, versions 2.25.x and 2.26.x are supported. To ensure you have the latest release, please visit this [link](https://geoserver.org/download/) and avoid using older versions of GeoServer. + +### AND +This operator combines multiple conditions into a single filter expression. The resulting expression matches only those features that meet all of the specified criteria. + +- As an example of using this filter in WFS getFeature request, navigate to the **Demos** page, then select **Demo requests**. +- From the **Request** section, select the **WFS_getFeature1.0.xml** request. + +Use the following block codes to replace line 26: + + + + LAND_KM + 100000 + + + PERSONS + 5000000 + + + +**Note.** In all examples in this blog post, we utilize the `topp:states` layer. + +In this example, we applied a filter to the layer, where the value of the `LAND_KM` attribute, is less than 100,000 **and** the `PERSONS` is greater than 5 million people. + +The results include three states: `Massachusetts`, `New Jersey` and `Indiana`. + + +To use the CQL filtering to apply the equivalent of this example, first, preview the `top:states` layer in the **Layer Preview** section. Then, add the filter `CQL_FILTER=LAND_KM<100000 And PERSONS>5000000` to the end of the URL. + +The complete URL for the layer is as follows: + + http://localhost:8080/geoserver/topp/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp%3Astates&bbox=-124.73142200000001,24.955967,-66.969849,49.371735&width=768&height=330&srs=EPSG%3A4326&styles=&format=application/openlayers&CQL_FILTER=LAND_KM<100000 And PERSONS>5000000 + + +### OR +This operator allows you to combine multiple conditions and retrieve features that satisfy any of the specified conditions. In simpler terms, at least one condition must be true for the filter to be considered a match. + +Here's an example of how to use the "OR" operator to filter a WFS layer based on two conditions. + + + + LAND_KM + 100000 + + + PERSONS + 5000000 + + + + +Press the **Submit** button. + +In this example, we filtered the layer to display features that meet either of these conditions: The value of the `LAND_KM` attribute is less than 100,000 **or** the `PERSONS` attribute represents a population greater than 5 million people. The results include `25` states. + + +To apply the same example using the CQL filtering and observe the results, use the following code in the URL of the layer as mentioned above: + + http://localhost:8080/geoserver/topp/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp%3Astates&bbox=-124.73142200000001,24.955967,-66.969849,49.371735&width=768&height=330&srs=EPSG%3A4326&styles=&format=application/openlayers&CQL_FILTER=LAND_KM<100000 Or PERSONS>5000000 + + +### NOT +In GeoServer, the **NOT** operator, also known as the logical negation operator, is used to invert the meaning of a filter expression. It takes one or more filter expressions and returns features that don't meet the specified conditions. + +Here's an example of using the "NOT" operator for filtering a WFS layer by two conditions: + + + + + LAND_KM + 100000 + + + PERSONS + 5000000 + + + + + +Press the **Submit** button. + +In this example, we filtered the layer to show features that don't meet any of these conditions. That is, neither the value of the `LAND_KM` attribute is less than 100,000 **nor** is the value of the `PERSONS` parameter more than 5 million people. The results include `24` states. + +To see how to use the NOT operator in CQL filtering, use the following code at the end of the URL’s layer: + + http://localhost:8080/geoserver/topp/wms?service=WMS&version=1.1.0&request=GetMap&layers=topp%3Astates&bbox=-124.73142200000001,24.955967,-66.969849,49.371735&width=768&height=330&srs=EPSG%3A4326&styles=&format=application/openlayers&CQL_FILTER=NOT(LAND_KM<100000 Or PERSONS>5000000) + + +## Combine operators +GeoServer provides the capability of combining logical operators with geometric filters, enhancing the flexibility of WFS filtering. This feature enables users to create more specific and reliable filtering criteria. + +Here is an example that effectively uses both spatial and comparison filtering: + + + + + the_geom + + -73.9,43.5 -81.1,38.6 -78.57,35.5 + + + + PERSONS + 10000000 + + + + + +In this example, we filtered out states with populations exceeding 10 million, as well as states intersected by a LineString with given coordinates. + +Thus, we identified `New York` and `Pennsylvania` as the two states that satisfy these conditions. + + +To see how to use CQL filtering for this example, follow the instance shown on the screen: + + + CQL_FILTER=INTERSECTS(the_geom,LINESTRING(-73.9 43.5,-81.1 38.6,-78.57 35.5)) AND PERSONS>10000000 + + +As a final example, we examine a comprehensive scenario that incorporates different operators. This example includes a spatial operator, such as the Within filter. Additionally, it showcases two comparison operators, namely `PropertyIsLike` and `PropertyIsGreaterThan`. + +To better understand these concepts, use the following example: + + + + + + the_geom + + + + -100,30 -100,45 -80,45 -80,30 -100,30 + + + + + + + + STATE_NAME + %na% + + + + STATE_FIPS + 30 + + + + + + +In this example, we use WFS filtering to extract the States that are completely enclosed within specific coordinates. Moreover, we retrieve States whose `STATENAME` includes the letters "na" or whose `STATEFIPS` value is greater than 30. + +Therefore, we have identified three states that meet the specified criteria: `Tennessee`, `Indiana`, and `Ohio`. + + +To use the CQL filtering for this example, use the following code: + + CQL_FILTER=Within(the_geom,Polygon((-100 30,-100 45,-80 45,-80 30,-100 30))) AND (STATE_NAME LIKE '%na%' OR STATE_FIPS > 30) + + +---- + +In this session, we took a brief journey through the **Combining multiple operators for WFS filtering** in GeoServer. If you want to access the complete tutorial, click on the [link](https://www.youtube.com/watch?v=_9bTXVGqlcA&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL). \ No newline at end of file From 83c39568105289af826fe8aab8a0913fea1f8c1e Mon Sep 17 00:00:00 2001 From: MiladRafiei <166007313+MiladRafiei@users.noreply.github.com> Date: Mon, 23 Dec 2024 00:42:39 +0330 Subject: [PATCH 3/4] Delete _posts/2024-09-24-geospatial-techno.md --- _posts/2024-09-24-geospatial-techno.md | 145 ------------------------- 1 file changed, 145 deletions(-) delete mode 100644 _posts/2024-09-24-geospatial-techno.md diff --git a/_posts/2024-09-24-geospatial-techno.md b/_posts/2024-09-24-geospatial-techno.md deleted file mode 100644 index 396a78324..000000000 --- a/_posts/2024-09-24-geospatial-techno.md +++ /dev/null @@ -1,145 +0,0 @@ ---- -author: Milad Rafiei -layout: post -title: Using Spatial Operators in GeoServer Filters -date: 2024-09-24 -categories: -- Tutorials ---- - -[GeoSpatial Techno](https://www.youtube.com/@geospatialtechno) is a startup focused on geospatial information that is providing e-learning courses to enhance the knowledge of geospatial information users, students, and other startups. The main approach of this startup is providing quality, valid specialized training in the field of geospatial information. - -( [YouTube](https://www.youtube.com/@geospatialtechno) -| [LinkedIn](https://www.linkedin.com/in/geospatialtechno) -| [Facebook](https://www.facebook.com/geospatialtechno) -| [X](https://twitter.com/geospatialtechn) -) - ----- - -### Spatial Operators in GeoServer Filters -In this session, we want to talk about the **Spatial operators in GeoServer** in detail. If you want to access the complete tutorial, click on the [link](https://www.youtube.com/watch?v=mYD0sCNiczE&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL). - -[![](https://img.youtube.com/vi/mYD0sCNiczE/0.jpg)](https://www.youtube.com/watch?v=mYD0sCNiczE&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL) - -## Introduction -GeoServer supports various spatial operators that filter geospatial data based on their location or spatial relationships with other features. These operators are commonly used with other filter expressions to create complex queries. These queries are useful for extracting specific subsets of data from a larger dataset. - -The spatial operators are Topological, Distance, and Bounding Box operators. We'll explain them in more detail below. - -**Note.** This video was recorded on GeoServer 2.22.4, which is not the most up-to-date version. Currently, versions 2.24.x and 2.25.x are supported. To ensure you have the latest release, please visit this [link](https://geoserver.org/download/) and avoid using older versions of GeoServer. - -## Topological operators -In GeoServer, topological operators are used for spatial analysis and processing of geographic data. These operators perform geometric operations that preserve the spatial relationship or topology between geometric features. Some common topological operators in GeoServer include: Intersects, Within, Contains, etc. - -### Intersects -The **Intersects** filter in GeoServer is used to query spatial data based on the intersection of two geometry objects. For example, you can use this operator to extract all features that intersect with a specified Point, Line, or Polygon. - -Here are some examples of how you can use this filter in an XML request to filter the `States` layer by the `State_Name` attribute: - -- Navigate to the **Demos** page, then select **Demo requests**. -- From the Request section, select the **WFS_getFeatureIntersects1.0.xml** request. -- The address will be filled in automatically, in the URL section. -- Now, we will explain some elements: - - The first thirteen lines include explanations in the form of comments. - - Line 14 describes the XML version and the `getFeatureIntersects` operation of the WFS service being used. - - Line 15 specifies the default output format for the WFS service as `GML2`. Additionally, GeoServer supports several other commonly used formats such as "gml3, shapefile, geojson, and csv." - - Lines 16 to 22 define the start of the XML request and declare the namespaces used in the request. - - Line 23 specifies the type name of the feature to be queried. In this case, it requests features of the `topp:states`. - - Lines 25 to 30 define the filter criteria for the query. On these lines, we use the **Intersects** filter, to retrieve all states that intersects with a Point defined by latitude and longitude. - -- Press the **Submit** button. - -**Note.** For GeoServer 2.25.2 the Demo Request page has been improved to show response Headers, and provide the option to pretty print XML output. - -### Within -This operator is used to retrieve features that are completely within the specified geometry. For example, you can use this operator to extract all features that are within a polygon. - -Here's an example of how you can define a `Within` filter in XML. As an example of using this filter in a WFS getFeature request, use the following block codes to replace lines 24 to 31: - - - - the_geom - - - - -90.73,29.85 -90.73,35.92 -80.76,35.92 -80.76,29.85 -90.73,29.85 - - - - - - -Press the **Submit** button. As you can see, the result includes two states named `Alabama` and `Georgia`. - -### Contains -This operator is used to filter data that is completely contained within a given geometry. For example, you can use this operator to extract all features that are completely contained within a polygon that represents a state boundary. - -Here's an example of how you can define a `Contains` operator in XML: - - - - the_geom - - -89.35,31.46 -89.35,32.11 -89.49,32.23 -90.21,32.23 - - - - -Press the **Submit** button. As you can see, the state that contains the given geometry is `Mississippi`. - -You will need to adjust the filter and shape to match your data and SRS. Assuming you have a data source with a geometry column named the_geom that uses the EPSG:4326 coordinate system. - -## Distance operators -In GeoServer, Distance operators like "DWithin" and "Beyond" filters, are used to filter and retrieve features based on their spatial relationship and proximity to a given geometry or location. These operators can be used in WFS requests and are useful for performing spatial analysis and finding nearby features. - -### DWithin -The 'DWithin' or 'Distance Within' filter, will return records that are located within a specific distance of a defined point, much like a buffer. As well as the point geometry, you must specify the value of the distance from this point and the unit of measure. The units for the DWithin are: Feet, meters, kilometers and miles. - -Here's an example of how to use the `DWithin` filter in a GeoServer XML configuration file. To find all the features that are within `10000` meters of a given point in a layer called "sf:archsites", the following WFS request can be used. - - - - - - the_geom - - 593250,4923867 - - 10000 - - - - - -This will return all the features in "sf:archsites" layer, that are within 10000 meters of the given point. -Remember that, the EPSG code mentioned in line 11 is very important because it serves as a reference point for importing coordinates and distance values. - -Press the **Submit** button. - -## Bounding Box operators -The Bounding Box operator is used to filter data based on a specified bounding box. A bounding box is a rectangular region defined by its lower left and upper right coordinates: minx, miny, maxx, and maxy. For example, you can use this operator to extract all features that are located or partially located inside a box of coordinates. - -As an example of using this operator, select the **WFS_getFeatureBBOX1.0.xml** from the Request section. Now the filters block code is as follows: - - - - the_geom - - -75.102613,40.212597 -72.361859,41.512517 - - - - -In this case, we just get the `STATE_NAME` and `PERSONS` attribute. -Using the range specified in the code specifies the features that are completely or partially located in this area. -The result includes four states named `New York`, `Pennsylvania`, `Connecticut`, and `New Jersey` as you see on the screen. - ----- - -In this session, we took a brief journey through the "Spatial operators in GeoServer". If you want to access the complete tutorial, click on the [link](https://www.youtube.com/watch?v=mYD0sCNiczE&list=PL_ITaxp1Ob4sjk24Stboa5XbO0LGdEKbL). \ No newline at end of file From 7408199e294f86e77b9deaae11972a37f90c8814 Mon Sep 17 00:00:00 2001 From: Milad Rafiei <166007313+MiladRafiei@users.noreply.github.com> Date: Mon, 23 Dec 2024 00:46:02 +0330 Subject: [PATCH 4/4] Update 2024-12-25-geospatial-techno.md --- _posts/2024-12-25-geospatial-techno.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/_posts/2024-12-25-geospatial-techno.md b/_posts/2024-12-25-geospatial-techno.md index 2d0bafe09..26bc3ae3b 100644 --- a/_posts/2024-12-25-geospatial-techno.md +++ b/_posts/2024-12-25-geospatial-techno.md @@ -2,7 +2,7 @@ author: Milad Rafiei layout: post title: Using Logical Operators in GeoServer Filters -date: 2024-12-24 +date: 2024-12-25 categories: - Tutorials ---