Geoserver - filtering points using DWITHIN

前端 未结 1 372
再見小時候
再見小時候 2021-01-15 06:09

First of all I am new to Geoserver and Openlayers. I have been trying to get this working on the Geoserver side using the Layer preview page to view my layer using the Openl

相关标签:
1条回答
  • 2021-01-15 06:35

    After spending some time with this I was able to answer my own question.

    First of all doing some searching I determined 1 degree = 111.325 kms approximately. https://answers.yahoo.com/question/index?qid=20060905051639AAWGjH9

    To add multiple DWITHIN filters all you have to do is add an AND between each one. If it is in the WFS format you may have to add %20AND%20 so the spaces are included.

    To do a DWITHIN of a certain location you would append the following to your wfs. The point is the long/lat, 0.05 is the degrees from the point, kilometers is the unit that is passed in. When using geoserver it will default to degrees as the link in the original question states.

    &CQL_FILTER=DWITHIN(GEOM,Point(-60.2 46.1),0.05,kilometers)
    

    This will return any of the features from your WFS layer that are within the degrees of the point specified.

    To filter off of another layer I used info from the following URL http://docs.geoserver.org/2.6.x/en/user/extensions/querylayer/index.html

    Firs you must install the proper querylayer module to your version of Geoserer as the link states.

    To do the filter based of feature name I used the following CQL_filter:

    &CQL_FILTER=DWITHIN(GEOM,collectGeometries(queryCollection('Workspace:AssetLayer','GEOM','AssetTypeID=1')),
     .02,kilometers%29
    

    This will return any features from the WFS layer you are requesting that are within the degrees specified of a feature with the AssetID of 1 from the layer 'Workspace:AssetLayer'.

    ie if school had an AssetTypeID of 1, this would return all features from the original layer that were within 0.02 degrees of a school on the 'Workspace:AssetLayer' layer.

    The "GEOM" value should be the name of column that holds your geometry data in SQL.

    Also, I encoded the last parenthesis in the CQL_Filter "%29" because I found when making the request through openlayers it was stripping it off.

    As I said I am new to openlayers/geoserver so this may not work in every case but this is how I figured it out. I am thinking in different projections there may be some changes. Hope this can get you on the right track.

    0 讨论(0)
提交回复
热议问题