mapserver postgis connection

Stephen Woodbridge woodbri at SWOODBRIDGE.COM
Mon Oct 31 05:19:01 PST 2005


Frans Knibbe wrote:
> Hello Frank,
> 
> Thank you for the comments. I will certainly use CLOSE_CONNECTION=DEFER 
> if I use PostGIS. But regarding the difference in performance between 
> PostGIS and shapefile, doesn't the indexing PostGIS/PostgreSQL can do 
> count for anything? For large datasets, you need a spatial index. I 
> understand that the native shapefile driver (which is the recommended 
> way to access shapefiles according to the MapServer Reference Guide for 
> Vector Data Access 
> (http://www.maptools.org/dl/docs/mapserv/MsVectorDataGuide.pdf)) does 
> not support ESRI's spatial index for shapefiles. OGR, on the other hand, 

This is true BUT mapserver has its own spatial index. See the utilities 
shptree and every *.shp should have an index *.qix

find /pat/to/data -name \*.shp -exec shptree {} \;

will add the spatial indexes in Linux.

> can use a spatial index (see 
> http://www.gdal.org/ogr/drv_shapefile.html). Better still, it also 
> supports an attribute index. An attribute index could be used by 
> MapServer if a layer has a classification based on attribute values. I 
> really don't know how MapServer reads and sorts its data, but I can 
> imagine an attribute index will be beneficial for layers with 
> symbolization based on attribute values. Still, if I understand 
> correctly, the attribute index that OGR uses can not be used if a 
> classification based on value ranges is wanted.

Other than the spatial index mentioned above mapserver does not use any 
other indexes like for attribute joins. Once you know what entities 
spatially overlap the map it cycles through all of them and renders each 
in turn so there is no need or benefit for other indexes.

PostGIS is needed if you want to do thematic maps because a join is 
required is usually require to generate the theme CLASS column.

> So is it really true that shapefiles always outperform PostGIS data, 
> even if we are talking about big datasets with classifications?

Yes, unless you require a join for rendering or need to filter out a lot 
of data from the file/table.

-Steve W.

> Regards,
> 
> Frans
> 
> 
> 
> Frank Warmerdam wrote:
> 
>> On 10/28/05, Frans Knibbe <frans at geodan.nl> wrote:
>>  
>>
>>> An interesting thread.
>>> Shouldn't the connection step go faster if you have FastCGI enabled in
>>> the MapServer?
>>>   
>>
>>
>> Frans,
>>
>> My understanding is that PostGIS connection times are very fast
>> so FastCGI is unlikely to give much benefit.  However, if you have
>> many PostGIS layers in the map, I would encourage at least using
>> the CLOSE_CONNECTION=DEFER processing option to ensure
>> the same connection is used for all the layers.  This does not require
>> FastCGI.   FastCGI basically just allows preserving the connection
>> from cgi request to cgi request.
>>
>>  
>>
>>> Also, I wonder if PostGIS would improve relative to shapefile if you
>>> have many concurrent users requesting the same data...
>>>   
>>
>>
>> I am dubious about that.  The operating system will already preserve
>> the shapefile data in RAM from request to request.  I would think
>> that PostGIS would pay off in speed in cases that shapefiles don't
>> optimize well, for instance if you want to filter out most data based
>> on an attribute column, that could be done very fast in Postgres.
>>
>> Other than that, as folks mention Postgres' big benefit is flexability
>> of data integration and updatability.
>>
>> Best regards,
>> -- 
>> ---------------------------------------+-------------------------------------- 
>>
>> I set the clouds in motion - turn up   | Frank Warmerdam, 
>> warmerdam at pobox.com
>> light and sound - activate the windows | http://pobox.com/~warmerdam
>> and watch the world go round - Rush    | Geospatial Programmer for Rent
>>
>>
>>  
>>
> 



More information about the MapServer-users mailing list