2

I am new in MapServer and I want to visualize some raster tables in MapServer.

My mapfile is:

MAP
CONFIG "MS_ERRORFILE"  "error.log"
DEBUG 5
NAME "milad"
STATUS on
SIZE 600 600 
EXTENT -8321547  5668833  -7583277  6240180
UNITS meters


LAYER
    NAME "poly"
    STATUS DEFAULT
    TYPE RASTER

    DATA "PG:host=localhost port=5432 dbname=geodatabase user=postgres password=**** schema=public table=milad_raster column=st_asraster" 

    PROJECTION
        "init=epsg:3857"
    END 

    PROCESSING "NODATA=-9999"
    PROCESSING "SCALE=AUTO"


    CLASS
        STYLE
            COLOR 200 0 0
        END
    END
END

END

Then I use this URL to see the map but I see nothing. It is just the white screen.

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/milad/milad_raster.map&mode=map

I checked the log files and I saw that the error is:

[Thu Jan 23 15:34:58 2020].675000 
msLoadMap(): 0.016s
[Thu Jan 23 15:34:58 2020].675000 CGI Request 
1 on process 7144
[Thu Jan 23 15:34:58 2020].675000 
msDrawMap(): rendering using outputformat 
named png (AGG/PNG).
[Thu Jan 23 15:34:58 2020].675000 
msDrawMap(): WMS/WFS set-up and query, 0.000s
[Thu Jan 23 15:34:58 2020].675000 
msDrawRasterLayerLow(poly): entering.
[Thu Jan 23 15:34:58 2020].768000 Corrupt, 
empty or missing file 'PG:host=localhost 
port=5432 dbname=geodatabase user=postgres 
password=**** schema=public 
table=milad_raster column=st_asraster' for 
layer 'poly' ... ignoring this missing data.  
Error browsing database for PostGIS Raster 
properties
[Thu Jan 23 15:34:58 2020].768000 
msDrawMap(): Layer 0 (poly), 0.093s
[Thu Jan 23 15:34:58 2020].768000 
msDrawMap(): Drawing Label Cache, 0.000s
[Thu Jan 23 15:34:58 2020].768000 msDrawMap() 
total time: 0.093s
[Thu Jan 23 15:34:58 2020].768000 
msSaveImage(stdout) total time: 0.000s
[Thu Jan 23 15:34:58 2020].768000 mapserv 
request processing time (msLoadMap not 
incl.): 0.093s
[Thu Jan 23 15:34:58 2020].768000 
msFreeMap(): freeing map at 02648FD8.
[Thu Jan 23 15:34:58 2020].784000 mapserv 
total execution time: 0.125s

If you do not want to read that file, just read this one cuz error is here:

[Thu Jan 23 15:34:58 2020].768000 Corrupt, empty or missing file 'PG:host=localhost port=5436 dbname=geodatabase user=postgres password=**** schema=public table=milad_raster column=st_asraster' for layer 'poly' ... ignoring this missing data. Error browsing database for PostGIS Raster properties

I can visualize my raster table in QGIS. Thus, I believe it should be correct. I checked with gdalinfo and I was able to read the raster table. What is the problem? the URL? the mapfile? or something else?

7
  • From memory, think Map file is missing connection and connectiontype.
    – nmtoken
    Commented Jan 23, 2020 at 20:51
  • @nmtoken are you sure I have to put it for raster also?? I think that is for vector data only.
    – milad
    Commented Jan 23, 2020 at 21:03
  • Not sure, did you try it, connection at least for the pg connection info?
    – nmtoken
    Commented Jan 23, 2020 at 21:38
  • I do not know what exact lines I have to add. for vector I added : TYPE POLYGON CONNECTIONTYPE postgis CONNECTION "user=postgres password=**** dbname=geodatabase host=localhost port=5436" DATA "geom from milad_test using SRID=3857 using unique id"
    – milad
    Commented Jan 23, 2020 at 21:53
  • You are right, it can't have labels, connection, connectiontype or feature information mapserver.org/input/raster.html#raster, sorry for taking you that way
    – nmtoken
    Commented Jan 23, 2020 at 21:54

1 Answer 1

1

I did some steps and with the help of @nmtoken I was able to fix it. I believe that my raster table had some problems maybe because I created it with complex geometries or maybe another reason. This time I changed the raster table I just simply used this codes in PostGIS to create a raster table from a single polygon:

SELECT ST_AsRaster(geom, 100, 100 , '8BSI', 100 , -99 ) AS rast
INTO raster_test
FROM polygon;

ALTER TABLE raster_test ADD COLUMN rid SERIAL PRIMARY KEY;

SELECT AddRasterConstraints('raster_test','rast');

Before, my table did not have rid and was created from complex geometries. Then, I used the following mapfile:

MAP
CONFIG "MS_ERRORFILE"  "error.log"
DEBUG 5
NAME "milad"
STATUS on
SIZE 600 600 
EXTENT -8321547  5668833  -7583277  6240180
UNITS meters

LAYER
    NAME "poly"
    STATUS DEFAULT
    TYPE RASTER
    CLASSITEM "[pixel]"
    DATA "PG:host=localhost port=5436 dbname=geodatabase user=postgres password=**** schema=public table=raster_test column=rast mode=2"      
    PROJECTION

        "init=epsg:3857"

    END 



    PROCESSING "SCALE=AUTO"
    CLASS
    EXPRESSION "0"
        STYLE
           COLOR 0 0 0
        END
    END

    CLASS
    EXPRESSION ([pixel] >= 64 AND [pixel] < 128)
        STYLE

            COLOR 200 0 0

        END
    END
END

END

Then, I used the following URL:

http://localhost/cgi-bin/mapserv.exe?map=/ms4w/apps/milad/milad_raster.map&mode=map

And it is the raster representation in browser:

enter image description here

I am not sure but I think my previous raster may had overlapping pixels in some areas.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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