1

user30184 answered the same question here Why is MapServer returning a blank image?

user30184 answers to start by specifying SRID and that it often has to do with extent and projection.

I imported a soils shape with ogr2ogr using -a_srs EPSG:4326

I am attempting to view the layer with Google Earth. It currently shows a blank image.

My setup :

Ubuntu 14.0.4

PostGIS

POSTGIS="2.1.2 r12389" 
GEOS="3.4.2-CAPI-1.8.2 r3921" 
PROJ="Rel. 4.8.0, 6 March 2012" 
GDAL="GDAL 1.11.2, released 2015/02/10" LIBXML="2.9.1"
LIBJSON="UNKNOWN" RASTER

MapServer

MapServer version 6.4.2 OUTPUT=GIF OUTPUT=PNG OUTPUT=JPEG OUTPUT=KML SUPPORTS=PROJ SUPPORTS=GD SUPPORTS=AGG SUPPORTS=FREETYPE SUPPORTS=CAIRO SUPPORTS=SVG_SYMBOLS SUPPORTS=RSVG SUPPORTS=ICONV SUPPORTS=FRIBIDI SUPPORTS=WMS_SERVER SUPPORTS=WMS_CLIENT SUPPORTS=WFS_SERVER SUPPORTS=WFS_CLIENT SUPPORTS=WCS_SERVER SUPPORTS=SOS_SERVER SUPPORTS=FASTCGI SUPPORTS=THREADS SUPPORTS=GEOS INPUT=JPEG INPUT=POSTGIS INPUT=OGR INPUT=GDAL INPUT=SHAPEFILE

Mapfile

MAP
DEBUG 5
CONFIG "PROJ_DEBUG" "ON"

NAME "WMS-test"

CONFIG "MS_ERRORFILE" "/tmp/ms_error.txt"

STATUS ON

EXTENT -180 -90 180 90

PROJECTION "init=epsg:4326" END

IMAGECOLOR 55 55 55

WEB

METADATA
  "wms_title"          "WMS Test"      
  "wms_onlineresource" "http://10.0.0.7/cgi-bin/mapserv?map=/mapserver/wms.map&" 
  "wms_srs"            "EPSG:4326 EPSG:3857"
  "wms_enable_request" "*"
  "wms_formatlist"     "image/png,image/gif,image/jpeg"
  "wms_format"         "image/gif"
END 

END # Web

LAYER

DEBUG 5

NAME "polygons"

PROJECTION
  "init=epsg:4326"
END

METADATA
  "wms_srs"            "EPSG:4326"
  "wms_name"           "polygon"
  "wms_title"          "polygon layer"
  "wms_server_version" "1.1.1"
  "wms_format"         "image/gif"
  "wms_include_items"  "all"
END

CONNECTIONTYPE postgis
CONNECTION "user=xxxx password=xxxx dbname=xxxx host=localhost"
PROCESSING "CLOSE_CONNECTION=DEFER"

DATA "geometry from polygon USING UNIQUE fid USING srid=4326"

STATUS ON
EXTENT -180 -90 180 90
TYPE POLYGON
CLASS
  STYLE
    COLOR 255 22 22
    OUTLINECOLOR 32 32 32
  END
END   

END #layer

END # Map File

MapServer Logfile

CGI Request 1 on process 9224

msWMSLoadGetMapParams(): enabling non-square pixels.

msDrawMap(): kicking into non-square pixel preserving mode.

msDrawMap(): rendering using outputformat named gif (GD/GIF).

msDrawMap(): WMS/WFS set-up and query, 0.000s

msPostGISLayerOpen called: geometry from polygon USING UNIQUE fid USING srid=4326

msPostGISLayerOpen: No connection in pool, creating a fresh one.

msConnPoolRegister(ssurgo,user=xxxx password=xxxx dbname=xxxx host=localhost,0xc7ad90)

msPostGISLayerOpen: Got PostGIS version 20100.

msPostGISLayerOpen: Forcing 2D geometries: yes.

msPostGISLayerFreeItemInfo called.

msPostGISLayerWhichShapes called.

msPostGISParseData called.

msPostGISParseData: unique_column=fid, srid=4326, geom_column_name=geometry, table_name=polygon

msPostGISBuildSQL called.

msPostGISBuildSQLItems called.

msPostGISBuildSQLItems: 0 items requested.

msPostGISBuildSQLFrom called.

