[mapserver-dev] MongoDB support?

Stephen Woodbridge woodbri at swoodbridge.com
Tue Feb 12 07:07:04 PST 2013


Umberto,

Interesting read, especially if you wade through the following comments. 
Regardless of the issues related to MongoDB, if you have data in the 
database and you need to display it in mapserver then read on ...

Regarding connecting to MongoDB or any unsupported data source that you 
can access via python, perl, php, etc I have found a solution using OGR 
with some help from Even and Frank.

1. Expose your data source via an HTTP GET
I wrote a trivial PHP script to connect to the database and issue a 
query and returned the data as CSV data stream.

2. Using GDAL/OGR 1.10beta you can create a virtual file system that can 
read your streaming web service. Create an OGR vrt file like test.vrt:

<OGRVRTDataSource>
      <OGRVRTLayer name="test">
 
<SrcDataSource>CSV:/vsicurl_streaming/http://imaptools.com:8080/ws/test.php?id=12</SrcDataSource>
          <GeometryType>wkbPoint</GeometryType>
          <LayerSRS>WGS84</LayerSRS>
          <GeometryField encoding="PointFromColumns" x="x" y="y"/>
      </OGRVRTLayer>
</OGRVRTDataSource>

You can test that this works with:

ogrinfo test.vrt -al -q -ro

3. Finally create a mapfile with a layer definition like:

LAYER
   NAME "test"
        CONNECTIONTYPE OGR
        CONNECTION '<OGRVRTDataSource>
      <OGRVRTLayer name="test">
 
<SrcDataSource>CSV:/vsicurl_streaming/http://example.com/ws/test.php?id=12</SrcDataSource>
          <GeometryType>wkbPoint</GeometryType>
          <LayerSRS>WGS84</LayerSRS>
          <GeometryField encoding="PointFromColumns" x="x" y="y"/>
      </OGRVRTLayer>
</OGRVRTDataSource>'
     DATA test
     STATUS default
     TYPE POINT
   CLASS
     NAME "test"
     SYMBOL "circle-filled"
     SIZE [count]
     COLOR 0 0 0
   END
END

I have not tried it yet, but I believe you can probably use CGI 
parameter substitutions into your CONNECTION string to pass parameters 
from you mapserver request into your data source url.

Thanks to Even and Frank for their suggestions and help figuring this 
all out.

I think using this new feature in the up coming GDAL release will be 
extremely powerful glue for support many orphaned or emerging data 
sources that are not supported directly in mapserver or GDAL.

Thanks,
   -Steve

On 2/12/2013 3:30 AM, Umberto Nicoletti wrote:
> Thought you might be interested in this:
>
> http://hackingdistributed.com/2013/01/29/mongo-ft/
>
> Umberto
>
>
> On Wed, Feb 6, 2013 at 9:13 PM, Stephen Woodbridge
> <woodbri at swoodbridge.com <mailto:woodbri at swoodbridge.com>> wrote:
>
>     On 2/6/2013 2:06 PM, Lime, Steve D (MNIT) wrote:
>
>         Not something I've thought of. Options as I see it would be to:
>
>             - use mapscript. Presumably most scripting languages can
>         access MongoDB.
>             - Write a native MapServer driver plugin...
>             - Wait for OGR support...
>
>
>     Hi Steve,
>
>     Yeah, this was my conclusion also. I wrote to Frank and suggested it
>     would be useful to extent file support of ogr to allow access to
>     <service>://... servers because then you could do something like
>     open a CSV connection to http://example.com/myphp.php?__args
>     <http://example.com/myphp.php?args>.. and PHP to make the querys and
>     format the data to OGR for reading data. This would allow it to them
>     be called from Mapserver. If you keep it simple this could be
>     extremely useful for supporting all kinds of services that could not
>     be support otherwise. This would work in OGR for CSV, GML, basically
>     any text flat file reader that already exists in OGR today.
>
>     For now, I might write a trivial mapscript application to support my
>     immediate needs.
>
>     There are a large number of these NOSQL databases popping up and
>     being able to have some generic connection via scripting up a web
>     service makes a lot of sense to me, beyond the immediate need that I
>     have. I have already just dumped the some data to a text file and
>     used that to create a shapefile to get some data into a map. But I
>     really like the idea of some kind of universal glue like the above.
>
>     Thanks,
>        -Steve
>
>
>         Steve
>
>         -----Original Message-----
>         From: mapserver-dev-bounces at lists.__osgeo.org
>         <mailto:mapserver-dev-bounces at lists.osgeo.org>
>         [mailto:mapserver-dev-bounces at __lists.osgeo.org
>         <mailto:mapserver-dev-bounces at lists.osgeo.org>] On Behalf Of
>         Stephen Woodbridge
>         Sent: Tuesday, February 05, 2013 10:13 AM
>         To: mapserver-dev
>         Subject: [mapserver-dev] MongoDB support?
>
>         Hi All,
>
>         Has anyone thought of adding support for MongoDB? I asked on the
>         GDAL list if there was support via OGR.
>
>         MongoDB is a popular NoSQL database, there are others and google
>         around it seems that people have experimented with moving
>         shapefiles in and out of it using python and ogr.
>
>         Anyway, I'm trying to keep up with the technology and found that
>         MongoDB actually has some basic spatial support built into it.
>         Which got me to the point that I would like to be able to issue
>         a query and pull points and attributes into a mapserver layer.
>
>         Any thoughts on how to do this?
>
>         Thanks,
>              -Steve
>         _________________________________________________
>         mapserver-dev mailing list
>         mapserver-dev at lists.osgeo.org <mailto:mapserver-dev at lists.osgeo.org>
>         http://lists.osgeo.org/__mailman/listinfo/mapserver-dev
>         <http://lists.osgeo.org/mailman/listinfo/mapserver-dev>
>
>
>
>     _________________________________________________
>     mapserver-dev mailing list
>     mapserver-dev at lists.osgeo.org <mailto:mapserver-dev at lists.osgeo.org>
>     http://lists.osgeo.org/__mailman/listinfo/mapserver-dev
>     <http://lists.osgeo.org/mailman/listinfo/mapserver-dev>
>
>



More information about the mapserver-dev mailing list