 <?xml-stylesheet type="text/css" href="https://www.esdm.co.uk/Data/style/rss1.css" ?> <?xml-stylesheet type="text/xsl" href="https://www.esdm.co.uk/Data/style/rss1.xsl" ?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd">
  <channel>
    <title>The knowledge base blog</title>
    <link>https://www.esdm.co.uk/knowledge</link>
    <description />
    <docs>http://www.rssboard.org/rss-specification</docs>
    <generator>mojoPortal Blog Module</generator>
    <language>en-GB</language>
    <ttl>120</ttl>
    <atom:link href="https://www.esdm.co.uk/Blog/RSS.aspx?p=138~108~189" rel="self" type="application/rss+xml" />
    <itunes:owner />
    <itunes:explicit>no</itunes:explicit>
    <item>
      <title>When MapServer refuses to run in an ASP.NET Core MVC site (401 - unauthorized)</title>
      <description><![CDATA[<p>Well that was two hours I won’t get back, but I’ll make a note here in case it helps anyone else. I had simply overlooked one of those many tiny things…</p><p>We use MapServer as a lightweight GIS engine in many of our products, giving us WMS/WFS API endpoints for a wide range of purposes. When upgrading the <a href="https://colchesterheritage.co.uk" target="_blank">Colchester Heritage Explorer website</a>, an ASP.NET Core MVC site made with <a href="https://www.cloudscribe.com" target="_blank">cloudscribe</a> and <a href="https://hbsmrdocumentation.esdm.co.uk/hbsmr-webapi" target="_blank">HBSMR WEB/API</a> components, I dived in to configure and test the MapServer instance. I followed our usual processes, enabled the CGI extension to execute, setting folder permissions to allow MapServer to write out log files, configured our secure MapServer Proxy component, etc. </p><p>But it wasn’t working. </p><p>One of our first tests of a MapServer instance is to browse to the location of the main MapServer executable, in this case the address was:</p><p>https://colchesterheritage.co.uk/wwwroot/MapServer/Scripts/mapserv.exe </p><p>but instead of a nice diagnostic response, I got “401 – Unauthorized: Access is denied due to invalid credentials”:</p><p><img width="640" height="116" title="image" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_160.png" border="0"></p><p>This was very puzzling, as I already had this working perfectly in a parallel test site, on the same server with identical configuration in every respect – or so I thought. Both sites were using an application pool with Identity set to ApplicationPoolIdentity, folder permissions were all good for this identity, there were no ip restrictions, and no reason I could see for it not to work.</p><p>Except that I’d forgotten about the Anonymous Authentication Credentials… in IIS select the site &gt; Authentication &gt; select Anonymous Authentication and click “Edit…” &gt; I found the default setting:</p><p><img width="640" height="328" title="image" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_161.png" border="0"></p><p>And of course I had not set up permissions for this user to access the location of the MapServer files. So there are two solutions: a) <em>less preferred</em>: add the IUSR account at the root of site with default permissions:</p><p><img width="378" height="457" title="image" style="margin: 0px; border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_162.png" border="0"></p><p>(if I were using this solution I would also tick “Deny” for the “Write” setting off bottom of that image);</p><p>or b) <em>preferred</em>: change the Anonymous Authentication Credentials for the site to the Application pool identity:</p><p><img width="640" height="330" title="image" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_163.png" border="0"></p><p>After making this change, on browsing to our MapServer executable I saw the expected response “Noquery information to decode. QUERY_STRING is set, but empty. ” which means the CGI application is working. </p><p><strong>Phew – problem solved!</strong></p><p>My next step in hardening this site is to block this direct access, and route all requests through a secured proxy, so the above URL to the exe won’t work by the time you read this if we’ve done our security right.</p><p>To see the working result, check out the maps within the <a href="https://colchesterheritage.co.uk" target="_blank">Colchester Heritage Explorer</a>, for example this map of the historic buildings and sites that are <a href="https://colchesterheritage.co.uk/map?center=100120.11461153519,6780076.084676751&amp;zoom=16&amp;baselayer=OpenStreetMap&amp;opacity=1&amp;panel=overlays&amp;overlays=LocalList&amp;overlaysoff=RegisteredParksAndGardens,ConservationAreas,ListedBuildings,ScheduledMonuments,Events,Monuments" target="_blank">included on the Colchester “Local List”</a>.</p><p>And here’s a rather nice map of WW2 pillboxes and related defensive sites around Colchester, generated by a MapServer WFS request in response to a <a href="https://colchesterheritage.co.uk/globalsearch/index?q=pillboxes" target="_blank">a free text search on “pillboxes”</a>:</p><p><img width="559" height="480" title="image" style="border: 0px currentcolor; border-image: none; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_164.png" border="0"></p><p>I hope this helps someone, and please feel free to add comments below.</p><br /><a href='https://www.esdm.co.uk/when-mapserver-refuses-to-run-in-an-aspnet-core-mvc-site-401-unauthorized'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/when-mapserver-refuses-to-run-in-an-aspnet-core-mvc-site-401-unauthorized'>...</a>]]></description>
      <link>https://www.esdm.co.uk/when-mapserver-refuses-to-run-in-an-aspnet-core-mvc-site-401-unauthorized</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/when-mapserver-refuses-to-run-in-an-aspnet-core-mvc-site-401-unauthorized</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/when-mapserver-refuses-to-run-in-an-aspnet-core-mvc-site-401-unauthorized</guid>
      <pubDate>Sat, 19 Oct 2019 10:55:24 GMT</pubDate>
    </item>
    <item>
      <title>Mapserver returning WFS attributes scrambled when using msplugin_mssql2008 plugin</title>
      <description><![CDATA[<p>We recently upgraded Mapserver to the current version for a project because we wanted the WFS id field to be populated in geojson which required a recent version of (OGR &gt;=2.3) which was included in mapserver build 7.2.1</p><p>All went well and we modified the mapserver geojson output format to specify the field we wanted to use (originally named id in our case) but adding in the line: FORMATOPTION "LCO:ID_FIELD=id"</p><blockquote><p>OUTPUTFORMAT<br>&nbsp;&nbsp; NAME "geojson"<br>&nbsp;&nbsp; DRIVER "OGR/GEOJSON"<br>&nbsp;&nbsp; MIMETYPE "application/json; subtype=geojson"<br>&nbsp;&nbsp; FORMATOPTION "STORAGE=stream"<br>&nbsp;&nbsp; FORMATOPTION "FORM=SIMPLE"<br>&nbsp;&nbsp; FORMATOPTION "LCO:COORDINATE_PRECISION=0"<br>&nbsp;&nbsp; FORMATOPTION "LCO:ID_FIELD=id"<br>
END</p></blockquote><p>The field “id” needed to be included in the relevant map layer in the gml_include_items e.g.:</p><blockquote><p> "gml_include_items"&nbsp;&nbsp;&nbsp;&nbsp; "name,recsubtype,recsubtypecode,rectype,ref,uid,id"</p></blockquote><p>After those changes – all seemed to be going well and the id was appearing in our WFS return</p><p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_151.png"><img width="244" height="52" title="image" style="margin: 0px; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_thumb_122.png" border="0"></a></p><p>However when we looked at some of the other attributes we noticed scrambled characters (these had been fine with the previous version of mapserver). e.g. rectype in screenshot below</p><p><a href="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_152.png"><img width="244" height="57" title="image" style="margin: 0px; display: inline; background-image: none;" alt="image" src="https://www.esdm.co.uk/Data/Sites/1/media/wlw/image_thumb_123.png" border="0"></a></p><p>Our data was coming from SQL server using the msplugin_mssql2008 plugin– and if we set debug in the mapserver layer and looked at the log we saw:</p><blockquote><p><em>msConvertWideStringToUTF8(): General error message. Unable to convert string in encoding 'UCS-2LE' to UTF8 An invalid multibyte sequence has been encountered in the input</em></p></blockquote><p>So it looked as it something was going wrong in the unicode translation.&nbsp; The workaround was refreshingly simple – we just had to alter the view that the data was being pulled from to force the conversion e.g. change:</p><blockquote><p>‘Site’</p><p>to:</p><p>CONVERT(nvarchar(1),N’Site’)</p></blockquote><p>then all was well again.</p><br /><a href='https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin'></a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin'>...</a>]]></description>
      <link>https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin</link>
      <author>()</author>
      <comments>https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/mapserver-returning-wfs-attributes-scrambled-when-using-msplugin_mssql2008-plugin</guid>
      <pubDate>Thu, 21 Feb 2019 12:54:32 GMT</pubDate>
    </item>
    <item>
      <title>GeoServer WFS fails on SQL Server tables/views with GUID data type</title>
      <description><![CDATA[<p>Just a quick note that might be useful to some.</p>

<h4>The problem...</h4>

<p>If you publish a SQL Server (in this case 2014) table or view with a GUID field using GeoServer (version&nbsp;2.10), it will fail to make&nbsp; a valid WFS because the &amp;request=DescribeFeatureType response <em>will not include these layers</em>.</p>

<p>This manifests itself in various ways depending on the client, but in QGIS on trying to load the layer into the map we get this in the "Log Messages Panel":</p>

<blockquote>
<p>Analysis of DescribeFeatureType response failed for url&nbsp; srsname='EPSG:27700' typename=xxx:yyyurl='https://mysite.com/myworkspace/wfs' version='1.0.0' table="" sql=: it is probably a schema for Complex Features</p>
</blockquote>

<p>which had me puzzled for quite some time!</p>

<h4>The solution...</h4>

<p>Changing the data source view to include this field with</p>

<p>CAST(myGUID AS varchar(36)) AS myGUID</p>

<p>then hitting "Reload feature type" in the GeoServer layer configuration screen fixes it. This changes the field data type from "UUID" to "string" in that screen. Or just omit the field entirely.</p>

<p>My guess is this will not help transactional WFS, but I have not tested this. Overall, GUIDs are still best avoided in GIS-land as they are so poorly supported by the database drivers.</p>
<br /><a href='https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type'>Crispin Flower</a>&nbsp;&nbsp;<a href='https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type'>...</a>]]></description>
      <link>https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type</link>
      <author>crispin.flower@idoxgroup.com (Crispin Flower)</author>
      <comments>https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type</comments>
      <guid isPermaLink="true">https://www.esdm.co.uk/geoserver-wfs-fails-on-sql-server-tablesviews-with-guid-data-type</guid>
      <pubDate>Wed, 11 Jan 2017 22:23:00 GMT</pubDate>
    </item>
  </channel>
</rss>