msPostGISBuildSQLWhere called.

msPostGISBuildSQLSRID called.

msPostGISBuildSQLSRID: SRID provided (4326)

msPostGISBuildSQLBox called.

msPostGISLayerWhichShapes query: select encode(ST_AsBinary(ST_Force2D("geometry"),'NDR'),'hex') as geom,"fid" from polygon where geometry && ST_GeomFromText('POLYGON((-77.6373995911467 35.5916923817181,-77.6373995911467 35.6036240727873,-77.6170454186829 35.6036240727873,-77.6170454186829 35.5916923817181,-77.6373995911467 35.5916923817181))',4326)

msPostGISLayerWhichShapes query status: PGRES_TUPLES_OK (2)

msPostGISLayerWhichShapes got 0 records in result.

msPostGISLayerNextShape called.

msPostGISLayerFreeItemInfo called.

msPostGISLayerClose called: geometry from polygon USING UNIQUE fid USING srid=4326

msConnPoolRelease(ssurgo,user=xxxx password=xxxx dbname=xxxx host=localhost,0xc7ad90)

msDrawMap(): Layer 0 (ssurgo), 0.015s

msDrawMap(): Drawing Label Cache, 0.000s

msDrawMap() total time: 0.015s

msSaveImage(stdout) total time: 0.002s

mapserv request processing time (msLoadMap not incl.): 0.017s

msFreeMap(): freeing map at 0xc0b630.

freeLayer(): freeing layer at 0xc14160.

msPostGISLayerIsOpen called.

msConnPoolClose(user=xxxx password=xxxx dbname=xxxx host=localhost,0xc7ad90)

1

msPostGISLayerWhichShapes got 0 records in result.

tells me that there comes nothing back from the database. Are you sure that your soil data is in WGS84? You could verify with QGIS for example that there is data in your database. Or you could do a simple query inside PostGIS to see if something is there, something like this to check your data's extent and see the coordinates (adopt the query to your situation please):

SELECT ST_Extent(the_geom) as bextent FROM sometable;

I am just asking because the ogr2ogr -a_srs option assigns an SRS to the data, even if the assigned SRS is different to the data's actual SRS.

  • thanks @Frank! here's the output \BOX(1054154.3037 1345250.5414,1838923.5134 1688864.6571)\ The data comes in Albers 4326. I'm slowly learning GIS, but clearly see the coords aren't in WGS84. Is it recommended to put them into WGS84 upon import? I thought I could dynamically re-project. I only intend of using WGS84 for the current work I'm doing. I'm guessing that might boost performance, too. – owl Jan 23 '16 at 14:53
  • I re-imported with the following -s_srs "+proj=aea +lat_1=20 +lat_2=60 +lat_0=40 +lon_0=-96 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs" -t_srs "EPSG:4326" and a bbox ST_Extent result now looks like BOX(-80.1021918303873 49.6667785692599,-67.9711156466496 52.4666193122625) .. no results yet, but working through some config file changes – owl Jan 23 '16 at 15:35
  • ok, so now I can connect with QGIS and zoom-to-layer and see that it is correctly determining coordinates based on an OSM base-map ( the data is over North Carolina in USA ) .. no results from postgis yet, but seems like I'm getting closer – owl Jan 23 '16 at 15:42
  • now, if I re-add the WMS endpoint to QGIS, then right-click and "add layer", it looks like it is pulling all of the polygons. the query looks like this msPostGISLayerWhichShapes query: select encode(ST_AsBinary(ST_Force2D(“my_geome try"),'NDR'),'hex') as geom,"fid" from polygon where my_geometry && ST_GeomFromText('POLYGON((-179.79020979 021 -89.7902097902098,-179.79020979021 89.7902097902098,179.79020979021 89.7902097902098,179.79020979021 -89.79020 97902098,-179.79020979021 -89.7902097902098))',4326) ... I had to increase the timeout because it is pulling aLOT of records (1056549 records) – owl Jan 23 '16 at 16:29
  • I would debug one software layer after the other. If your data is now in PostGIS and in the right coordinate system, I would use the shp2img program that comes with mapserver to test your mapfile. If your query takes too long you could limit the returned records to speed testing up. Or you could add an index (See Mapserver/PostGIS docs). If shp2img works, you go ahead and test the OGC capabilities with QGIS. – Frank Jan 23 '16 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.