geomoose / gm3

GeoMoose 3.0 Development. Please submit pull requests to the 'main' branch.
https://www.geomoose.org
MIT License
58 stars 60 forks source link

WFS map-source and BBOX coordinates SRS #524

Open brentfraser opened 4 years ago

brentfraser commented 4 years ago

I'm trying to set up a map-source of type="wfs", mostly to test and document. I did some searching and found a candidate server

https://sdmdataaccess.nrcs.usda.gov/WebServiceHelp.aspx#SDMWGS84Geographic

Looking getCapabilities doc, it says the layer typename=mapunitpolythematic

<FeatureType>
  <Name>mapunitpolythematic</Name>
  <Title>Soil Mapunit Polygon Thematic Map</Title>
  <Abstract>
    Map unit polygons delineating a selected soil interpretation.
  </Abstract>
  <ows:Keywords>
    <ows:Keyword>Soils</ows:Keyword>
    <ows:Keyword>SSURGO Mapunit</ows:Keyword>
    <ows:Keyword>mapunit polygons</ows:Keyword>
    <ows:Keyword>mapunit interpretation</ows:Keyword>
  </ows:Keywords>
  <DefaultSRS>urn:ogc:def:crs:EPSG::4326</DefaultSRS>
  <OutputFormats>
    <Format>text/xml; subtype=gml/3.1.1</Format>
  </OutputFormats>
  <ows:WGS84BoundingBox dimensions="2">
    <ows:LowerCorner>-179.9999 -80</ows:LowerCorner>
    <ows:UpperCorner>179.9999 80</ows:UpperCorner>
  </ows:WGS84BoundingBox>
  <MetadataURL format="text/xml" type="TC211">
    https://SDMDataAccess.sc.egov.usda.gov/Spatial/SDMWGS84GEOGRAPHIC.wfs?request=GetMetadata&layer=mapunitpolythematic
  </MetadataURL>
</FeatureType>

It looks like it prefers (requires?) EPSG:4326 , and GeoMoose sends the BBOX as:

bbox=-10383601.716728799,5535877.43392501, -10351765.69444802,5569471.507856345, EPSG:3857

Which the server rejects:

Error getting BBOX and extent area from WFS request string (shorthand BBOX filter) - invalid Bounding Box coordinate format (shorthand BBOX).

Having a look at vector.js, around line 80:

                const url_params = Object.assign({}, mapSource.params, {
                    'srsname': 'EPSG:3857',
                    'outputFormat': output_format,
                    'service': 'WFS',
                    'version': '1.1.0',
                    'request': 'GetFeature',
                    'bbox': extent.concat('EPSG:3857').join(',')
                });

I see GM will always send the BBOX in EPSG:3857. While I think we need to change this to allow the map-source parameters to override the default GM ones, instead of the other way around (as is is now).

brentfraser commented 4 years ago

I made the changed I suggested above but still got BBOX errors from the server. I looked at their example (which returns some resilts) and saw they did not have a separate BBOX parameter, but instead included it in a Filter, so I added a filter parameter (escaped XML) to the map-source def:

    <map-source name="wfs" type="wfs">
        <url>http://giswebservices.massgis.state.ma.us/geoserver/wfs</url>
        <param name="typename" value="'massgis:GISDATA.PARCELTOWNS_100ACREWIND"/>
        <param name="outputFormat" value="GML2"/>
        <param name="srsname" value="EPSG:4326"/>
        <param name="filter" value="&lt;Filter&gt;&lt;BBOX&gt;&lt;PropertyName&gt;Geometry&lt;/PropertyName&gt;&lt;Box srsName=&apos;EPSG:4326&apos;&gt; &lt;coordinates&gt;-121.77100,37.368402 -121.76000,37.373473&lt;/coordinates&gt; &lt;/Box&gt;&lt;/BBOX&gt;&lt;/Filter&gt;"/>

        <layer name="default">
            <style><![CDATA[
            {
                "line-color" : "#9e8647",
                "line-width" : 5
            }
            ]]></style>

            <template name="identify" auto="true" />
        </layer>
    </map-source>

Their server returned results (just a few around San Jose, CA), but GM did not render them.

tchaddad commented 4 years ago

Yes WFS parameters are different then WMS, and people can pick and choose what their servers support, so it can be challenging to figure out.

I have a WFS service that supports geojson output, maybe you can try it? here is an example URL:

https://www.coastalatlas.net/services/wfs/?service=WFS&request=GetFeature&version=2.0.0&TYPENAMES=public_access_2010&OUTPUTFORMAT=geojson

This returns point data so the rendering should be simple (?)

(apologies - the data is on the Oregon coast...)

brentfraser commented 4 years ago

Any data is appreciated! So many WFS variations to test...

I added a wfs map-source by copying the existing mapserver-wfs and doing a few edits. Good enough to test the Identify, styling, etc.

    <map-source name="wfs" type="wfs">
        <url>http://localhost/cgi-bin/mapserv.exe</url>
        <param name="map" value="C:/ms4w/apps/gm3-demo-data/demo/parcels/parcels.map"/>
        <param name="typename" value="ms:parcels"/>
        <layer name="default">
            <style><![CDATA[
            {
                "circle-radius": 4,
                "circle-color": "#fec44f",
                "fill-color": "#fec44f",
                "circle-stroke-color": "#d95f0e",
                "line-color": "#d95f0e",
                "line-width": 2,
                "fill-opacity": 0.20,
                "line-opacity": 0.80,
                "text-field": "{OWNER_NAME}",
                "text-color": "#000000"
            }
            ]]></style>
            <template name="identify" auto="true" />
        </layer>
    </map-source>
brentfraser commented 4 years ago

Fixes have been made, so this issue just needs doc. GM's WFS default params (case-sensitive) names and values are:

                    'srsname': 'EPSG:3857',
                    'outputFormat': 'text/xml; subtype=gml/2.1.2',
                    'service': 'WFS',
                    'version': '1.1.0',
                    'request': 'GetFeature',
                    'bbox': extent.concat('EPSG:3857').join(',')

so if you want to over-ride these in your mapbook, use the same case in the names. For example, use outputFormat, not OUTPUTFORMAT:

<param name="outputFormat" value="application/geojson"/>

brentfraser commented 1 year ago

TBD: test in PR #787