[mapserver-users] Bulk creation of mapfile

Jeff McKenna jmckenna at gatewaygeomatics.com
Wed Aug 13 14:51:39 PDT 2014


Robert, you cool Python script would live nicely on the MapServer wiki 
;) https://github.com/mapserver/mapserver/wiki

-jeff



On 2014-08-13 6:02 PM, Robert Sanson wrote:
> Here is a small Python script that read in a file of shapefile names of tileindexes for thousands of rasters and wrote out the LAYER sections to a text file. It used fiona to work out the extents of each tileindex shapefile. The input list included file name and ground sampling distance (GSD):
>
> import sys, os
> import fiona
>
> fl = open('list','r')
> lines = fl.readlines()
> lines.reverse()
> outf = open('extents','w')
> for line in lines:
>      line = line.strip()
>      fn, res = line.split()
>      dn, ind = fn.split("_")
>      c = fiona.open(fn + ".shp")
>      x1,y1,x2,y2 = c.bounds
>      c.close()
>      outf.write(" LAYER\n")
>      outf.write("  NAME " + dn + "\n")
>      outf.write("  GROUP 'highres'\n")
>      outf.write("  TYPE RASTER\n")
>      outf.write("  STATUS ON\n")
>      outf.write("  TILEINDEX ../../data/nz/" + fn + "\n")
>      outf.write("  TILEITEM Location\n")
>      outf.write("  MAXSCALE 100000\n")
>      outf.write("  METADATA\n")
>      outf.write("   'ows_title' '" + dn + "'\n")
>      outf.write("   'wms_opaque' '1'\n")
>      outf.write("   'wms_group_title' 'highres'\n")
>      outf.write("   'wms_resx' '" + str(res) + "'\n")
>      outf.write("   'wms_resy' '" + str(res) + "'\n")
>      outf.write("   'ows_extent' '" + str(x1) + " " + str(y1) + " " +str(x2) + " " + str(y2) + "'\n")
>      outf.write("  END\n")
>      outf.write(" END\n")
>      outf.write("\n")
> fl.close()
> outf.close()
>
> Regards,
>
> Robert
>
>>>> Cristiano Sumariva <sumariva at gmail.com> 14/08/2014 6:44 a.m. >>>
> I took the plpgsql way. Created a set of functions that generates the
> mapfile blocks and store the tokens in several postgresql tables(using
> traditional SQL relations).
>
> Then I invoke the mapfile( id ) from database and pass the mapfile text
> direct to mapscript.
> With this, the mapfile creation has been managed by the database and did
> not need any files.
>
> Since all layers are already at database, I do not think those generation
> steps take some much processing.
> It is working for a few layers already loaded.
>
> Current postgresql could also store them as XML. Recent mapserver could
> parse xml mapfiles. But never implemented something this way.
>
>
>
> 2014-08-13 15:08 GMT-03:00 Alex Lopes <alexlopespereira at gmail.com>:
>
>> Thank you everybody who helped me. I'll study all the suggestions and post
>> here the complete source code of my solution.
>>
>> Alex
>>
>>
>> 2014-08-13 9:34 GMT-04:00 Jeff McKenna <jmckenna at gatewaygeomatics.com>:
>>
>> Definitely leverage mapfile INCLUDEs (http://mapserver.org/mapfile/
>>> include.html). In your case, each LAYER could be an include, and you
>>> could have a mapfile template file that your shell script writes those
>>> include layers into.
>>>
>>> I recently saw a presentation at FOSS4G-Europe from PropertyShark, who
>>> manages thousands of layers, using includes, and generates them through
>>> custom Perl scripts (you can read about that discussion, or contact them,
>>> through the recent Google+ discussion https://plus.google.com/
>>> communities/103841604654304099367).
>>>
>>> -jeff
>>>
>>>
>>> --
>>> Jeff McKenna
>>> MapServer Consulting and Training Services
>>> http://www.gatewaygeomatics.com/
>>>
>>>
>>> On 2014-08-13 10:03 AM, Alex Lopes wrote:
>>>
>>>> Hi Everybody,
>>>>
>>>>
>>>> I need to create a script shell to build thousands of mapfiles based on
>>>> postgis layers.
>>>>
>>>> Which is the best way to accomplish this task?
>>>>
>>>> Best regards,
>>>> Alex
>>>>


More information about the mapserver-users mailing list